graphql-upload 12.0.0 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +25 -25
- package/private/GRAPHQL_MULTIPART_REQUEST_SPEC_URL.js +2 -2
- package/private/ignoreStream.js +2 -2
- package/public/GraphQLUpload.js +19 -19
- package/public/Upload.js +5 -5
- package/public/graphqlUploadExpress.js +13 -13
- package/public/graphqlUploadKoa.js +13 -13
- package/public/index.js +6 -6
- package/public/index.mjs +5 -5
- package/public/processRequest.js +65 -78
- package/readme.md +40 -42
- package/changelog.md +0 -530
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-upload",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.0",
|
|
4
4
|
"description": "Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -38,48 +38,48 @@
|
|
|
38
38
|
"require": "./public/index.js"
|
|
39
39
|
},
|
|
40
40
|
"./public/*": "./public/*",
|
|
41
|
-
"./package": "./package.json",
|
|
42
41
|
"./package.json": "./package.json"
|
|
43
42
|
},
|
|
44
43
|
"engines": {
|
|
45
|
-
"node": "^12.
|
|
44
|
+
"node": "^12.22.0 || ^14.17.0 || >= 16.0.0"
|
|
46
45
|
},
|
|
47
46
|
"peerDependencies": {
|
|
48
|
-
"graphql": "0.13.1 -
|
|
47
|
+
"graphql": "0.13.1 - 16"
|
|
49
48
|
},
|
|
50
49
|
"dependencies": {
|
|
51
50
|
"busboy": "^0.3.1",
|
|
52
51
|
"fs-capacitor": "^6.2.0",
|
|
53
|
-
"http-errors": "^1.8.
|
|
54
|
-
"
|
|
55
|
-
"object-path": "^0.11.5"
|
|
52
|
+
"http-errors": "^1.8.1",
|
|
53
|
+
"object-path": "^0.11.8"
|
|
56
54
|
},
|
|
57
55
|
"devDependencies": {
|
|
58
56
|
"coverage-node": "^5.0.1",
|
|
59
|
-
"eslint": "^
|
|
60
|
-
"eslint-config-env": "^
|
|
57
|
+
"eslint": "^8.3.0",
|
|
58
|
+
"eslint-config-env": "^23.0.0",
|
|
61
59
|
"eslint-config-prettier": "^8.3.0",
|
|
62
|
-
"eslint-plugin-import": "^2.
|
|
63
|
-
"eslint-plugin-jsdoc": "^
|
|
60
|
+
"eslint-plugin-import": "^2.25.3",
|
|
61
|
+
"eslint-plugin-jsdoc": "^37.0.3",
|
|
64
62
|
"eslint-plugin-node": "^11.1.0",
|
|
65
|
-
"eslint-plugin-prettier": "^
|
|
63
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
66
64
|
"express": "^4.17.1",
|
|
67
|
-
"form-data": "^
|
|
68
|
-
"
|
|
65
|
+
"form-data-encoder": "^1.7.1",
|
|
66
|
+
"formdata-node": "^4.3.1",
|
|
67
|
+
"graphql": "^16.0.1",
|
|
69
68
|
"hard-rejection": "^2.1.0",
|
|
70
|
-
"jsdoc-md": "^
|
|
71
|
-
"koa": "^2.13.
|
|
72
|
-
"node-
|
|
73
|
-
"
|
|
74
|
-
"
|
|
69
|
+
"jsdoc-md": "^11.0.2",
|
|
70
|
+
"koa": "^2.13.4",
|
|
71
|
+
"node-abort-controller": "^3.0.1",
|
|
72
|
+
"node-fetch": "^3.1.0",
|
|
73
|
+
"prettier": "^2.5.0",
|
|
74
|
+
"test-director": "^7.0.0"
|
|
75
75
|
},
|
|
76
76
|
"scripts": {
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"test
|
|
77
|
+
"docs-update": "jsdoc-md",
|
|
78
|
+
"docs-check": "jsdoc-md -c",
|
|
79
|
+
"eslint": "eslint .",
|
|
80
|
+
"prettier": "prettier -c .",
|
|
81
|
+
"tests": "coverage-node -r hard-rejection/register test/index.mjs",
|
|
82
|
+
"test": "npm run eslint && npm run prettier && npm run docs-check && npm run tests",
|
|
83
83
|
"prepublishOnly": "npm test"
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* [GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec)
|
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
* @ignore
|
|
10
10
|
*/
|
|
11
11
|
module.exports =
|
|
12
|
-
|
|
12
|
+
"https://github.com/jaydenseric/graphql-multipart-request-spec";
|
package/private/ignoreStream.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Safely ignores a Node.js readable stream.
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
module.exports = function ignoreStream(stream) {
|
|
11
11
|
// Prevent an unhandled error from crashing the process.
|
|
12
|
-
stream.on(
|
|
12
|
+
stream.on("error", () => {});
|
|
13
13
|
|
|
14
14
|
// Waste the stream.
|
|
15
15
|
stream.resume();
|
package/public/GraphQLUpload.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// https://github.com/gajus/eslint-plugin-jsdoc/issues/710
|
|
3
3
|
/* eslint-disable jsdoc/check-examples */
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
"use strict";
|
|
6
6
|
|
|
7
|
-
const { GraphQLScalarType, GraphQLError } = require(
|
|
8
|
-
const Upload = require(
|
|
7
|
+
const { GraphQLScalarType, GraphQLError } = require("graphql");
|
|
8
|
+
const Upload = require("./Upload");
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* A GraphQL `Upload` scalar that can be used in a
|
|
@@ -16,24 +16,24 @@ const Upload = require('./Upload');
|
|
|
16
16
|
* @name GraphQLUpload
|
|
17
17
|
* @example <caption>Ways to `import`.</caption>
|
|
18
18
|
* ```js
|
|
19
|
-
* import { GraphQLUpload } from
|
|
19
|
+
* import { GraphQLUpload } from "graphql-upload";
|
|
20
20
|
* ```
|
|
21
21
|
*
|
|
22
22
|
* ```js
|
|
23
|
-
* import GraphQLUpload from
|
|
23
|
+
* import GraphQLUpload from "graphql-upload/public/GraphQLUpload.js";
|
|
24
24
|
* ```
|
|
25
25
|
* @example <caption>Ways to `require`.</caption>
|
|
26
26
|
* ```js
|
|
27
|
-
* const { GraphQLUpload } = require(
|
|
27
|
+
* const { GraphQLUpload } = require("graphql-upload");
|
|
28
28
|
* ```
|
|
29
29
|
*
|
|
30
30
|
* ```js
|
|
31
|
-
* const GraphQLUpload = require(
|
|
31
|
+
* const GraphQLUpload = require("graphql-upload/public/GraphQLUpload.js");
|
|
32
32
|
* ```
|
|
33
33
|
* @example <caption>A schema built using [`makeExecutableSchema`](https://www.graphql-tools.com/docs/api/modules/schema#makeexecutableschema) from [`@graphql-tools/schema`](https://npm.im/@graphql-tools/schema).</caption>
|
|
34
34
|
* ```js
|
|
35
|
-
* const { makeExecutableSchema } = require(
|
|
36
|
-
* const { GraphQLUpload } = require(
|
|
35
|
+
* const { makeExecutableSchema } = require("@graphql-tools/schema");
|
|
36
|
+
* const { GraphQLUpload } = require("graphql-upload");
|
|
37
37
|
*
|
|
38
38
|
* const schema = makeExecutableSchema({
|
|
39
39
|
* typeDefs: /* GraphQL *\/ `
|
|
@@ -46,19 +46,19 @@ const Upload = require('./Upload');
|
|
|
46
46
|
* ```
|
|
47
47
|
* @example <caption>A manually constructed schema with an image upload mutation.</caption>
|
|
48
48
|
* ```js
|
|
49
|
-
* const { GraphQLSchema, GraphQLObjectType, GraphQLBoolean } = require(
|
|
50
|
-
* const { GraphQLUpload } = require(
|
|
49
|
+
* const { GraphQLSchema, GraphQLObjectType, GraphQLBoolean } = require("graphql");
|
|
50
|
+
* const { GraphQLUpload } = require("graphql-upload");
|
|
51
51
|
*
|
|
52
52
|
* const schema = new GraphQLSchema({
|
|
53
53
|
* mutation: new GraphQLObjectType({
|
|
54
|
-
* name:
|
|
54
|
+
* name: "Mutation",
|
|
55
55
|
* fields: {
|
|
56
56
|
* uploadImage: {
|
|
57
|
-
* description:
|
|
57
|
+
* description: "Uploads an image.",
|
|
58
58
|
* type: GraphQLBoolean,
|
|
59
59
|
* args: {
|
|
60
60
|
* image: {
|
|
61
|
-
* description:
|
|
61
|
+
* description: "Image file.",
|
|
62
62
|
* type: GraphQLUpload,
|
|
63
63
|
* },
|
|
64
64
|
* },
|
|
@@ -75,16 +75,16 @@ const Upload = require('./Upload');
|
|
|
75
75
|
* ```
|
|
76
76
|
*/
|
|
77
77
|
module.exports = new GraphQLScalarType({
|
|
78
|
-
name:
|
|
79
|
-
description:
|
|
78
|
+
name: "Upload",
|
|
79
|
+
description: "The `Upload` scalar type represents a file upload.",
|
|
80
80
|
parseValue(value) {
|
|
81
81
|
if (value instanceof Upload) return value.promise;
|
|
82
|
-
throw new GraphQLError(
|
|
82
|
+
throw new GraphQLError("Upload value invalid.");
|
|
83
83
|
},
|
|
84
84
|
parseLiteral(ast) {
|
|
85
|
-
throw new GraphQLError(
|
|
85
|
+
throw new GraphQLError("Upload literal unsupported.", ast);
|
|
86
86
|
},
|
|
87
87
|
serialize() {
|
|
88
|
-
throw new GraphQLError(
|
|
88
|
+
throw new GraphQLError("Upload serialization unsupported.");
|
|
89
89
|
},
|
|
90
90
|
});
|
package/public/Upload.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A file expected to be uploaded as it has been declared in the `map` field of
|
|
@@ -12,19 +12,19 @@
|
|
|
12
12
|
* @name Upload
|
|
13
13
|
* @example <caption>Ways to `import`.</caption>
|
|
14
14
|
* ```js
|
|
15
|
-
* import { Upload } from
|
|
15
|
+
* import { Upload } from "graphql-upload";
|
|
16
16
|
* ```
|
|
17
17
|
*
|
|
18
18
|
* ```js
|
|
19
|
-
* import Upload from
|
|
19
|
+
* import Upload from "graphql-upload/public/Upload.js";
|
|
20
20
|
* ```
|
|
21
21
|
* @example <caption>Ways to `require`.</caption>
|
|
22
22
|
* ```js
|
|
23
|
-
* const { Upload } = require(
|
|
23
|
+
* const { Upload } = require("graphql-upload");
|
|
24
24
|
* ```
|
|
25
25
|
*
|
|
26
26
|
* ```js
|
|
27
|
-
* const Upload = require(
|
|
27
|
+
* const Upload = require("graphql-upload/public/Upload.js");
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
module.exports = class Upload {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
const defaultProcessRequest = require(
|
|
3
|
+
const defaultProcessRequest = require("./processRequest");
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Creates [Express](https://expressjs.com) middleware that processes
|
|
@@ -16,30 +16,30 @@ const defaultProcessRequest = require('./processRequest');
|
|
|
16
16
|
* @returns {Function} Express middleware.
|
|
17
17
|
* @example <caption>Ways to `import`.</caption>
|
|
18
18
|
* ```js
|
|
19
|
-
* import { graphqlUploadExpress } from
|
|
19
|
+
* import { graphqlUploadExpress } from "graphql-upload";
|
|
20
20
|
* ```
|
|
21
21
|
*
|
|
22
22
|
* ```js
|
|
23
|
-
* import graphqlUploadExpress from
|
|
23
|
+
* import graphqlUploadExpress from "graphql-upload/public/graphqlUploadExpress.js";
|
|
24
24
|
* ```
|
|
25
25
|
* @example <caption>Ways to `require`.</caption>
|
|
26
26
|
* ```js
|
|
27
|
-
* const { graphqlUploadExpress } = require(
|
|
27
|
+
* const { graphqlUploadExpress } = require("graphql-upload");
|
|
28
28
|
* ```
|
|
29
29
|
*
|
|
30
30
|
* ```js
|
|
31
|
-
* const graphqlUploadExpress = require(
|
|
31
|
+
* const graphqlUploadExpress = require("graphql-upload/public/graphqlUploadExpress.js");
|
|
32
32
|
* ```
|
|
33
33
|
* @example <caption>Basic [`express-graphql`](https://npm.im/express-graphql) setup.</caption>
|
|
34
34
|
* ```js
|
|
35
|
-
* const express = require(
|
|
36
|
-
* const graphqlHTTP = require(
|
|
37
|
-
* const { graphqlUploadExpress } = require(
|
|
38
|
-
* const schema = require(
|
|
35
|
+
* const express = require("express");
|
|
36
|
+
* const graphqlHTTP = require("express-graphql");
|
|
37
|
+
* const { graphqlUploadExpress } = require("graphql-upload");
|
|
38
|
+
* const schema = require("./schema");
|
|
39
39
|
*
|
|
40
40
|
* express()
|
|
41
41
|
* .use(
|
|
42
|
-
*
|
|
42
|
+
* "/graphql",
|
|
43
43
|
* graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }),
|
|
44
44
|
* graphqlHTTP({ schema })
|
|
45
45
|
* )
|
|
@@ -51,9 +51,9 @@ module.exports = function graphqlUploadExpress({
|
|
|
51
51
|
...processRequestOptions
|
|
52
52
|
} = {}) {
|
|
53
53
|
return function graphqlUploadExpressMiddleware(request, response, next) {
|
|
54
|
-
if (!request.is(
|
|
54
|
+
if (!request.is("multipart/form-data")) return next();
|
|
55
55
|
|
|
56
|
-
const finished = new Promise((resolve) => request.on(
|
|
56
|
+
const finished = new Promise((resolve) => request.on("end", resolve));
|
|
57
57
|
const { send } = response;
|
|
58
58
|
|
|
59
59
|
response.send = (...args) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
const defaultProcessRequest = require(
|
|
3
|
+
const defaultProcessRequest = require("./processRequest");
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Creates [Koa](https://koajs.com) middleware that processes
|
|
@@ -16,27 +16,27 @@ const defaultProcessRequest = require('./processRequest');
|
|
|
16
16
|
* @returns {Function} Koa middleware.
|
|
17
17
|
* @example <caption>Ways to `import`.</caption>
|
|
18
18
|
* ```js
|
|
19
|
-
* import { graphqlUploadKoa } from
|
|
19
|
+
* import { graphqlUploadKoa } from "graphql-upload";
|
|
20
20
|
* ```
|
|
21
21
|
*
|
|
22
22
|
* ```js
|
|
23
|
-
* import graphqlUploadKoa from
|
|
23
|
+
* import graphqlUploadKoa from "graphql-upload/public/graphqlUploadKoa.js";
|
|
24
24
|
* ```
|
|
25
25
|
* @example <caption>Ways to `require`.</caption>
|
|
26
26
|
* ```js
|
|
27
|
-
* const { graphqlUploadKoa } = require(
|
|
27
|
+
* const { graphqlUploadKoa } = require("graphql-upload");
|
|
28
28
|
* ```
|
|
29
29
|
*
|
|
30
30
|
* ```js
|
|
31
|
-
* const graphqlUploadKoa = require(
|
|
31
|
+
* const graphqlUploadKoa = require("graphql-upload/public/graphqlUploadKoa.js");
|
|
32
32
|
* ```
|
|
33
33
|
* @example <caption>Basic [`graphql-api-koa`](https://npm.im/graphql-api-koa) setup.</caption>
|
|
34
34
|
* ```js
|
|
35
|
-
* const Koa = require(
|
|
36
|
-
* const bodyParser = require(
|
|
37
|
-
* const { errorHandler, execute } = require(
|
|
38
|
-
* const { graphqlUploadKoa } = require(
|
|
39
|
-
* const schema = require(
|
|
35
|
+
* const Koa = require("koa");
|
|
36
|
+
* const bodyParser = require("koa-bodyparser");
|
|
37
|
+
* const { errorHandler, execute } = require("graphql-api-koa");
|
|
38
|
+
* const { graphqlUploadKoa } = require("graphql-upload");
|
|
39
|
+
* const schema = require("./schema");
|
|
40
40
|
*
|
|
41
41
|
* new Koa()
|
|
42
42
|
* .use(errorHandler())
|
|
@@ -51,9 +51,9 @@ module.exports = function graphqlUploadKoa({
|
|
|
51
51
|
...processRequestOptions
|
|
52
52
|
} = {}) {
|
|
53
53
|
return async function graphqlUploadKoaMiddleware(ctx, next) {
|
|
54
|
-
if (!ctx.request.is(
|
|
54
|
+
if (!ctx.request.is("multipart/form-data")) return next();
|
|
55
55
|
|
|
56
|
-
const finished = new Promise((resolve) => ctx.req.on(
|
|
56
|
+
const finished = new Promise((resolve) => ctx.req.on("end", resolve));
|
|
57
57
|
|
|
58
58
|
try {
|
|
59
59
|
ctx.request.body = await processRequest(
|
package/public/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
exports.GraphQLUpload = require(
|
|
4
|
-
exports.processRequest = require(
|
|
5
|
-
exports.graphqlUploadKoa = require(
|
|
6
|
-
exports.graphqlUploadExpress = require(
|
|
7
|
-
exports.Upload = require(
|
|
3
|
+
exports.GraphQLUpload = require("./GraphQLUpload");
|
|
4
|
+
exports.processRequest = require("./processRequest");
|
|
5
|
+
exports.graphqlUploadKoa = require("./graphqlUploadKoa");
|
|
6
|
+
exports.graphqlUploadExpress = require("./graphqlUploadExpress");
|
|
7
|
+
exports.Upload = require("./Upload");
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* File upload details that are only available after the file’s field in the
|
package/public/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { default as GraphQLUpload } from
|
|
2
|
-
export { default as processRequest } from
|
|
3
|
-
export { default as graphqlUploadKoa } from
|
|
4
|
-
export { default as graphqlUploadExpress } from
|
|
5
|
-
export { default as Upload } from
|
|
1
|
+
export { default as GraphQLUpload } from "./GraphQLUpload.js";
|
|
2
|
+
export { default as processRequest } from "./processRequest.js";
|
|
3
|
+
export { default as graphqlUploadKoa } from "./graphqlUploadKoa.js";
|
|
4
|
+
export { default as graphqlUploadExpress } from "./graphqlUploadExpress.js";
|
|
5
|
+
export { default as Upload } from "./Upload.js";
|
package/public/processRequest.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
const Busboy = require(
|
|
4
|
-
const { WriteStream } = require(
|
|
5
|
-
const createError = require(
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const Upload = require('./Upload');
|
|
3
|
+
const Busboy = require("busboy");
|
|
4
|
+
const { WriteStream } = require("fs-capacitor");
|
|
5
|
+
const createError = require("http-errors");
|
|
6
|
+
const objectPath = require("object-path");
|
|
7
|
+
const GRAPHQL_MULTIPART_REQUEST_SPEC_URL = require("../private/GRAPHQL_MULTIPART_REQUEST_SPEC_URL");
|
|
8
|
+
const ignoreStream = require("../private/ignoreStream");
|
|
9
|
+
const Upload = require("./Upload");
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Processes a
|
|
@@ -27,19 +26,19 @@ const Upload = require('./Upload');
|
|
|
27
26
|
* @type {ProcessRequestFunction}
|
|
28
27
|
* @example <caption>Ways to `import`.</caption>
|
|
29
28
|
* ```js
|
|
30
|
-
* import { processRequest } from
|
|
29
|
+
* import { processRequest } from "graphql-upload";
|
|
31
30
|
* ```
|
|
32
31
|
*
|
|
33
32
|
* ```js
|
|
34
|
-
* import processRequest from
|
|
33
|
+
* import processRequest from "graphql-upload/public/processRequest.js";
|
|
35
34
|
* ```
|
|
36
35
|
* @example <caption>Ways to `require`.</caption>
|
|
37
36
|
* ```js
|
|
38
|
-
* const { processRequest } = require(
|
|
37
|
+
* const { processRequest } = require("graphql-upload");
|
|
39
38
|
* ```
|
|
40
39
|
*
|
|
41
40
|
* ```js
|
|
42
|
-
* const processRequest = require(
|
|
41
|
+
* const processRequest = require("graphql-upload/public/processRequest.js");
|
|
43
42
|
* ```
|
|
44
43
|
*/
|
|
45
44
|
module.exports = function processRequest(
|
|
@@ -54,7 +53,7 @@ module.exports = function processRequest(
|
|
|
54
53
|
return new Promise((resolve, reject) => {
|
|
55
54
|
let released;
|
|
56
55
|
let exitError;
|
|
57
|
-
let
|
|
56
|
+
let lastFileStream;
|
|
58
57
|
let operations;
|
|
59
58
|
let operationsPath;
|
|
60
59
|
let map;
|
|
@@ -77,14 +76,24 @@ module.exports = function processRequest(
|
|
|
77
76
|
* @ignore
|
|
78
77
|
*/
|
|
79
78
|
const exit = (error) => {
|
|
79
|
+
// None of the tested scenarios cause multiple calls of this function, but
|
|
80
|
+
// it’t still good to guard against it happening in case it’s possible now
|
|
81
|
+
// or in the future.
|
|
82
|
+
// coverage ignore next line
|
|
80
83
|
if (exitError) return;
|
|
84
|
+
|
|
81
85
|
exitError = error;
|
|
82
86
|
|
|
83
87
|
reject(exitError);
|
|
84
88
|
|
|
85
89
|
parser.destroy();
|
|
86
90
|
|
|
87
|
-
if (
|
|
91
|
+
if (
|
|
92
|
+
lastFileStream &&
|
|
93
|
+
!lastFileStream.readableEnded &&
|
|
94
|
+
!lastFileStream.destroyed
|
|
95
|
+
)
|
|
96
|
+
lastFileStream.destroy(exitError);
|
|
88
97
|
|
|
89
98
|
if (map)
|
|
90
99
|
for (const upload of map.values())
|
|
@@ -101,42 +110,9 @@ module.exports = function processRequest(
|
|
|
101
110
|
});
|
|
102
111
|
};
|
|
103
112
|
|
|
104
|
-
/**
|
|
105
|
-
* Releases resources and cleans up Capacitor temporary files. Successive
|
|
106
|
-
* calls have no effect.
|
|
107
|
-
* @kind function
|
|
108
|
-
* @name processRequest~release
|
|
109
|
-
* @ignore
|
|
110
|
-
*/
|
|
111
|
-
const release = () => {
|
|
112
|
-
if (released) return;
|
|
113
|
-
released = true;
|
|
114
|
-
|
|
115
|
-
if (map)
|
|
116
|
-
for (const upload of map.values())
|
|
117
|
-
if (upload.file) upload.file.capacitor.release();
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Handles when the request is closed before it properly ended.
|
|
122
|
-
* @kind function
|
|
123
|
-
* @name processRequest~abort
|
|
124
|
-
* @ignore
|
|
125
|
-
*/
|
|
126
|
-
const abort = () => {
|
|
127
|
-
exit(
|
|
128
|
-
createError(
|
|
129
|
-
499,
|
|
130
|
-
'Request disconnected during file upload stream parsing.'
|
|
131
|
-
)
|
|
132
|
-
);
|
|
133
|
-
};
|
|
134
|
-
|
|
135
113
|
parser.on(
|
|
136
|
-
|
|
114
|
+
"field",
|
|
137
115
|
(fieldName, value, fieldNameTruncated, valueTruncated) => {
|
|
138
|
-
if (exitError) return;
|
|
139
|
-
|
|
140
116
|
if (valueTruncated)
|
|
141
117
|
return exit(
|
|
142
118
|
createError(
|
|
@@ -146,7 +122,7 @@ module.exports = function processRequest(
|
|
|
146
122
|
);
|
|
147
123
|
|
|
148
124
|
switch (fieldName) {
|
|
149
|
-
case
|
|
125
|
+
case "operations":
|
|
150
126
|
try {
|
|
151
127
|
operations = JSON.parse(value);
|
|
152
128
|
} catch (error) {
|
|
@@ -158,7 +134,9 @@ module.exports = function processRequest(
|
|
|
158
134
|
);
|
|
159
135
|
}
|
|
160
136
|
|
|
161
|
-
|
|
137
|
+
// `operations` should be an object or an array. Note that arrays
|
|
138
|
+
// and `null` have an `object` type.
|
|
139
|
+
if (typeof operations !== "object" || !operations)
|
|
162
140
|
return exit(
|
|
163
141
|
createError(
|
|
164
142
|
400,
|
|
@@ -169,7 +147,7 @@ module.exports = function processRequest(
|
|
|
169
147
|
operationsPath = objectPath(operations);
|
|
170
148
|
|
|
171
149
|
break;
|
|
172
|
-
case
|
|
150
|
+
case "map": {
|
|
173
151
|
if (!operations)
|
|
174
152
|
return exit(
|
|
175
153
|
createError(
|
|
@@ -190,7 +168,12 @@ module.exports = function processRequest(
|
|
|
190
168
|
);
|
|
191
169
|
}
|
|
192
170
|
|
|
193
|
-
|
|
171
|
+
// `map` should be an object.
|
|
172
|
+
if (
|
|
173
|
+
typeof parsedMap !== "object" ||
|
|
174
|
+
!parsedMap ||
|
|
175
|
+
Array.isArray(parsedMap)
|
|
176
|
+
)
|
|
194
177
|
return exit(
|
|
195
178
|
createError(
|
|
196
179
|
400,
|
|
@@ -220,7 +203,7 @@ module.exports = function processRequest(
|
|
|
220
203
|
map.set(fieldName, new Upload());
|
|
221
204
|
|
|
222
205
|
for (const [index, path] of paths.entries()) {
|
|
223
|
-
if (typeof path !==
|
|
206
|
+
if (typeof path !== "string")
|
|
224
207
|
return exit(
|
|
225
208
|
createError(
|
|
226
209
|
400,
|
|
@@ -247,11 +230,8 @@ module.exports = function processRequest(
|
|
|
247
230
|
}
|
|
248
231
|
);
|
|
249
232
|
|
|
250
|
-
parser.on(
|
|
251
|
-
|
|
252
|
-
ignoreStream(stream);
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
233
|
+
parser.on("file", (fieldName, stream, filename, encoding, mimetype) => {
|
|
234
|
+
lastFileStream = stream;
|
|
255
235
|
|
|
256
236
|
if (!map) {
|
|
257
237
|
ignoreStream(stream);
|
|
@@ -263,11 +243,6 @@ module.exports = function processRequest(
|
|
|
263
243
|
);
|
|
264
244
|
}
|
|
265
245
|
|
|
266
|
-
currentStream = stream;
|
|
267
|
-
stream.on('end', () => {
|
|
268
|
-
currentStream = null;
|
|
269
|
-
});
|
|
270
|
-
|
|
271
246
|
const upload = map.get(fieldName);
|
|
272
247
|
|
|
273
248
|
if (!upload) {
|
|
@@ -280,12 +255,12 @@ module.exports = function processRequest(
|
|
|
280
255
|
let fileError;
|
|
281
256
|
const capacitor = new WriteStream();
|
|
282
257
|
|
|
283
|
-
capacitor.on(
|
|
258
|
+
capacitor.on("error", () => {
|
|
284
259
|
stream.unpipe();
|
|
285
260
|
stream.resume();
|
|
286
261
|
});
|
|
287
262
|
|
|
288
|
-
stream.on(
|
|
263
|
+
stream.on("limit", () => {
|
|
289
264
|
fileError = createError(
|
|
290
265
|
413,
|
|
291
266
|
`File truncated as it exceeds the ${maxFileSize} byte size limit.`
|
|
@@ -294,10 +269,10 @@ module.exports = function processRequest(
|
|
|
294
269
|
capacitor.destroy(fileError);
|
|
295
270
|
});
|
|
296
271
|
|
|
297
|
-
stream.on(
|
|
272
|
+
stream.on("error", (error) => {
|
|
298
273
|
fileError = error;
|
|
299
274
|
stream.unpipe();
|
|
300
|
-
capacitor.destroy(
|
|
275
|
+
capacitor.destroy(fileError);
|
|
301
276
|
});
|
|
302
277
|
|
|
303
278
|
const file = {
|
|
@@ -311,17 +286,17 @@ module.exports = function processRequest(
|
|
|
311
286
|
},
|
|
312
287
|
};
|
|
313
288
|
|
|
314
|
-
Object.defineProperty(file,
|
|
289
|
+
Object.defineProperty(file, "capacitor", { value: capacitor });
|
|
315
290
|
|
|
316
291
|
stream.pipe(capacitor);
|
|
317
292
|
upload.resolve(file);
|
|
318
293
|
});
|
|
319
294
|
|
|
320
|
-
parser.once(
|
|
295
|
+
parser.once("filesLimit", () =>
|
|
321
296
|
exit(createError(413, `${maxFiles} max file uploads exceeded.`))
|
|
322
297
|
);
|
|
323
298
|
|
|
324
|
-
parser.once(
|
|
299
|
+
parser.once("finish", () => {
|
|
325
300
|
request.unpipe(parser);
|
|
326
301
|
request.resume();
|
|
327
302
|
|
|
@@ -343,17 +318,29 @@ module.exports = function processRequest(
|
|
|
343
318
|
|
|
344
319
|
for (const upload of map.values())
|
|
345
320
|
if (!upload.file)
|
|
346
|
-
upload.reject(createError(400,
|
|
321
|
+
upload.reject(createError(400, "File missing in the request."));
|
|
347
322
|
});
|
|
348
323
|
|
|
349
|
-
parser.once(
|
|
324
|
+
parser.once("error", exit);
|
|
350
325
|
|
|
351
|
-
response.once(
|
|
352
|
-
|
|
326
|
+
response.once("close", () => {
|
|
327
|
+
released = true;
|
|
328
|
+
|
|
329
|
+
if (map)
|
|
330
|
+
for (const upload of map.values())
|
|
331
|
+
if (upload.file)
|
|
332
|
+
// Release resources and clean up temporary files.
|
|
333
|
+
upload.file.capacitor.release();
|
|
334
|
+
});
|
|
353
335
|
|
|
354
|
-
request.once(
|
|
355
|
-
|
|
356
|
-
|
|
336
|
+
request.once("close", () => {
|
|
337
|
+
if (!request.readableEnded)
|
|
338
|
+
exit(
|
|
339
|
+
createError(
|
|
340
|
+
499,
|
|
341
|
+
"Request disconnected during file upload stream parsing."
|
|
342
|
+
)
|
|
343
|
+
);
|
|
357
344
|
});
|
|
358
345
|
|
|
359
346
|
request.pipe(parser);
|