use multer instead

This commit is contained in:
cutestnekoaqua 2023-02-10 23:29:29 +01:00
parent 2ff3e68d94
commit 465cb5a570
2 changed files with 19 additions and 22 deletions

View file

@ -12,7 +12,6 @@ import { Instances, AccessTokens, Users } from "@/models/index.js";
import config from "@/config/index.js";
import endpoints from "./endpoints.js";
import compatibility from "./compatibility.js";
import {koaBody} from "koa-body";
import handler from "./api-handler.js";
import signup from "./private/signup.js";
import signin from "./private/signin.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,13 +44,6 @@ app.use(async (ctx, next) => {
await next();
});
app.use(
koaBody({
json: false,
multipart: true
})
);
app.use(
bodyParser({
// リクエストが multipart/form-data でない限りはJSONだと見なす
@ -54,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();
@ -75,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 {

View file

@ -3335,7 +3335,7 @@ packages:
/axios/0.24.0:
resolution: {integrity: sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==}
dependencies:
follow-redirects: 1.15.2
follow-redirects: 1.15.2_debug@4.3.4
transitivePeerDependencies:
- debug
dev: false
@ -3343,7 +3343,7 @@ packages:
/axios/0.25.0_debug@4.3.4:
resolution: {integrity: sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==}
dependencies:
follow-redirects: 1.15.2
follow-redirects: 1.15.2_debug@4.3.4
transitivePeerDependencies:
- debug
dev: true
@ -3351,7 +3351,7 @@ packages:
/axios/1.2.2:
resolution: {integrity: sha512-bz/J4gS2S3I7mpN/YZfGFTqhXTYzRho8Ay38w2otuuDR322KzFIWm/4W2K6gIwvWaws5n+mnb7D1lN9uD+QH6Q==}
dependencies:
follow-redirects: 1.15.2
follow-redirects: 1.15.2_debug@4.3.4
form-data: 4.0.0
proxy-from-env: 1.1.0
transitivePeerDependencies:
@ -3361,7 +3361,7 @@ packages:
/axios/1.3.2:
resolution: {integrity: sha512-1M3O703bYqYuPhbHeya5bnhpYVsDDRyQSabNja04mZtboLNSuZ4YrltestrLXfHgmzua4TpUqRiVKbiQuo2epw==}
dependencies:
follow-redirects: 1.15.2
follow-redirects: 1.15.2_debug@4.3.4
form-data: 4.0.0
proxy-from-env: 1.1.0
transitivePeerDependencies:
@ -6301,7 +6301,7 @@ packages:
readable-stream: 2.3.7
dev: true
/follow-redirects/1.15.2:
/follow-redirects/1.15.2_debug@4.3.4:
resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==}
engines: {node: '>=4.0'}
peerDependencies:
@ -6309,6 +6309,8 @@ packages:
peerDependenciesMeta:
debug:
optional: true
dependencies:
debug: 4.3.4
/for-each/0.3.3:
resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==}