@lbu/server
Advanced tools
Comparing version 0.0.62 to 0.0.63
{ | ||
"name": "@lbu/server", | ||
"version": "0.0.62", | ||
"version": "0.0.63", | ||
"description": "Koa server and common middleware", | ||
@@ -19,4 +19,4 @@ "main": "./index.js", | ||
"dependencies": { | ||
"@lbu/insight": "0.0.62", | ||
"@lbu/stdlib": "0.0.62", | ||
"@lbu/insight": "0.0.63", | ||
"@lbu/stdlib": "0.0.63", | ||
"formidable": "2.0.0-canary.20200504.1", | ||
@@ -26,4 +26,3 @@ "keygrip": "1.1.0", | ||
"koa-body": "4.2.0", | ||
"koa-session": "6.0.0", | ||
"qs": "6.9.4" | ||
"koa-session": "6.0.0" | ||
}, | ||
@@ -51,3 +50,3 @@ "maintainers": [ | ||
}, | ||
"gitHead": "1cf32f25700229a1c20488776304a4c05884d88e" | ||
"gitHead": "a2a6732381f5b0a3460336afd90d611c6ba4447c" | ||
} |
import { AppError } from "@lbu/stdlib"; | ||
import formidable from "formidable"; | ||
import koaBody from "koa-body"; | ||
import qs from "qs"; | ||
@@ -11,3 +10,4 @@ /** | ||
* @param {IKoaBodyOptions} [bodyOpts={}] Options that will be passed to koa-body | ||
* @param {IFormidableBodyOptions} [multipartBodyOpts={}] Options that will be passed to formidable | ||
* @param {IFormidableBodyOptions} [multipartBodyOpts={}] Options that will be passed to | ||
* formidable | ||
* @returns {BodyParserPair} | ||
@@ -30,3 +30,4 @@ */ | ||
* | ||
* Source; https://github.com/node-formidable/formidable/blob/master/src/Formidable.js#L103 | ||
* Source; | ||
* https://github.com/node-formidable/formidable/blob/master/src/Formidable.js#L103 | ||
* | ||
@@ -48,17 +49,4 @@ * @param {IFormidableBodyOptions} opts | ||
let mockFields = ""; | ||
const fields = {}; | ||
const files = {}; | ||
// skips query string conversion for object/array | ||
// types, since this is done in the apiClient | ||
form.on("field", (name, value) => { | ||
// check if object | ||
if (value.indexOf("&") === 0) { | ||
mockFields = `${mockFields}&${value}`; | ||
} else { | ||
const mObj = { [name]: value }; | ||
mockFields = `${mockFields}&${qs.stringify(mObj)}`; | ||
} | ||
}); | ||
form.on("file", (name, file) => { | ||
@@ -75,11 +63,9 @@ if (Object.prototype.hasOwnProperty.call(files, name)) { | ||
form.on("error", (err) => { | ||
reject(AppError.serverError({ fields, files }, err)); | ||
reject(AppError.serverError({ files }, err)); | ||
}); | ||
form.on("end", () => { | ||
Object.assign(fields, qs.parse(mockFields)); | ||
resolve({ fields, files }); | ||
resolve({ files }); | ||
}); | ||
form.parse(ctx.req); | ||
}).then(({ fields, files }) => { | ||
ctx.request.body = fields; | ||
}).then(({ files }) => { | ||
ctx.request.files = files; | ||
@@ -86,0 +72,0 @@ return next(); |
7
56490
1789
+ Added@lbu/insight@0.0.63(transitive)
+ Added@lbu/stdlib@0.0.63(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedqs@6.14.0(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
- Removedqs@6.9.4
- Removed@lbu/insight@0.0.62(transitive)
- Removed@lbu/stdlib@0.0.62(transitive)
- Removedqs@6.9.4(transitive)
Updated@lbu/insight@0.0.63
Updated@lbu/stdlib@0.0.63