use formidable instead

This commit is contained in:
cutestnekoaqua 2023-02-10 23:50:22 +01:00
parent 23ad352088
commit b8406ecaa4
No known key found for this signature in database
GPG key ID: 6BF0964A5069C1E0
3 changed files with 29 additions and 15 deletions

View file

@ -25,6 +25,7 @@
"@bull-board/api": "^4.6.4", "@bull-board/api": "^4.6.4",
"@bull-board/koa": "^4.6.4", "@bull-board/koa": "^4.6.4",
"@bull-board/ui": "^4.6.4", "@bull-board/ui": "^4.6.4",
"@cutls/megalodon": "5.1.15",
"@discordapp/twemoji": "14.0.2", "@discordapp/twemoji": "14.0.2",
"@elastic/elasticsearch": "7.17.0", "@elastic/elasticsearch": "7.17.0",
"@koa/cors": "3.4.3", "@koa/cors": "3.4.3",
@ -37,12 +38,11 @@
"@tensorflow/tfjs": "^4.2.0", "@tensorflow/tfjs": "^4.2.0",
"ajv": "8.11.2", "ajv": "8.11.2",
"archiver": "5.3.1", "archiver": "5.3.1",
"koa-body": "^6.0.1",
"autobind-decorator": "2.4.0", "autobind-decorator": "2.4.0",
"autolinker": "4.0.0", "autolinker": "4.0.0",
"axios": "^1.3.2",
"autwh": "0.1.0", "autwh": "0.1.0",
"aws-sdk": "2.1277.0", "aws-sdk": "2.1277.0",
"axios": "^1.3.2",
"bcryptjs": "2.4.3", "bcryptjs": "2.4.3",
"blurhash": "1.1.5", "blurhash": "1.1.5",
"bull": "4.10.2", "bull": "4.10.2",
@ -71,6 +71,7 @@
"jsonld": "6.0.0", "jsonld": "6.0.0",
"jsrsasign": "10.6.1", "jsrsasign": "10.6.1",
"koa": "2.13.4", "koa": "2.13.4",
"koa-body": "^6.0.1",
"koa-bodyparser": "4.3.0", "koa-bodyparser": "4.3.0",
"koa-favicon": "2.1.0", "koa-favicon": "2.1.0",
"koa-json-body": "5.3.0", "koa-json-body": "5.3.0",
@ -79,7 +80,7 @@
"koa-send": "5.0.1", "koa-send": "5.0.1",
"koa-slow": "2.1.0", "koa-slow": "2.1.0",
"koa-views": "7.0.2", "koa-views": "7.0.2",
"@cutls/megalodon": "5.1.15", "koa2-formidable": "^1.0.3",
"mfm-js": "0.23.2", "mfm-js": "0.23.2",
"mime-types": "2.1.35", "mime-types": "2.1.35",
"multer": "1.4.4-lts.1", "multer": "1.4.4-lts.1",

View file

@ -6,6 +6,7 @@ import Koa from "koa";
import Router from "@koa/router"; import Router from "@koa/router";
import multer from "@koa/multer"; import multer from "@koa/multer";
import bodyParser from "koa-bodyparser"; import bodyParser from "koa-bodyparser";
const formidable = require('koa2-formidable')
import cors from "@koa/cors"; import cors from "@koa/cors";
import { apiMastodonCompatible } from './mastodon/ApiMastodonCompatibleService.js'; import { apiMastodonCompatible } from './mastodon/ApiMastodonCompatibleService.js';
import { Instances, AccessTokens, Users } from "@/models/index.js"; import { Instances, AccessTokens, Users } from "@/models/index.js";
@ -23,15 +24,6 @@ import twitter from "./service/twitter.js";
// Init app // Init app
const app = new Koa(); const app = new Koa();
// Init multer instance
const upload = multer({
storage: multer.diskStorage({}),
limits: {
fileSize: config.maxFileSize || 262144000,
files: 1,
},
});
app.use( app.use(
cors({ cors({
origin: "*", origin: "*",
@ -44,6 +36,8 @@ app.use(async (ctx, next) => {
await next(); await next();
}); });
app.use(formidable());
app.use( app.use(
bodyParser({ bodyParser({
// リクエストが multipart/form-data でない限りはJSONだと見なす // リクエストが multipart/form-data でない限りはJSONだと見なす
@ -55,9 +49,14 @@ app.use(
}), }),
); );
app.use( // Init multer instance
upload.any() const upload = multer({
); storage: multer.diskStorage({}),
limits: {
fileSize: config.maxFileSize || 262144000,
files: 1,
},
});
// Init router // Init router
const router = new Router(); const router = new Router();
@ -71,6 +70,7 @@ for (const endpoint of [...endpoints, ...compatibility]) {
if (endpoint.meta.requireFile) { if (endpoint.meta.requireFile) {
router.post( router.post(
`/${endpoint.name}`, `/${endpoint.name}`,
upload.single("file"),
handler.bind(null, endpoint), handler.bind(null, endpoint),
); );
} else { } else {

View file

@ -164,6 +164,7 @@ importers:
koa-send: 5.0.1 koa-send: 5.0.1
koa-slow: 2.1.0 koa-slow: 2.1.0
koa-views: 7.0.2 koa-views: 7.0.2
koa2-formidable: ^1.0.3
mfm-js: 0.23.2 mfm-js: 0.23.2
mime-types: 2.1.35 mime-types: 2.1.35
mocha: 10.2.0 mocha: 10.2.0
@ -278,6 +279,7 @@ importers:
koa-send: 5.0.1 koa-send: 5.0.1
koa-slow: 2.1.0 koa-slow: 2.1.0
koa-views: 7.0.2_6tybghmia4wsnt33xeid7y4rby koa-views: 7.0.2_6tybghmia4wsnt33xeid7y4rby
koa2-formidable: 1.0.3
mfm-js: 0.23.2 mfm-js: 0.23.2
mime-types: 2.1.35 mime-types: 2.1.35
multer: 1.4.4-lts.1 multer: 1.4.4-lts.1
@ -6370,6 +6372,11 @@ packages:
dependencies: dependencies:
fetch-blob: 3.2.0 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: /formidable/2.1.1:
resolution: {integrity: sha512-0EcS9wCFEzLvfiks7omJ+SiYJAiD+TzK4Pcw1UlUoGnhUxDcMKjt0P7x8wEb0u6OHu8Nb98WG3nxtlF5C7bvUQ==} resolution: {integrity: sha512-0EcS9wCFEzLvfiks7omJ+SiYJAiD+TzK4Pcw1UlUoGnhUxDcMKjt0P7x8wEb0u6OHu8Nb98WG3nxtlF5C7bvUQ==}
dependencies: dependencies:
@ -8381,6 +8388,12 @@ packages:
- supports-color - supports-color
dev: false 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: /ky-universal/0.10.1_ky@0.30.0:
resolution: {integrity: sha512-r8909k+ELKZAxhVA5c440x22hqw5XcMRwLRbgpPQk4JHy3/ddJnvzcnSo5Ww3HdKdNeS3Y8dBgcIYyVahMa46g==} resolution: {integrity: sha512-r8909k+ELKZAxhVA5c440x22hqw5XcMRwLRbgpPQk4JHy3/ddJnvzcnSo5Ww3HdKdNeS3Y8dBgcIYyVahMa46g==}
engines: {node: '>=14'} engines: {node: '>=14'}