From 450c92f3e760e1f6311329efb052a963406d6e66 Mon Sep 17 00:00:00 2001 From: cutestnekoaqua Date: Sat, 11 Feb 2023 00:15:40 +0100 Subject: [PATCH] Revert "use formidable instead" This reverts commit b8406ecaa40c08576d2644b797e05363533b0cfb. --- packages/backend/package.json | 7 +++---- packages/backend/src/server/api/index.ts | 24 ++++++++++++------------ pnpm-lock.yaml | 13 ------------- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/packages/backend/package.json b/packages/backend/package.json index a629a96cc..80484f95c 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -25,7 +25,6 @@ "@bull-board/api": "^4.6.4", "@bull-board/koa": "^4.6.4", "@bull-board/ui": "^4.6.4", - "@cutls/megalodon": "5.1.15", "@discordapp/twemoji": "14.0.2", "@elastic/elasticsearch": "7.17.0", "@koa/cors": "3.4.3", @@ -38,11 +37,12 @@ "@tensorflow/tfjs": "^4.2.0", "ajv": "8.11.2", "archiver": "5.3.1", + "koa-body": "^6.0.1", "autobind-decorator": "2.4.0", "autolinker": "4.0.0", + "axios": "^1.3.2", "autwh": "0.1.0", "aws-sdk": "2.1277.0", - "axios": "^1.3.2", "bcryptjs": "2.4.3", "blurhash": "1.1.5", "bull": "4.10.2", @@ -71,7 +71,6 @@ "jsonld": "6.0.0", "jsrsasign": "10.6.1", "koa": "2.13.4", - "koa-body": "^6.0.1", "koa-bodyparser": "4.3.0", "koa-favicon": "2.1.0", "koa-json-body": "5.3.0", @@ -80,7 +79,7 @@ "koa-send": "5.0.1", "koa-slow": "2.1.0", "koa-views": "7.0.2", - "koa2-formidable": "^1.0.3", + "@cutls/megalodon": "5.1.15", "mfm-js": "0.23.2", "mime-types": "2.1.35", "multer": "1.4.4-lts.1", diff --git a/packages/backend/src/server/api/index.ts b/packages/backend/src/server/api/index.ts index ddcb9a884..593c7a284 100644 --- a/packages/backend/src/server/api/index.ts +++ b/packages/backend/src/server/api/index.ts @@ -6,7 +6,6 @@ import Koa from "koa"; import Router from "@koa/router"; import multer from "@koa/multer"; import bodyParser from "koa-bodyparser"; -const formidable = require('koa2-formidable') import cors from "@koa/cors"; import { apiMastodonCompatible } from './mastodon/ApiMastodonCompatibleService.js'; import { Instances, AccessTokens, Users } from "@/models/index.js"; @@ -24,6 +23,15 @@ import twitter from "./service/twitter.js"; // Init app const app = new Koa(); +// Init multer instance +const upload = multer({ + storage: multer.diskStorage({}), + limits: { + fileSize: config.maxFileSize || 262144000, + files: 1, + }, +}); + app.use( cors({ origin: "*", @@ -36,8 +44,6 @@ app.use(async (ctx, next) => { await next(); }); -app.use(formidable()); - app.use( bodyParser({ // リクエストが multipart/form-data でない限りはJSONだと見なす @@ -49,14 +55,9 @@ app.use( }), ); -// Init multer instance -const upload = multer({ - storage: multer.diskStorage({}), - limits: { - fileSize: config.maxFileSize || 262144000, - files: 1, - }, -}); +app.use( + upload.any() +); // Init router const router = new Router(); @@ -70,7 +71,6 @@ for (const endpoint of [...endpoints, ...compatibility]) { if (endpoint.meta.requireFile) { router.post( `/${endpoint.name}`, - upload.single("file"), handler.bind(null, endpoint), ); } else { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5c6765f2e..54880d9c9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -164,7 +164,6 @@ importers: koa-send: 5.0.1 koa-slow: 2.1.0 koa-views: 7.0.2 - koa2-formidable: ^1.0.3 mfm-js: 0.23.2 mime-types: 2.1.35 mocha: 10.2.0 @@ -279,7 +278,6 @@ importers: koa-send: 5.0.1 koa-slow: 2.1.0 koa-views: 7.0.2_6tybghmia4wsnt33xeid7y4rby - koa2-formidable: 1.0.3 mfm-js: 0.23.2 mime-types: 2.1.35 multer: 1.4.4-lts.1 @@ -6372,11 +6370,6 @@ packages: dependencies: fetch-blob: 3.2.0 - /formidable/1.2.6: - resolution: {integrity: sha512-KcpbcpuLNOwrEjnbpMC0gS+X8ciDoZE1kkqzat4a8vrprf+s9pKNQ/QIwWfbfs4ltgmFl3MD177SNTkve3BwGQ==} - deprecated: 'Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau' - dev: false - /formidable/2.1.1: resolution: {integrity: sha512-0EcS9wCFEzLvfiks7omJ+SiYJAiD+TzK4Pcw1UlUoGnhUxDcMKjt0P7x8wEb0u6OHu8Nb98WG3nxtlF5C7bvUQ==} dependencies: @@ -8388,12 +8381,6 @@ packages: - supports-color dev: false - /koa2-formidable/1.0.3: - resolution: {integrity: sha512-m80sje/vb4mvhZn7HbZPwYHnsGjKL+oJ4OasNbH+jdvjIddVMPmugmmBwPnMYDGaMnL0tT9mJrfKRcp8MMdNyQ==} - dependencies: - formidable: 1.2.6 - dev: false - /ky-universal/0.10.1_ky@0.30.0: resolution: {integrity: sha512-r8909k+ELKZAxhVA5c440x22hqw5XcMRwLRbgpPQk4JHy3/ddJnvzcnSo5Ww3HdKdNeS3Y8dBgcIYyVahMa46g==} engines: {node: '>=14'}