From f5537af8a12369b859daa0366735371addbfe31f Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 00:31:14 +0100 Subject: [PATCH] aaa --- packages/backend/src/server/api/index.ts | 1 + .../src/server/api/mastodon/endpoints/status.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/server/api/index.ts b/packages/backend/src/server/api/index.ts index 3ea3ff67e7..0f58d3acfc 100644 --- a/packages/backend/src/server/api/index.ts +++ b/packages/backend/src/server/api/index.ts @@ -171,6 +171,7 @@ errorRouter.all("(.*)", async (ctx) => { // Register router app.use(mastoRouter.routes()); +app.use(mastoRouter.allowedMethods()); app.use(router.routes()); app.use(errorRouter.routes()); diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index a72ac2c7e0..0ba1e42297 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -289,14 +289,16 @@ export function apiStatusMastodon(router: Router): void { const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); try { - const multipartData = await ctx.file; + let multipartData = await ctx.request.files; if (!multipartData) { ctx.body = { error: "No image" }; + ctx.status = 401; return; } - const [path] = await createTemp(); - await pump(multipartData.buffer, fs.createWriteStream(path)); - const image = fs.readFileSync(path); + if ((multipartData as any).file) { + multipartData = (multipartData as any).file; + } + const image = fs.readFileSync((multipartData as any).path); const data = await client.uploadMedia(image); ctx.body = data.data; } catch (e: any) { @@ -313,6 +315,7 @@ export function apiStatusMastodon(router: Router): void { const multipartData = await ctx.file; if (!multipartData) { ctx.body = { error: "No image" }; + ctx.status = 401; return; } const [path] = await createTemp();