@based/server 3.3.7 → 3.4.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/.turbo/turbo-build.log +5 -5
- package/dist/BasedServerClient.d.ts +0 -0
- package/dist/BasedServerClient.js +0 -0
- package/dist/BasedServerClient.js.map +0 -0
- package/dist/Client.d.ts +0 -0
- package/dist/Client.js +0 -0
- package/dist/Client.js.map +0 -0
- package/dist/Params.d.ts +0 -0
- package/dist/Params.js +0 -0
- package/dist/Params.js.map +0 -0
- package/dist/auth/authorize.d.ts +2 -0
- package/dist/auth/authorize.js +8 -0
- package/dist/auth/authorize.js.map +1 -0
- package/dist/auth/authorizeAdvanced.d.ts +2 -0
- package/dist/auth/authorizeAdvanced.js +10 -0
- package/dist/auth/authorizeAdvanced.js.map +1 -0
- package/dist/auth/defaults/authorize.d.ts +2 -0
- package/dist/auth/defaults/authorize.js +8 -0
- package/dist/auth/defaults/authorize.js.map +1 -0
- package/dist/auth/defaults/authorizeAdvanced.d.ts +2 -0
- package/dist/auth/defaults/authorizeAdvanced.js +8 -0
- package/dist/auth/defaults/authorizeAdvanced.js.map +1 -0
- package/dist/auth/defaults/index.d.ts +2 -0
- package/dist/auth/defaults/index.js +19 -0
- package/dist/auth/defaults/index.js.map +1 -0
- package/dist/auth/index.d.ts +10 -0
- package/dist/auth/index.js +23 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/closeListener.d.ts +0 -0
- package/dist/closeListener.js +0 -0
- package/dist/closeListener.js.map +0 -0
- package/dist/error.d.ts +34 -0
- package/dist/error.js +107 -0
- package/dist/error.js.map +1 -0
- package/dist/findPrefix.d.ts +0 -0
- package/dist/findPrefix.js +0 -0
- package/dist/findPrefix.js.map +0 -0
- package/dist/functions/index.d.ts +31 -0
- package/dist/functions/index.js +200 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/functions/timeout.d.ts +3 -0
- package/dist/functions/timeout.js +23 -0
- package/dist/functions/timeout.js.map +1 -0
- package/dist/getFromConfig.d.ts +0 -0
- package/dist/getFromConfig.js +0 -0
- package/dist/getFromConfig.js.map +0 -0
- package/dist/handlers/authorize.d.ts +0 -0
- package/dist/handlers/authorize.js +0 -0
- package/dist/handlers/authorize.js.map +0 -0
- package/dist/handlers/bulkUpdate/index.d.ts +0 -0
- package/dist/handlers/bulkUpdate/index.js +0 -0
- package/dist/handlers/bulkUpdate/index.js.map +0 -0
- package/dist/handlers/configuration/index.d.ts +0 -0
- package/dist/handlers/configuration/index.js +0 -0
- package/dist/handlers/configuration/index.js.map +0 -0
- package/dist/handlers/configuration/observable/index.d.ts +0 -0
- package/dist/handlers/configuration/observable/index.js +0 -0
- package/dist/handlers/configuration/observable/index.js.map +0 -0
- package/dist/handlers/configure/index.d.ts +0 -0
- package/dist/handlers/configure/index.js +0 -0
- package/dist/handlers/configure/index.js.map +0 -0
- package/dist/handlers/copy/index.d.ts +0 -0
- package/dist/handlers/copy/index.js +0 -0
- package/dist/handlers/copy/index.js.map +0 -0
- package/dist/handlers/delete/index.d.ts +0 -0
- package/dist/handlers/delete/index.js +0 -0
- package/dist/handlers/delete/index.js.map +0 -0
- package/dist/handlers/digest/index.d.ts +0 -0
- package/dist/handlers/digest/index.js +0 -0
- package/dist/handlers/digest/index.js.map +0 -0
- package/dist/handlers/functions/call.d.ts +0 -0
- package/dist/handlers/functions/call.js +0 -0
- package/dist/handlers/functions/call.js.map +0 -0
- package/dist/handlers/functions/observable/Observable.d.ts +0 -0
- package/dist/handlers/functions/observable/Observable.js +0 -0
- package/dist/handlers/functions/observable/Observable.js.map +0 -0
- package/dist/handlers/functions/observable/SharedObservable.d.ts +0 -0
- package/dist/handlers/functions/observable/SharedObservable.js +0 -0
- package/dist/handlers/functions/observable/SharedObservable.js.map +0 -0
- package/dist/handlers/functions/observable/index.d.ts +0 -0
- package/dist/handlers/functions/observable/index.js +0 -0
- package/dist/handlers/functions/observable/index.js.map +0 -0
- package/dist/handlers/get/index.d.ts +0 -0
- package/dist/handlers/get/index.js +0 -0
- package/dist/handlers/get/index.js.map +0 -0
- package/dist/handlers/getConfig/index.d.ts +0 -0
- package/dist/handlers/getConfig/index.js +0 -0
- package/dist/handlers/getConfig/index.js.map +0 -0
- package/dist/handlers/handleRequests.d.ts +0 -0
- package/dist/handlers/handleRequests.js +0 -0
- package/dist/handlers/handleRequests.js.map +0 -0
- package/dist/handlers/index.d.ts +0 -0
- package/dist/handlers/index.js +0 -0
- package/dist/handlers/index.js.map +0 -0
- package/dist/handlers/messageParser.d.ts +0 -0
- package/dist/handlers/messageParser.js +0 -0
- package/dist/handlers/messageParser.js.map +0 -0
- package/dist/handlers/removeField/index.d.ts +0 -0
- package/dist/handlers/removeField/index.js +0 -0
- package/dist/handlers/removeField/index.js.map +0 -0
- package/dist/handlers/removeType/index.d.ts +0 -0
- package/dist/handlers/removeType/index.js +0 -0
- package/dist/handlers/removeType/index.js.map +0 -0
- package/dist/handlers/rest/file/DataStream.d.ts +0 -0
- package/dist/handlers/rest/file/DataStream.js +0 -0
- package/dist/handlers/rest/file/DataStream.js.map +0 -0
- package/dist/handlers/rest/file/formStream.d.ts +0 -0
- package/dist/handlers/rest/file/formStream.js +0 -0
- package/dist/handlers/rest/file/formStream.js.map +0 -0
- package/dist/handlers/rest/file/getExtenstion.d.ts +0 -0
- package/dist/handlers/rest/file/getExtenstion.js +0 -0
- package/dist/handlers/rest/file/getExtenstion.js.map +0 -0
- package/dist/handlers/rest/file/index.d.ts +0 -0
- package/dist/handlers/rest/file/index.js +0 -0
- package/dist/handlers/rest/file/index.js.map +0 -0
- package/dist/handlers/rest/file/storeFile.d.ts +0 -0
- package/dist/handlers/rest/file/storeFile.js +0 -0
- package/dist/handlers/rest/file/storeFile.js.map +0 -0
- package/dist/handlers/rest/file/stream.d.ts +0 -0
- package/dist/handlers/rest/file/stream.js +0 -0
- package/dist/handlers/rest/file/stream.js.map +0 -0
- package/dist/handlers/rest/file/types.d.ts +0 -0
- package/dist/handlers/rest/file/types.js +0 -0
- package/dist/handlers/rest/file/types.js.map +0 -0
- package/dist/handlers/rest/getReqMessage.d.ts +0 -0
- package/dist/handlers/rest/getReqMessage.js +0 -0
- package/dist/handlers/rest/getReqMessage.js.map +0 -0
- package/dist/handlers/rest/index.d.ts +0 -0
- package/dist/handlers/rest/index.js +0 -0
- package/dist/handlers/rest/index.js.map +0 -0
- package/dist/handlers/rest/invalidReq.d.ts +0 -0
- package/dist/handlers/rest/invalidReq.js +0 -0
- package/dist/handlers/rest/invalidReq.js.map +0 -0
- package/dist/handlers/rest/parseResponse.d.ts +0 -0
- package/dist/handlers/rest/parseResponse.js +0 -0
- package/dist/handlers/rest/parseResponse.js.map +0 -0
- package/dist/handlers/rest/playground/index.d.ts +0 -0
- package/dist/handlers/rest/playground/index.js +0 -0
- package/dist/handlers/rest/playground/index.js.map +0 -0
- package/dist/handlers/rest/readBody.d.ts +0 -0
- package/dist/handlers/rest/readBody.js +0 -0
- package/dist/handlers/rest/readBody.js.map +0 -0
- package/dist/handlers/set/index.d.ts +0 -0
- package/dist/handlers/set/index.js +0 -0
- package/dist/handlers/set/index.js.map +0 -0
- package/dist/handlers/subscription/index.d.ts +0 -0
- package/dist/handlers/subscription/index.js +0 -0
- package/dist/handlers/subscription/index.js.map +0 -0
- package/dist/handlers/token.d.ts +0 -0
- package/dist/handlers/token.js +0 -0
- package/dist/handlers/token.js.map +0 -0
- package/dist/handlers/track/index.d.ts +0 -0
- package/dist/handlers/track/index.js +0 -0
- package/dist/handlers/track/index.js.map +0 -0
- package/dist/handlers/userAuth/index.d.ts +0 -0
- package/dist/handlers/userAuth/index.js +0 -0
- package/dist/handlers/userAuth/index.js.map +0 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/index.js.map +0 -0
- package/dist/network/http/authorize.d.ts +3 -0
- package/dist/network/http/authorize.js +30 -0
- package/dist/network/http/authorize.js.map +1 -0
- package/dist/network/http/compress.d.ts +6 -0
- package/dist/network/http/compress.js +47 -0
- package/dist/network/http/compress.js.map +1 -0
- package/dist/network/http/end.d.ts +4 -0
- package/dist/network/http/end.js +19 -0
- package/dist/network/http/end.js.map +1 -0
- package/dist/network/http/function/index.d.ts +3 -0
- package/dist/network/http/function/index.js +82 -0
- package/dist/network/http/function/index.js.map +1 -0
- package/dist/network/http/function/stream/DataStream.d.ts +7 -0
- package/dist/network/http/function/stream/DataStream.js +17 -0
- package/dist/network/http/function/stream/DataStream.js.map +1 -0
- package/dist/network/http/function/stream/index.d.ts +8 -0
- package/dist/network/http/function/stream/index.js +93 -0
- package/dist/network/http/function/stream/index.js.map +1 -0
- package/dist/network/http/function/stream/multipartFormStream.d.ts +0 -0
- package/dist/network/http/function/stream/multipartFormStream.js +194 -0
- package/dist/network/http/function/stream/multipartFormStream.js.map +1 -0
- package/dist/network/http/function/stream/stream.d.ts +4 -0
- package/dist/network/http/function/stream/stream.js +49 -0
- package/dist/network/http/function/stream/stream.js.map +1 -0
- package/dist/network/http/function.d.ts +3 -0
- package/dist/network/http/function.js +46 -0
- package/dist/network/http/function.js.map +1 -0
- package/dist/network/http/get.d.ts +3 -0
- package/dist/network/http/get.js +143 -0
- package/dist/network/http/get.js.map +1 -0
- package/dist/network/http/index.d.ts +3 -0
- package/dist/network/http/index.js +125 -0
- package/dist/network/http/index.js.map +1 -0
- package/dist/network/http/readBody.d.ts +2 -0
- package/dist/network/http/readBody.js +134 -0
- package/dist/network/http/readBody.js.map +1 -0
- package/dist/network/http/readPostData.d.ts +3 -0
- package/dist/network/http/readPostData.js +50 -0
- package/dist/network/http/readPostData.js.map +1 -0
- package/dist/network/http/send.d.ts +6 -0
- package/dist/network/http/send.js +65 -0
- package/dist/network/http/send.js.map +1 -0
- package/dist/network/http/sendError.d.ts +4 -0
- package/dist/network/http/sendError.js +27 -0
- package/dist/network/http/sendError.js.map +1 -0
- package/dist/network/http/stream/DataStream.d.ts +7 -0
- package/dist/network/http/stream/DataStream.js +17 -0
- package/dist/network/http/stream/DataStream.js.map +1 -0
- package/dist/network/http/stream/formStream.d.ts +4 -0
- package/dist/network/http/stream/formStream.js +184 -0
- package/dist/network/http/stream/formStream.js.map +1 -0
- package/dist/network/http/stream/getExtenstion.d.ts +2 -0
- package/dist/network/http/stream/getExtenstion.js +22 -0
- package/dist/network/http/stream/getExtenstion.js.map +1 -0
- package/dist/network/http/stream/index.d.ts +9 -0
- package/dist/network/http/stream/index.js +42 -0
- package/dist/network/http/stream/index.js.map +1 -0
- package/dist/network/http/stream/multipartFormStream.d.ts +0 -0
- package/dist/network/http/stream/multipartFormStream.js +194 -0
- package/dist/network/http/stream/multipartFormStream.js.map +1 -0
- package/dist/network/http/stream/storeFile.d.ts +5 -0
- package/dist/network/http/stream/storeFile.js +30 -0
- package/dist/network/http/stream/storeFile.js.map +1 -0
- package/dist/network/http/stream/stream.d.ts +4 -0
- package/dist/network/http/stream/stream.js +49 -0
- package/dist/network/http/stream/stream.js.map +1 -0
- package/dist/network/http/stream/types.d.ts +9 -0
- package/dist/network/http/stream/types.js +3 -0
- package/dist/network/http/stream/types.js.map +1 -0
- package/dist/network/http/streamFunction/DataStream.d.ts +7 -0
- package/dist/network/http/streamFunction/DataStream.js +17 -0
- package/dist/network/http/streamFunction/DataStream.js.map +1 -0
- package/dist/network/http/streamFunction/endStreamRequest.d.ts +3 -0
- package/dist/network/http/streamFunction/endStreamRequest.js +20 -0
- package/dist/network/http/streamFunction/endStreamRequest.js.map +1 -0
- package/dist/network/http/streamFunction/getExtension.d.ts +2 -0
- package/dist/network/http/streamFunction/getExtension.js +22 -0
- package/dist/network/http/streamFunction/getExtension.js.map +1 -0
- package/dist/network/http/streamFunction/index.d.ts +3 -0
- package/dist/network/http/streamFunction/index.js +71 -0
- package/dist/network/http/streamFunction/index.js.map +1 -0
- package/dist/network/http/streamFunction/multipartFormStream.d.ts +5 -0
- package/dist/network/http/streamFunction/multipartFormStream.js +189 -0
- package/dist/network/http/streamFunction/multipartFormStream.js.map +1 -0
- package/dist/network/http/streamFunction/multipartStream.d.ts +13 -0
- package/dist/network/http/streamFunction/multipartStream.js +166 -0
- package/dist/network/http/streamFunction/multipartStream.js.map +1 -0
- package/dist/network/http/streamFunction/stream.d.ts +4 -0
- package/dist/network/http/streamFunction/stream.js +106 -0
- package/dist/network/http/streamFunction/stream.js.map +1 -0
- package/dist/network/index.d.ts +4 -0
- package/dist/network/index.js +84 -0
- package/dist/network/index.js.map +1 -0
- package/dist/network/message/auth.d.ts +4 -0
- package/dist/network/message/auth.js +35 -0
- package/dist/network/message/auth.js.map +1 -0
- package/dist/network/message/function.d.ts +3 -0
- package/dist/network/message/function.js +70 -0
- package/dist/network/message/function.js.map +1 -0
- package/dist/network/message/get.d.ts +3 -0
- package/dist/network/message/get.js +111 -0
- package/dist/network/message/get.js.map +1 -0
- package/dist/network/message/index.d.ts +3 -0
- package/dist/network/message/index.js +61 -0
- package/dist/network/message/index.js.map +1 -0
- package/dist/network/message/observable.d.ts +5 -0
- package/dist/network/message/observable.js +105 -0
- package/dist/network/message/observable.js.map +1 -0
- package/dist/network/message/send.d.ts +3 -0
- package/dist/network/message/send.js +11 -0
- package/dist/network/message/send.js.map +1 -0
- package/dist/network/rest/function.d.ts +3 -0
- package/dist/network/rest/function.js +85 -0
- package/dist/network/rest/function.js.map +1 -0
- package/dist/network/rest/index.d.ts +3 -0
- package/dist/network/rest/index.js +65 -0
- package/dist/network/rest/index.js.map +1 -0
- package/dist/network/upgrade.d.ts +4 -0
- package/dist/network/upgrade.js +48 -0
- package/dist/network/upgrade.js.map +1 -0
- package/dist/observable/index.d.ts +8 -0
- package/dist/observable/index.js +224 -0
- package/dist/observable/index.js.map +1 -0
- package/dist/openListener.d.ts +0 -0
- package/dist/openListener.js +0 -0
- package/dist/openListener.js.map +0 -0
- package/dist/protocol.d.ts +18 -0
- package/dist/protocol.js +206 -0
- package/dist/protocol.js.map +1 -0
- package/dist/secrets.d.ts +0 -0
- package/dist/secrets.js +0 -0
- package/dist/secrets.js.map +0 -0
- package/dist/server.d.ts +28 -0
- package/dist/server.js +96 -0
- package/dist/server.js.map +1 -0
- package/dist/types.d.ts +0 -0
- package/dist/types.js +0 -0
- package/dist/types.js.map +0 -0
- package/dist/upgradeListener.d.ts +0 -0
- package/dist/upgradeListener.js +0 -0
- package/dist/upgradeListener.js.map +0 -0
- package/dist/workers/index.d.ts +0 -0
- package/dist/workers/index.js +0 -0
- package/dist/workers/index.js.map +0 -0
- package/dist/workers/workerCode.d.ts +0 -0
- package/dist/workers/workerCode.js +0 -0
- package/dist/workers/workerCode.js.map +0 -0
- package/package.json +2 -2
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const end_1 = __importDefault(require("../end"));
|
|
7
|
+
exports.default = (client) => {
|
|
8
|
+
// size?
|
|
9
|
+
// request id
|
|
10
|
+
if (client.res) {
|
|
11
|
+
client.res.cork(() => {
|
|
12
|
+
client.res.writeStatus('200 OK');
|
|
13
|
+
client.res.writeHeader('Access-Control-Allow-Origin', '*');
|
|
14
|
+
client.res.writeHeader('Access-Control-Allow-Headers', 'content-type');
|
|
15
|
+
client.res.writeHeader('Content-Type', 'application/json');
|
|
16
|
+
(0, end_1.default)(client, '{}');
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=endStreamRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endStreamRequest.js","sourceRoot":"","sources":["../../../../src/network/http/streamFunction/endStreamRequest.ts"],"names":[],"mappings":";;;;;AACA,iDAAwB;AAExB,kBAAe,CAAC,MAAkB,EAAE,EAAE;IACpC,QAAQ;IACR,aAAa;IACb,IAAI,MAAM,CAAC,GAAG,EAAE;QACd,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE;YACnB,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;YAChC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;YAC1D,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,8BAA8B,EAAE,cAAc,CAAC,CAAA;YACtE,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAA;YAC1D,IAAA,aAAG,EAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACnB,CAAC,CAAC,CAAA;KACH;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const mime_types_1 = __importDefault(require("mime-types"));
|
|
7
|
+
exports.default = (mimeType) => {
|
|
8
|
+
const [mime, type] = mimeType.split('/');
|
|
9
|
+
if (mime === 'font') {
|
|
10
|
+
return 'woff';
|
|
11
|
+
}
|
|
12
|
+
else if (type === 'mp3') {
|
|
13
|
+
return 'mp3';
|
|
14
|
+
}
|
|
15
|
+
else if (type === 'woff2') {
|
|
16
|
+
return 'woff2';
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return mime_types_1.default.extension(mimeType);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=getExtension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getExtension.js","sourceRoot":"","sources":["../../../../src/network/http/streamFunction/getExtension.ts"],"names":[],"mappings":";;;;;AAAA,4DAAkC;AAElC,kBAAe,CAAC,QAAgB,EAAE,EAAE;IAClC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACxC,IAAI,IAAI,KAAK,MAAM,EAAE;QACnB,OAAO,MAAM,CAAA;KACd;SAAM,IAAI,IAAI,KAAK,KAAK,EAAE;QACzB,OAAO,KAAK,CAAA;KACb;SAAM,IAAI,IAAI,KAAK,OAAO,EAAE;QAC3B,OAAO,OAAO,CAAA;KACf;SAAM;QACL,OAAO,oBAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;KACrC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.httpStreamFunction = void 0;
|
|
7
|
+
const stream_1 = __importDefault(require("./stream"));
|
|
8
|
+
const send_1 = require("../send");
|
|
9
|
+
const types_1 = require("../../../types");
|
|
10
|
+
const authorize_1 = require("../authorize");
|
|
11
|
+
const error_1 = require("../../../error");
|
|
12
|
+
const multipartStream_1 = __importDefault(require("./multipartStream"));
|
|
13
|
+
const httpStreamFunction = (server, client, payload, route) => {
|
|
14
|
+
if (!client.res) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const size = client.context.headers['content-length'];
|
|
18
|
+
if (route.maxPayloadSize > -1 && route.maxPayloadSize < size) {
|
|
19
|
+
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.PayloadTooLarge);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const type = client.context.headers['content-type'];
|
|
23
|
+
if (type === 'multipart/form-data') {
|
|
24
|
+
(0, authorize_1.authorizeRequest)(server, client, payload, route, (payload) => {
|
|
25
|
+
server.functions
|
|
26
|
+
.install(route.name)
|
|
27
|
+
.then((spec) => {
|
|
28
|
+
if (spec && !(0, types_1.isObservableFunctionSpec)(spec) && spec.stream) {
|
|
29
|
+
(0, multipartStream_1.default)(server, client, payload, spec);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.FunctionNotFound, route.name);
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
.catch(() => {
|
|
36
|
+
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.FunctionNotFound, route.name);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
// destroy stream from context
|
|
42
|
+
(0, authorize_1.authorizeRequest)(server, client, payload, route, (payload) => {
|
|
43
|
+
server.functions
|
|
44
|
+
.install(route.name)
|
|
45
|
+
.then((spec) => {
|
|
46
|
+
if (spec && !(0, types_1.isObservableFunctionSpec)(spec) && spec.stream) {
|
|
47
|
+
const stream = (0, stream_1.default)(client, size);
|
|
48
|
+
const streamPayload = { payload, stream };
|
|
49
|
+
spec
|
|
50
|
+
.function(streamPayload, client)
|
|
51
|
+
.catch((err) => {
|
|
52
|
+
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.FunctionError, {
|
|
53
|
+
err,
|
|
54
|
+
name: route.name,
|
|
55
|
+
});
|
|
56
|
+
})
|
|
57
|
+
.then(() => {
|
|
58
|
+
// function finished - dont really know what to do here :D
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.FunctionNotFound, route.name);
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
.catch(() => {
|
|
66
|
+
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.FunctionNotFound, route.name);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
exports.httpStreamFunction = httpStreamFunction;
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/network/http/stream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BAkE9B"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const DataStream_1 = require("./DataStream");
|
|
4
|
+
// import getExtenstion from './getExtenstion'
|
|
5
|
+
// import fs from 'fs'
|
|
6
|
+
// type FileDescriptor = {
|
|
7
|
+
// opts: Partial<FileOptions>
|
|
8
|
+
// stream: DataStream
|
|
9
|
+
// headersSet: number
|
|
10
|
+
// }
|
|
11
|
+
// const isCompleteOpts = (
|
|
12
|
+
// options: Partial<FileOptions>
|
|
13
|
+
// ): options is FileOptions => {
|
|
14
|
+
// return !!(options.id && options.size && options.type && options.extension)
|
|
15
|
+
// }
|
|
16
|
+
// handler for updates
|
|
17
|
+
const setHeader = (server, file, res) => {
|
|
18
|
+
file.headersSet++;
|
|
19
|
+
if (file.headersSet === 2) {
|
|
20
|
+
const opts = file.opts;
|
|
21
|
+
if (isCompleteOpts(opts)) {
|
|
22
|
+
if (opts.size < 200000) {
|
|
23
|
+
file.stream.on('end', () => {
|
|
24
|
+
const payload = {
|
|
25
|
+
$id: opts.id,
|
|
26
|
+
progress: 1,
|
|
27
|
+
size: opts.size,
|
|
28
|
+
};
|
|
29
|
+
if (opts.name) {
|
|
30
|
+
payload.name = opts.name;
|
|
31
|
+
}
|
|
32
|
+
server.based.set(payload);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
let progress = 0;
|
|
37
|
+
let total = 0;
|
|
38
|
+
let setInProgress = false;
|
|
39
|
+
const payload = {
|
|
40
|
+
$id: opts.id,
|
|
41
|
+
progress: 0,
|
|
42
|
+
size: opts.size,
|
|
43
|
+
};
|
|
44
|
+
if (opts.name) {
|
|
45
|
+
payload.name = opts.name;
|
|
46
|
+
}
|
|
47
|
+
server.based.set(payload);
|
|
48
|
+
const updateProgress = () => {
|
|
49
|
+
if (!setInProgress) {
|
|
50
|
+
setInProgress = true;
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
const payload = {
|
|
53
|
+
$id: opts.id,
|
|
54
|
+
progress,
|
|
55
|
+
};
|
|
56
|
+
server.based.set(payload);
|
|
57
|
+
setInProgress = false;
|
|
58
|
+
}, 250);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
file.stream.on('end', () => {
|
|
62
|
+
progress = 1;
|
|
63
|
+
updateProgress();
|
|
64
|
+
});
|
|
65
|
+
file.stream.on('data', (chunk) => {
|
|
66
|
+
total += chunk.byteLength;
|
|
67
|
+
progress = total / opts.size;
|
|
68
|
+
updateProgress();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
storeFile(server, file.stream, opts);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
invalidFile(res);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
};
|
|
81
|
+
const invalidFile = (res) => {
|
|
82
|
+
console.info('Invalid file');
|
|
83
|
+
res.aborted = true;
|
|
84
|
+
res.writeStatus('400 Invalid Request').end('{"error":"invalid file}');
|
|
85
|
+
};
|
|
86
|
+
const toBuffer = (str, firstWritten) => {
|
|
87
|
+
return Buffer.from(firstWritten ? str + '\r\n' : str, 'binary');
|
|
88
|
+
};
|
|
89
|
+
exports.default = async (server, client, res) => {
|
|
90
|
+
const files = [];
|
|
91
|
+
let boundary = null;
|
|
92
|
+
let prevLine;
|
|
93
|
+
let isWriting = false;
|
|
94
|
+
res.onData((chunk, isLast) => {
|
|
95
|
+
let firstWritten = false;
|
|
96
|
+
const blocks = Buffer.from(chunk).toString('binary').split('\r\n');
|
|
97
|
+
if (!boundary) {
|
|
98
|
+
boundary = blocks[0];
|
|
99
|
+
}
|
|
100
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
101
|
+
const line = blocks[i];
|
|
102
|
+
if (!boundary) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (isWriting && (line === boundary || line === boundary + '--')) {
|
|
106
|
+
isWriting = false;
|
|
107
|
+
const file = files[files.length - 1];
|
|
108
|
+
if (prevLine) {
|
|
109
|
+
file.stream.end(toBuffer(prevLine, firstWritten));
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
file.stream.end();
|
|
113
|
+
}
|
|
114
|
+
prevLine = null;
|
|
115
|
+
if (line === boundary + '--') {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (line === boundary && !isWriting) {
|
|
120
|
+
const file = {
|
|
121
|
+
stream: new DataStream_1.DataStream(),
|
|
122
|
+
headersSet: 0,
|
|
123
|
+
opts: {},
|
|
124
|
+
};
|
|
125
|
+
files.push(file);
|
|
126
|
+
// try {
|
|
127
|
+
// fs.unlinkSync('/Users/jim/Desktop/yes.png')
|
|
128
|
+
// } catch (err) {}
|
|
129
|
+
// file.stream.pipe(fs.createWriteStream('/Users/jim/Desktop/yes.png'))
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const file = files[files.length - 1];
|
|
133
|
+
if (!file) {
|
|
134
|
+
return invalidFile(res);
|
|
135
|
+
}
|
|
136
|
+
if (!isWriting && line.includes('Content-Disposition')) {
|
|
137
|
+
const meta = line.match(/name="(.*?)"/)?.[1];
|
|
138
|
+
if (!meta) {
|
|
139
|
+
return invalidFile(res);
|
|
140
|
+
}
|
|
141
|
+
const [functionName, raw, id, size, ...name] = meta.split('|');
|
|
142
|
+
const opts = file.opts;
|
|
143
|
+
opts.id = id;
|
|
144
|
+
if (raw) {
|
|
145
|
+
opts.raw = true;
|
|
146
|
+
}
|
|
147
|
+
if (name && name.length) {
|
|
148
|
+
opts.name = name.join('|');
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
opts.name = line.match(/filename="(.*?)"/)?.[1] || 'untitled';
|
|
152
|
+
}
|
|
153
|
+
if (functionName) {
|
|
154
|
+
opts.functionName = functionName;
|
|
155
|
+
}
|
|
156
|
+
opts.size = Number(size);
|
|
157
|
+
isWriting = setHeader(server, file, res);
|
|
158
|
+
if (isWriting === null) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (!isWriting && line.includes('Content-Type')) {
|
|
164
|
+
const mimeType = line.match(/Content-Type: ([a-zA-Z0-9].+\/[a-zA-Z0-9].+)/)?.[1];
|
|
165
|
+
if (!mimeType) {
|
|
166
|
+
return invalidFile(res);
|
|
167
|
+
}
|
|
168
|
+
file.opts.type = mimeType;
|
|
169
|
+
file.opts.extension = getExtenstion(mimeType);
|
|
170
|
+
isWriting = setHeader(server, file, res);
|
|
171
|
+
if (isWriting === null) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (isWriting) {
|
|
177
|
+
if (prevLine) {
|
|
178
|
+
file.stream.write(toBuffer(prevLine, firstWritten));
|
|
179
|
+
}
|
|
180
|
+
prevLine = line;
|
|
181
|
+
firstWritten = true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (isLast) {
|
|
185
|
+
res.end('{}');
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=multipartFormStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipartFormStream.js","sourceRoot":"","sources":["../../../../src/network/http/streamFunction/multipartFormStream.ts"],"names":[],"mappings":";;AAAA,6CAAyC;AAIzC,8CAA8C;AAC9C,sBAAsB;AAEtB,0BAA0B;AAC1B,+BAA+B;AAC/B,uBAAuB;AACvB,uBAAuB;AACvB,IAAI;AAEJ,2BAA2B;AAC3B,kCAAkC;AAClC,iCAAiC;AACjC,+EAA+E;AAC/E,IAAI;AAEJ,sBAAsB;AAEtB,MAAM,SAAS,GAAG,CAChB,MAAmB,EACnB,IAAoB,EACpB,GAAqB,EACZ,EAAE;IACX,IAAI,CAAC,UAAU,EA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FunctionSpec } from '../../../types';
|
|
3
|
+
export declare type FileOptions = {
|
|
4
|
+
name?: string;
|
|
5
|
+
raw?: boolean;
|
|
6
|
+
size: number;
|
|
7
|
+
type: string;
|
|
8
|
+
id: string;
|
|
9
|
+
extension: string;
|
|
10
|
+
functionName?: string;
|
|
11
|
+
};
|
|
12
|
+
declare const _default: (server: BasedServer, client: HttpClient, payload: any, fn: BasedFunctionSpec) => Promise<void>;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const DataStream_1 = require("./DataStream");
|
|
7
|
+
const error_1 = require("../../../error");
|
|
8
|
+
const send_1 = require("../send");
|
|
9
|
+
const getExtension_1 = __importDefault(require("./getExtension"));
|
|
10
|
+
const endStreamRequest_1 = __importDefault(require("./endStreamRequest"));
|
|
11
|
+
const setHeader = (file) => {
|
|
12
|
+
file.headersSet++;
|
|
13
|
+
if (file.headersSet === 2) {
|
|
14
|
+
const opts = file.opts;
|
|
15
|
+
if (opts.size < 200000) {
|
|
16
|
+
file.stream.on('end', () => {
|
|
17
|
+
console.info({ progress: 1 }, opts);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
let progress = 0;
|
|
22
|
+
let total = 0;
|
|
23
|
+
let setInProgress = false;
|
|
24
|
+
const payload = {
|
|
25
|
+
$id: opts.id,
|
|
26
|
+
progress: 0,
|
|
27
|
+
size: opts.size,
|
|
28
|
+
};
|
|
29
|
+
if (opts.name) {
|
|
30
|
+
payload.name = opts.name;
|
|
31
|
+
}
|
|
32
|
+
const updateProgress = () => {
|
|
33
|
+
if (!setInProgress) {
|
|
34
|
+
setInProgress = true;
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
console.info(progress);
|
|
37
|
+
setInProgress = false;
|
|
38
|
+
}, 250);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
file.stream.on('end', () => {
|
|
42
|
+
progress = 1;
|
|
43
|
+
updateProgress();
|
|
44
|
+
});
|
|
45
|
+
file.stream.on('data', (chunk) => {
|
|
46
|
+
total += chunk.byteLength;
|
|
47
|
+
progress = total / opts.size;
|
|
48
|
+
updateProgress();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
55
|
+
const toBuffer = (str, firstWritten) => {
|
|
56
|
+
return Buffer.from(firstWritten ? str + '\r\n' : str, 'binary');
|
|
57
|
+
};
|
|
58
|
+
exports.default = async (server, client, payload, fn) => {
|
|
59
|
+
// multi file...
|
|
60
|
+
if (!payload || (!payload && typeof payload !== 'object')) {
|
|
61
|
+
payload = {};
|
|
62
|
+
}
|
|
63
|
+
const files = [];
|
|
64
|
+
let boundary = null;
|
|
65
|
+
let prevLine;
|
|
66
|
+
let isWriting = false;
|
|
67
|
+
client.res.onData((chunk, isLast) => {
|
|
68
|
+
let firstWritten = false;
|
|
69
|
+
const blocks = Buffer.from(chunk).toString('binary').split('\r\n');
|
|
70
|
+
if (!boundary) {
|
|
71
|
+
boundary = blocks[0];
|
|
72
|
+
}
|
|
73
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
74
|
+
const line = blocks[i];
|
|
75
|
+
if (!boundary) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (isWriting && (line === boundary || line === boundary + '--')) {
|
|
79
|
+
isWriting = false;
|
|
80
|
+
const file = files[files.length - 1];
|
|
81
|
+
if (prevLine) {
|
|
82
|
+
file.stream.end(toBuffer(prevLine, firstWritten));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
file.stream.end();
|
|
86
|
+
}
|
|
87
|
+
prevLine = null;
|
|
88
|
+
if (line === boundary + '--') {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (line === boundary && !isWriting) {
|
|
93
|
+
const file = {
|
|
94
|
+
stream: new DataStream_1.DataStream(),
|
|
95
|
+
headersSet: 0,
|
|
96
|
+
opts: {},
|
|
97
|
+
};
|
|
98
|
+
// bit more
|
|
99
|
+
files.push(file);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const file = files[files.length - 1];
|
|
103
|
+
if (!file) {
|
|
104
|
+
// TODO: invalid file
|
|
105
|
+
return (0, send_1.sendHttpError)(client, error_1.BasedErrorCode.InvalidPayload);
|
|
106
|
+
}
|
|
107
|
+
if (!isWriting && line.includes('Content-Disposition')) {
|
|
108
|
+
const meta = line.match(/name="(.*?)"/)?.[1];
|
|
109
|
+
if (!meta) {
|
|
110
|
+
// TODO: invalid file
|
|
111
|
+
return (0, send_1.sendHttpError)(client, error_1.BasedErrorCode.InvalidPayload);
|
|
112
|
+
}
|
|
113
|
+
const [raw, id, size, ...name] = meta.split('|');
|
|
114
|
+
const opts = file.opts;
|
|
115
|
+
opts.id = id;
|
|
116
|
+
if (raw) {
|
|
117
|
+
opts.raw = true;
|
|
118
|
+
}
|
|
119
|
+
if (name && name.length) {
|
|
120
|
+
opts.name = name.join('|');
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
opts.name = line.match(/filename="(.*?)"/)?.[1] || 'untitled';
|
|
124
|
+
}
|
|
125
|
+
opts.size = Number(size);
|
|
126
|
+
isWriting = setHeader(file);
|
|
127
|
+
if (isWriting === null) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
fn.function({ payload: { ...payload, ...opts }, stream: file.stream }, client).catch(() => { });
|
|
132
|
+
}
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (!isWriting && line.includes('Content-Type')) {
|
|
136
|
+
const mimeType = line.match(/Content-Type: ([a-zA-Z0-9].+\/[a-zA-Z0-9].+)/)?.[1];
|
|
137
|
+
if (!mimeType) {
|
|
138
|
+
// TODO: invalid file
|
|
139
|
+
return (0, send_1.sendHttpError)(client, error_1.BasedErrorCode.InvalidPayload);
|
|
140
|
+
}
|
|
141
|
+
file.opts.type = mimeType;
|
|
142
|
+
file.opts.extension = (0, getExtension_1.default)(mimeType);
|
|
143
|
+
isWriting = setHeader(file);
|
|
144
|
+
if (isWriting === null) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
fn.function({ payload: { ...payload, ...file.opts }, stream: file.stream }, client).catch(() => { });
|
|
149
|
+
}
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (isWriting) {
|
|
153
|
+
if (prevLine) {
|
|
154
|
+
file.stream.write(toBuffer(prevLine, firstWritten));
|
|
155
|
+
}
|
|
156
|
+
prevLine = line;
|
|
157
|
+
firstWritten = true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (isLast) {
|
|
161
|
+
console.info('stream end');
|
|
162
|
+
(0, endStreamRequest_1.default)(client);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
//# sourceMappingURL=multipartStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipartStream.js","sourceRoot":"","sources":["../../../../src/network/http/streamFunction/multipartStream.ts"],"names":[],"mappings":";;;;;AAAA,6CAAyC;AAGzC,0CAA+C;AAC/C,kCAAuC;AACvC,kEAAyC;AACzC,0EAAiD;AAkBjD,MAAM,SAAS,GAAG,CAAC,IAAoB,EAAW,EAAE;IAClD,IAAI,CAAC,UAAU,EAAE,CAAA;IACjB,IAAI,IAAI,CAAC,UAAU,KAAK,CAAC,EAAE;QACzB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACtB,IAAI,IAAI,CAAC,IAAI,GAAG,MAAM,EAAE;YACtB,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAA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AAA;gBAC5C,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;gBAC3B,IAAI,SAAS,KAAK,IAAI,EAAE;oBACtB,OAAM;iBACP;qBAAM;oBACL,EAAE,CAAC,QAAQ,CACT,EAAE,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EAC9D,MAAM,CACP,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;iBAClB;gBACD,SAAQ;aACT;YAED,IAAI,SAAS,EAAE;gBACb,IAAI,QAAQ,EAAE;oBACZ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAA;iBACpD;gBACD,QAAQ,GAAG,IAAI,CAAA;gBACf,YAAY,GAAG,IAAI,CAAA;aACpB;SACF;QAED,IAAI,MAAM,EAAE;YACV,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YAC1B,IAAA,0BAAgB,EAAC,MAAM,CAAC,CAAA;SACzB;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const DataStream_1 = require("./DataStream");
|
|
7
|
+
const send_1 = require("../send");
|
|
8
|
+
const node_zlib_1 = __importDefault(require("node:zlib"));
|
|
9
|
+
const error_1 = require("../../../error");
|
|
10
|
+
const endStreamRequest_1 = __importDefault(require("./endStreamRequest"));
|
|
11
|
+
const MAX_CHUNK_SIZE = 1024 * 1024 * 5;
|
|
12
|
+
const UNCOMPRESS_OPTS = {
|
|
13
|
+
// can be endless scince we limit by incoming
|
|
14
|
+
chunkSize: 1024 * 1024 * 100,
|
|
15
|
+
};
|
|
16
|
+
exports.default = (client, size) => {
|
|
17
|
+
const stream = new DataStream_1.DataStream();
|
|
18
|
+
let total = 0;
|
|
19
|
+
let progress = 0;
|
|
20
|
+
let setInProgress = false;
|
|
21
|
+
stream.emit('progress', progress);
|
|
22
|
+
const emitProgress = size > 200000;
|
|
23
|
+
const contentEncoding = client.context.headers['content-encoding'];
|
|
24
|
+
if (contentEncoding) {
|
|
25
|
+
let uncompressStream;
|
|
26
|
+
if (contentEncoding === 'deflate') {
|
|
27
|
+
uncompressStream = node_zlib_1.default.createInflate(UNCOMPRESS_OPTS);
|
|
28
|
+
}
|
|
29
|
+
else if (contentEncoding === 'gzip') {
|
|
30
|
+
uncompressStream = node_zlib_1.default.createGunzip(UNCOMPRESS_OPTS);
|
|
31
|
+
}
|
|
32
|
+
else if (contentEncoding === 'br') {
|
|
33
|
+
uncompressStream = node_zlib_1.default.createBrotliDecompress(UNCOMPRESS_OPTS);
|
|
34
|
+
}
|
|
35
|
+
if (uncompressStream) {
|
|
36
|
+
client.res.onData((c, isLast) => {
|
|
37
|
+
total += c.byteLength;
|
|
38
|
+
if (c.byteLength > MAX_CHUNK_SIZE) {
|
|
39
|
+
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.ChunkTooLarge);
|
|
40
|
+
uncompressStream.destroy();
|
|
41
|
+
stream.destroy();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const buf = Buffer.alloc(c.byteLength, Buffer.from(c));
|
|
45
|
+
if (emitProgress) {
|
|
46
|
+
progress = total / size;
|
|
47
|
+
if (!setInProgress) {
|
|
48
|
+
setInProgress = true;
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
stream.emit('progress', progress);
|
|
51
|
+
setInProgress = false;
|
|
52
|
+
}, 250);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (isLast) {
|
|
56
|
+
if (!emitProgress) {
|
|
57
|
+
stream.emit('progress', 1);
|
|
58
|
+
}
|
|
59
|
+
uncompressStream.end(buf);
|
|
60
|
+
(0, endStreamRequest_1.default)(client);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
if (!uncompressStream.write(buf)) {
|
|
64
|
+
// handle backpressure
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
uncompressStream.pipe(stream);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.InvalidPayload, 'Unsupported Content-Encoding');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
client.res.onData((c, isLast) => {
|
|
76
|
+
total += c.byteLength;
|
|
77
|
+
if (c.byteLength > MAX_CHUNK_SIZE) {
|
|
78
|
+
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.ChunkTooLarge);
|
|
79
|
+
stream.destroy();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (emitProgress) {
|
|
83
|
+
progress = total / size;
|
|
84
|
+
if (!setInProgress) {
|
|
85
|
+
setInProgress = true;
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
stream.emit('progress', progress);
|
|
88
|
+
setInProgress = false;
|
|
89
|
+
}, 250);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (isLast) {
|
|
93
|
+
if (!emitProgress) {
|
|
94
|
+
stream.emit('progress', 1);
|
|
95
|
+
}
|
|
96
|
+
stream.end(Buffer.from(c));
|
|
97
|
+
(0, endStreamRequest_1.default)(client);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
stream.write(Buffer.from(c));
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return stream;
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../../src/network/http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