Skip to content

Commit

Permalink
Merge pull request #5 from kato/feature/multifiles
Browse files Browse the repository at this point in the history
文件上传时, 参数默认解析成数组
  • Loading branch information
raintean authored Apr 29, 2020
2 parents 476219e + 39ba6a2 commit 10339d7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 25 deletions.
4 changes: 2 additions & 2 deletions core/middleware/parameter/multipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default async function multipart(ctx: Context, next: Middleware) {

//解析multipart数据
const multipartParser = middlewareWrapper(multer({
storage: ctx.kato.options.files.storage || multer.memoryStorage(),
storage: ctx.kato.options.files.storage ?? multer.memoryStorage(),
limits: {
files: ctx.kato.options.files.maxCount,
fileSize: ctx.kato.options.files.maxSize
Expand All @@ -30,7 +30,7 @@ export default async function multipart(ctx: Context, next: Middleware) {
//文件解析
req.files && req.files.forEach(file => {
if (ctx.method.parameters.findIndex(p => p.name === file.fieldname) !== -1) {
ctx.parameters[file.fieldname] = file;
(ctx.parameters[file.fieldname] = (ctx.parameters[file.fieldname] ?? [])).push(file);
}
});

Expand Down
68 changes: 48 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kato-server",
"version": "2.1.1",
"version": "3.0.0-alpha.1",
"description": "kato server",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -40,6 +40,7 @@
"@babel/preset-env": "^7.5.5",
"@types/express": "^4.17.1",
"@types/jest": "^24.0.18",
"@types/multer": "^1.4.3",
"@types/node": "^12.7.2",
"@types/supertest": "^2.0.8",
"babel-core": "^7.0.0-bridge.0",
Expand All @@ -52,8 +53,8 @@
"nodemon-webpack-plugin": "^4.0.8",
"source-map-support": "^0.5.13",
"supertest": "^4.0.2",
"ts-loader": "^6.0.4",
"typescript": "^3.6.2",
"ts-loader": "^6.2.2",
"typescript": "^3.8.3",
"webpack": "^4.39.3",
"webpack-cli": "^3.3.7",
"webpack-merge": "^4.2.2",
Expand Down

0 comments on commit 10339d7

Please sign in to comment.