mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-21 05:26:27 -08:00
i dont know what to do
ill figure it out later
This commit is contained in:
parent
459c40bece
commit
17db90898f
|
@ -149,7 +149,7 @@ export namespace files {
|
|||
* @param fileId The target file's ID
|
||||
* @returns Promise that resolves after accounts.json finishes writing
|
||||
*/
|
||||
export function index(accountId:string,fileId:string) {
|
||||
export function index(accountId:string,fileId:string,noWrite:boolean = false) {
|
||||
// maybe replace with a obj like
|
||||
// { x:true }
|
||||
// for faster lookups? not sure if it would be faster
|
||||
|
@ -158,7 +158,7 @@ export namespace files {
|
|||
if (acc.files.find(e => e == fileId)) return
|
||||
|
||||
acc.files.push(fileId)
|
||||
return save()
|
||||
if (!noWrite) return save()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,6 +11,7 @@ import * as Accounts from "./accounts.js"
|
|||
import { z } from "zod"
|
||||
import * as schemas from "./schemas/files.js"
|
||||
import { issuesToMessage } from "./middleware.js"
|
||||
import file from "../routes/api/v1/file/index.js"
|
||||
|
||||
export let alphanum = Array.from(
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
||||
|
@ -695,8 +696,41 @@ export default class Files {
|
|||
delete this.files[uploadId]
|
||||
|
||||
if (!noWrite)
|
||||
this.write().catch((err) => {
|
||||
throw err
|
||||
})
|
||||
return this.write()
|
||||
}
|
||||
|
||||
async chown(uploadId: string, newOwner?: string, noWrite: boolean = false) {
|
||||
let target = this.files[uploadId]
|
||||
if (target.owner) {
|
||||
let i = files.deindex(target.owner, uploadId, Boolean(newOwner && noWrite))
|
||||
if (i) await i
|
||||
}
|
||||
|
||||
target.owner = newOwner
|
||||
if (newOwner) {
|
||||
let i = files.index(newOwner, uploadId, noWrite)
|
||||
if (i) await i
|
||||
}
|
||||
|
||||
if (!noWrite)
|
||||
return this.write()
|
||||
}
|
||||
|
||||
async mv(uploadId: string, newId: string, noWrite: boolean = false) {
|
||||
let target = this.files[uploadId]
|
||||
if (target.owner) {
|
||||
let owner = Accounts.getFromId(target.owner)
|
||||
if (owner) {
|
||||
owner.files.splice(owner.files.indexOf(uploadId), 1, newId)
|
||||
if (!noWrite)
|
||||
await Accounts.save()
|
||||
}
|
||||
}
|
||||
|
||||
this.files[newId] = target
|
||||
delete this.files[uploadId]
|
||||
|
||||
if (!noWrite)
|
||||
return this.write()
|
||||
}
|
||||
}
|
|
@ -103,6 +103,7 @@ export const issuesToMessage = function(issues: z.ZodIssue[]) {
|
|||
export const scheme = function(scheme: z.ZodTypeAny): RequestHandler {
|
||||
return async function(ctx, next) {
|
||||
let chk = scheme.safeParse(await ctx.req.json())
|
||||
ctx.set("parsedScheme", chk.data)
|
||||
if (chk.success) return next()
|
||||
else return ServeError(ctx, 400, issuesToMessage(chk.error.issues))
|
||||
}
|
||||
|
|
|
@ -4,17 +4,20 @@ import * as auth from "../../../../lib/auth.js"
|
|||
import RangeParser, { type Range } from "range-parser"
|
||||
import ServeError from "../../../../lib/errors.js"
|
||||
import Files, { WebError } from "../../../../lib/files.js"
|
||||
import { getAccount, requiresPermissions } from "../../../../lib/middleware.js"
|
||||
import { getAccount, requiresAccount, requiresPermissions, scheme } from "../../../../lib/middleware.js"
|
||||
import {Readable} from "node:stream"
|
||||
import type {ReadableStream as StreamWebReadable} from "node:stream/web"
|
||||
import formidable from "formidable"
|
||||
import { HttpBindings } from "@hono/node-server"
|
||||
import pkg from "../../../../../../package.json" assert {type: "json"}
|
||||
import { type StatusCode } from "hono/utils/http-status"
|
||||
import { z } from "zod"
|
||||
import { FileSchemas } from "../../../../lib/schemas/index.js"
|
||||
|
||||
const router = new Hono<{
|
||||
Variables: {
|
||||
account: Accounts.Account
|
||||
account: Accounts.Account,
|
||||
parsedSchema: any
|
||||
},
|
||||
Bindings: HttpBindings
|
||||
}>()
|
||||
|
|
Loading…
Reference in a new issue