diff --git a/src/server/lib/files.ts b/src/server/lib/files.ts index ab2e96a..9cf3f0a 100644 --- a/src/server/lib/files.ts +++ b/src/server/lib/files.ts @@ -434,8 +434,9 @@ export class UploadStream extends Writable { chunkSize: this.files.config.maxDiscordFileSize } - await this.files.write() delete this.files.locks[this.uploadId!] + await this.files.api.deleteMessages(ogf.messageids) + await this.files.write() if (this.owner) Accounts.files.index(this.owner, this.uploadId!) return this.uploadId } @@ -627,16 +628,16 @@ export default class Files { async unlink(uploadId: string, noWrite: boolean = false): Promise { let target = this.files[uploadId] if (!target) return + + await this.api.deleteMessages(target.messageids) + if (target.owner) { let id = files.deindex(target.owner, uploadId, noWrite) if (id) await id } - - await this.api.deleteMessages(target.messageids) - delete this.files[uploadId] - if (noWrite) return - return this.write().catch((err) => { + + if (!noWrite) this.write().catch((err) => { throw err }) } diff --git a/src/server/routes/api/v1/account.ts b/src/server/routes/api/v1/account.ts index 7a976f3..cf3b36a 100644 --- a/src/server/routes/api/v1/account.ts +++ b/src/server/routes/api/v1/account.ts @@ -212,8 +212,8 @@ export default function (files: Files) { requiresPermissions("manage"), async (ctx) => { const body = await ctx.req.json() as UserUpdateParameters - const actor = ctx.get("account")! as Accounts.Account - const target = ctx.get("target")! as Accounts.Account + const actor = ctx.get("account")! + const target = ctx.get("target")! if (Array.isArray(body)) return ServeError(ctx, 400, "invalid body") @@ -240,9 +240,7 @@ export default function (files: Files) { ) router.delete("/:user", requiresAccount, noAPIAccess, async (ctx) => { - let acc = ctx.req.param("user") == "me" ? ctx.get("account") : Accounts.getFromId(ctx.req.param("user")) - if (acc != ctx.get("account") && !ctx.get("account")?.admin) return ServeError(ctx, 403, "you are not an administrator") - if (!acc) return ServeError(ctx, 404, "account does not exist") + let acc = ctx.get("target") auth.AuthTokens.filter((e) => e.account == acc?.id).forEach( (token) => { @@ -266,5 +264,7 @@ export default function (files: Files) { return ctx.text("account deleted") }) + router.get("/:user") + return router }