@based/server 3.4.0 → 3.4.2
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 +2 -2
- package/dist/handlers/removeField/index.js +1 -0
- package/dist/handlers/removeField/index.js.map +1 -1
- package/dist/secrets.js +6 -3
- package/dist/secrets.js.map +1 -1
- package/package.json +1 -1
- package/dist/auth/authorize.d.ts +0 -2
- package/dist/auth/authorize.js +0 -8
- package/dist/auth/authorize.js.map +0 -1
- package/dist/auth/authorizeAdvanced.d.ts +0 -2
- package/dist/auth/authorizeAdvanced.js +0 -10
- package/dist/auth/authorizeAdvanced.js.map +0 -1
- package/dist/auth/defaults/authorize.d.ts +0 -2
- package/dist/auth/defaults/authorize.js +0 -8
- package/dist/auth/defaults/authorize.js.map +0 -1
- package/dist/auth/defaults/authorizeAdvanced.d.ts +0 -2
- package/dist/auth/defaults/authorizeAdvanced.js +0 -8
- package/dist/auth/defaults/authorizeAdvanced.js.map +0 -1
- package/dist/auth/defaults/index.d.ts +0 -2
- package/dist/auth/defaults/index.js +0 -19
- package/dist/auth/defaults/index.js.map +0 -1
- package/dist/auth/index.d.ts +0 -10
- package/dist/auth/index.js +0 -23
- package/dist/auth/index.js.map +0 -1
- package/dist/error.d.ts +0 -34
- package/dist/error.js +0 -107
- package/dist/error.js.map +0 -1
- package/dist/functions/index.d.ts +0 -31
- package/dist/functions/index.js +0 -200
- package/dist/functions/index.js.map +0 -1
- package/dist/functions/timeout.d.ts +0 -3
- package/dist/functions/timeout.js +0 -23
- package/dist/functions/timeout.js.map +0 -1
- package/dist/network/http/authorize.d.ts +0 -3
- package/dist/network/http/authorize.js +0 -30
- package/dist/network/http/authorize.js.map +0 -1
- package/dist/network/http/compress.d.ts +0 -6
- package/dist/network/http/compress.js +0 -47
- package/dist/network/http/compress.js.map +0 -1
- package/dist/network/http/end.d.ts +0 -4
- package/dist/network/http/end.js +0 -19
- package/dist/network/http/end.js.map +0 -1
- package/dist/network/http/function/index.d.ts +0 -3
- package/dist/network/http/function/index.js +0 -82
- package/dist/network/http/function/index.js.map +0 -1
- package/dist/network/http/function/stream/DataStream.d.ts +0 -7
- package/dist/network/http/function/stream/DataStream.js +0 -17
- package/dist/network/http/function/stream/DataStream.js.map +0 -1
- package/dist/network/http/function/stream/index.d.ts +0 -8
- package/dist/network/http/function/stream/index.js +0 -93
- package/dist/network/http/function/stream/index.js.map +0 -1
- package/dist/network/http/function/stream/multipartFormStream.d.ts +0 -0
- package/dist/network/http/function/stream/multipartFormStream.js +0 -194
- package/dist/network/http/function/stream/multipartFormStream.js.map +0 -1
- package/dist/network/http/function/stream/stream.d.ts +0 -4
- package/dist/network/http/function/stream/stream.js +0 -49
- package/dist/network/http/function/stream/stream.js.map +0 -1
- package/dist/network/http/function.d.ts +0 -3
- package/dist/network/http/function.js +0 -46
- package/dist/network/http/function.js.map +0 -1
- package/dist/network/http/get.d.ts +0 -3
- package/dist/network/http/get.js +0 -143
- package/dist/network/http/get.js.map +0 -1
- package/dist/network/http/index.d.ts +0 -3
- package/dist/network/http/index.js +0 -125
- package/dist/network/http/index.js.map +0 -1
- package/dist/network/http/readBody.d.ts +0 -2
- package/dist/network/http/readBody.js +0 -134
- package/dist/network/http/readBody.js.map +0 -1
- package/dist/network/http/readPostData.d.ts +0 -3
- package/dist/network/http/readPostData.js +0 -50
- package/dist/network/http/readPostData.js.map +0 -1
- package/dist/network/http/send.d.ts +0 -6
- package/dist/network/http/send.js +0 -65
- package/dist/network/http/send.js.map +0 -1
- package/dist/network/http/sendError.d.ts +0 -4
- package/dist/network/http/sendError.js +0 -27
- package/dist/network/http/sendError.js.map +0 -1
- package/dist/network/http/stream/DataStream.d.ts +0 -7
- package/dist/network/http/stream/DataStream.js +0 -17
- package/dist/network/http/stream/DataStream.js.map +0 -1
- package/dist/network/http/stream/formStream.d.ts +0 -4
- package/dist/network/http/stream/formStream.js +0 -184
- package/dist/network/http/stream/formStream.js.map +0 -1
- package/dist/network/http/stream/getExtenstion.d.ts +0 -2
- package/dist/network/http/stream/getExtenstion.js +0 -22
- package/dist/network/http/stream/getExtenstion.js.map +0 -1
- package/dist/network/http/stream/index.d.ts +0 -9
- package/dist/network/http/stream/index.js +0 -42
- package/dist/network/http/stream/index.js.map +0 -1
- package/dist/network/http/stream/multipartFormStream.d.ts +0 -0
- package/dist/network/http/stream/multipartFormStream.js +0 -194
- package/dist/network/http/stream/multipartFormStream.js.map +0 -1
- package/dist/network/http/stream/storeFile.d.ts +0 -5
- package/dist/network/http/stream/storeFile.js +0 -30
- package/dist/network/http/stream/storeFile.js.map +0 -1
- package/dist/network/http/stream/stream.d.ts +0 -4
- package/dist/network/http/stream/stream.js +0 -49
- package/dist/network/http/stream/stream.js.map +0 -1
- package/dist/network/http/stream/types.d.ts +0 -9
- package/dist/network/http/stream/types.js +0 -3
- package/dist/network/http/stream/types.js.map +0 -1
- package/dist/network/http/streamFunction/DataStream.d.ts +0 -7
- package/dist/network/http/streamFunction/DataStream.js +0 -17
- package/dist/network/http/streamFunction/DataStream.js.map +0 -1
- package/dist/network/http/streamFunction/endStreamRequest.d.ts +0 -3
- package/dist/network/http/streamFunction/endStreamRequest.js +0 -20
- package/dist/network/http/streamFunction/endStreamRequest.js.map +0 -1
- package/dist/network/http/streamFunction/getExtension.d.ts +0 -2
- package/dist/network/http/streamFunction/getExtension.js +0 -22
- package/dist/network/http/streamFunction/getExtension.js.map +0 -1
- package/dist/network/http/streamFunction/index.d.ts +0 -3
- package/dist/network/http/streamFunction/index.js +0 -71
- package/dist/network/http/streamFunction/index.js.map +0 -1
- package/dist/network/http/streamFunction/multipartFormStream.d.ts +0 -5
- package/dist/network/http/streamFunction/multipartFormStream.js +0 -189
- package/dist/network/http/streamFunction/multipartFormStream.js.map +0 -1
- package/dist/network/http/streamFunction/multipartStream.d.ts +0 -13
- package/dist/network/http/streamFunction/multipartStream.js +0 -166
- package/dist/network/http/streamFunction/multipartStream.js.map +0 -1
- package/dist/network/http/streamFunction/stream.d.ts +0 -4
- package/dist/network/http/streamFunction/stream.js +0 -106
- package/dist/network/http/streamFunction/stream.js.map +0 -1
- package/dist/network/index.d.ts +0 -4
- package/dist/network/index.js +0 -84
- package/dist/network/index.js.map +0 -1
- package/dist/network/message/auth.d.ts +0 -4
- package/dist/network/message/auth.js +0 -35
- package/dist/network/message/auth.js.map +0 -1
- package/dist/network/message/function.d.ts +0 -3
- package/dist/network/message/function.js +0 -70
- package/dist/network/message/function.js.map +0 -1
- package/dist/network/message/get.d.ts +0 -3
- package/dist/network/message/get.js +0 -111
- package/dist/network/message/get.js.map +0 -1
- package/dist/network/message/index.d.ts +0 -3
- package/dist/network/message/index.js +0 -61
- package/dist/network/message/index.js.map +0 -1
- package/dist/network/message/observable.d.ts +0 -5
- package/dist/network/message/observable.js +0 -105
- package/dist/network/message/observable.js.map +0 -1
- package/dist/network/message/send.d.ts +0 -3
- package/dist/network/message/send.js +0 -11
- package/dist/network/message/send.js.map +0 -1
- package/dist/network/rest/function.d.ts +0 -3
- package/dist/network/rest/function.js +0 -85
- package/dist/network/rest/function.js.map +0 -1
- package/dist/network/rest/index.d.ts +0 -3
- package/dist/network/rest/index.js +0 -65
- package/dist/network/rest/index.js.map +0 -1
- package/dist/network/upgrade.d.ts +0 -4
- package/dist/network/upgrade.js +0 -48
- package/dist/network/upgrade.js.map +0 -1
- package/dist/observable/index.d.ts +0 -8
- package/dist/observable/index.js +0 -224
- package/dist/observable/index.js.map +0 -1
- package/dist/protocol.d.ts +0 -18
- package/dist/protocol.js +0 -206
- package/dist/protocol.js.map +0 -1
- package/dist/server.d.ts +0 -28
- package/dist/server.js +0 -96
- package/dist/server.js.map +0 -1
- package/dist/workers/index.d.ts +0 -0
- package/dist/workers/index.js +0 -20
- package/dist/workers/index.js.map +0 -1
- package/dist/workers/workerCode.d.ts +0 -12
- package/dist/workers/workerCode.js +0 -46
- package/dist/workers/workerCode.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../src/functions/timeout.ts"],"names":[],"mappings":";;;AAEO,MAAM,YAAY,GAAG,CAC1B,IAAqD,EAC5C,EAAE;IACX,IAAI,IAAI,CAAC,cAAc,KAAK,CAAC,CAAC,EAAE;QAC9B,IAAI,IAAI,CAAC,cAAc,KAAK,CAAC,EAAE;YAC7B,OAAO,IAAI,CAAA;SACZ;QACD,IAAI,IAAI,CAAC,WAAW,GAAG,CAAC,IAAI,IAAI,CAAC,cAAc,GAAG,CAAC,EAAE;YACnD,IAAI,CAAC,cAAc,EAAE,CAAA;SACtB;KACF;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAZY,QAAA,YAAY,gBAYxB;AAEM,MAAM,oBAAoB,GAAG,CAClC,IAAqD,EACrD,EAAE;IACF,IAAI,IAAI,CAAC,cAAc,KAAK,CAAC,CAAC,EAAE;QAC9B,IAAI,CAAC,cAAc;YACjB,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,GAAG,GAAG,CAAC,CAAC,CAAA;KACvE;AACH,CAAC,CAAA;AAPY,QAAA,oBAAoB,wBAOhC"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { BasedServer } from '../../server';
|
|
2
|
-
import { BasedFunctionRoute, HttpClient } from '../../types';
|
|
3
|
-
export declare const authorizeRequest: (server: BasedServer, client: HttpClient, payload: any, route: BasedFunctionRoute, authorized: (payload: any) => void) => void;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.authorizeRequest = void 0;
|
|
4
|
-
const send_1 = require("./send");
|
|
5
|
-
const error_1 = require("../../error");
|
|
6
|
-
const authorizeRequest = (server, client, payload, route, authorized) => {
|
|
7
|
-
server.auth.config
|
|
8
|
-
.authorize(server, client, route.name, payload)
|
|
9
|
-
.then((ok) => {
|
|
10
|
-
if (!client.res) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if (!ok) {
|
|
14
|
-
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.AuthorizeRejectedError, {
|
|
15
|
-
name: route.name,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
authorized(payload);
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
.catch((err) => {
|
|
23
|
-
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.AuthorizeFunctionError, {
|
|
24
|
-
name: route.name,
|
|
25
|
-
err,
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
exports.authorizeRequest = authorizeRequest;
|
|
30
|
-
//# sourceMappingURL=authorize.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../../src/network/http/authorize.ts"],"names":[],"mappings":";;;AAEA,iCAAsC;AACtC,uCAA4C;AAErC,MAAM,gBAAgB,GAAG,CAC9B,MAAmB,EACnB,MAAkB,EAClB,OAAY,EACZ,KAAyB,EACzB,UAAkC,EAClC,EAAE;IACF,MAAM,CAAC,IAAI,CAAC,MAAM;SACf,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC;SAC9C,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE;QACX,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,OAAM;SACP;QACD,IAAI,CAAC,EAAE,EAAE;YACP,IAAA,oBAAa,EAAC,MAAM,EAAE,sBAAc,CAAC,sBAAsB,EAAE;gBAC3D,IAAI,EAAE,KAAK,CAAC,IAAI;aACjB,CAAC,CAAA;SACH;aAAM;YACL,UAAU,CAAC,OAAO,CAAC,CAAA;SACpB;IACH,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,IAAA,oBAAa,EAAC,MAAM,EAAE,sBAAc,CAAC,sBAAsB,EAAE;YAC3D,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,GAAG;SACJ,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AA3BY,QAAA,gBAAgB,oBA2B5B"}
|
|
@@ -1,47 +0,0 @@
|
|
|
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.compress = void 0;
|
|
7
|
-
const node_zlib_1 = __importDefault(require("node:zlib"));
|
|
8
|
-
const node_util_1 = require("node:util");
|
|
9
|
-
const deflate = (0, node_util_1.promisify)(node_zlib_1.default.deflate);
|
|
10
|
-
const gzip = (0, node_util_1.promisify)(node_zlib_1.default.gzip);
|
|
11
|
-
const br = (0, node_util_1.promisify)(node_zlib_1.default.brotliCompress);
|
|
12
|
-
/*
|
|
13
|
-
Content-Encoding: gzip
|
|
14
|
-
Content-Encoding: compress
|
|
15
|
-
Content-Encoding: deflate
|
|
16
|
-
Content-Encoding: br
|
|
17
|
-
*/
|
|
18
|
-
const compress = async (client, payload, encoding) => {
|
|
19
|
-
if (!client.res) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (encoding && typeof encoding === 'string') {
|
|
23
|
-
let responseEncoding;
|
|
24
|
-
let compressed;
|
|
25
|
-
if (!(payload instanceof Buffer)) {
|
|
26
|
-
payload = Buffer.from(payload);
|
|
27
|
-
}
|
|
28
|
-
if (encoding.includes('deflate')) {
|
|
29
|
-
responseEncoding = 'defalte';
|
|
30
|
-
compressed = await deflate(payload);
|
|
31
|
-
}
|
|
32
|
-
else if (encoding.includes('gzip')) {
|
|
33
|
-
responseEncoding = 'gzip';
|
|
34
|
-
compressed = await gzip(payload);
|
|
35
|
-
}
|
|
36
|
-
else if (encoding.includes('br')) {
|
|
37
|
-
responseEncoding = 'br';
|
|
38
|
-
compressed = await br(payload);
|
|
39
|
-
}
|
|
40
|
-
if (compressed) {
|
|
41
|
-
return { payload: compressed, encoding: responseEncoding };
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return { payload };
|
|
45
|
-
};
|
|
46
|
-
exports.compress = compress;
|
|
47
|
-
//# sourceMappingURL=compress.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compress.js","sourceRoot":"","sources":["../../../src/network/http/compress.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAC5B,yCAAqC;AAGrC,MAAM,OAAO,GAAG,IAAA,qBAAS,EAAC,mBAAI,CAAC,OAAO,CAAC,CAAA;AACvC,MAAM,IAAI,GAAG,IAAA,qBAAS,EAAC,mBAAI,CAAC,IAAI,CAAC,CAAA;AACjC,MAAM,EAAE,GAAG,IAAA,qBAAS,EAAC,mBAAI,CAAC,cAAc,CAAC,CAAA;AAEzC;;;;;EAKE;AAEK,MAAM,QAAQ,GAAG,KAAK,EAC3B,MAAkB,EAClB,OAAwB,EACxB,QAAgB,EAC0C,EAAE;IAC5D,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;QACf,OAAM;KACP;IACD,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAC5C,IAAI,gBAAwB,CAAA;QAC5B,IAAI,UAAkB,CAAA;QACtB,IAAI,CAAC,CAAC,OAAO,YAAY,MAAM,CAAC,EAAE;YAChC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SAC/B;QACD,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;YAChC,gBAAgB,GAAG,SAAS,CAAA;YAC5B,UAAU,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;SACpC;aAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACpC,gBAAgB,GAAG,MAAM,CAAA;YACzB,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,CAAA;SACjC;aAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YAClC,gBAAgB,GAAG,IAAI,CAAA;YACvB,UAAU,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,CAAA;SAC/B;QACD,IAAI,UAAU,EAAE;YACd,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAA;SAC3D;KACF;IACD,OAAO,EAAE,OAAO,EAAE,CAAA;AACpB,CAAC,CAAA;AA7BY,QAAA,QAAQ,YA6BpB"}
|
package/dist/network/http/end.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = (client, payload) => {
|
|
4
|
-
if (client.res) {
|
|
5
|
-
client.res.writeHeader('Access-Control-Allow-Origin', '*');
|
|
6
|
-
// only allowed headers
|
|
7
|
-
client.res.writeHeader('Access-Control-Allow-Headers', '*');
|
|
8
|
-
if (payload === undefined) {
|
|
9
|
-
client.res.end();
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
client.res.end(payload);
|
|
13
|
-
}
|
|
14
|
-
client.res = null;
|
|
15
|
-
client.req = null;
|
|
16
|
-
client.context = null;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=end.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"end.js","sourceRoot":"","sources":["../../../src/network/http/end.ts"],"names":[],"mappings":";;AAEA,kBAAe,CAAC,MAAkB,EAAE,OAAsC,EAAE,EAAE;IAC5E,IAAI,MAAM,CAAC,GAAG,EAAE;QACd,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;QAC1D,uBAAuB;QACvB,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAA;QAC3D,IAAI,OAAO,KAAK,SAAS,EAAE;YACzB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;SACjB;aAAM;YACL,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;SACxB;QACD,MAAM,CAAC,GAAG,GAAG,IAAI,CAAA;QACjB,MAAM,CAAC,GAAG,GAAG,IAAI,CAAA;QACjB,MAAM,CAAC,OAAO,GAAG,IAAI,CAAA;KACtB;AACH,CAAC,CAAA"}
|
|
@@ -1,82 +0,0 @@
|
|
|
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.httpFunction = void 0;
|
|
7
|
-
const functions_1 = require("../../../functions");
|
|
8
|
-
const end_1 = __importDefault(require("../end"));
|
|
9
|
-
const compress_1 = require("../compress");
|
|
10
|
-
const sendError_1 = require("../sendError");
|
|
11
|
-
const sendResponse = (client, encoding, result) => {
|
|
12
|
-
if (!client.res) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
client.res.writeStatus('200 OK');
|
|
16
|
-
// for functions there is never cache (idea is they are used to execute - observable fns are for cache)
|
|
17
|
-
client.res.writeHeader('Cache-Control', 'max-age=0, must-revalidate');
|
|
18
|
-
let parsed;
|
|
19
|
-
if (typeof result === 'string') {
|
|
20
|
-
client.res.writeHeader('Content-Type', 'text/plain');
|
|
21
|
-
parsed = result;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
client.res.writeHeader('Content-Type', 'application/json');
|
|
25
|
-
parsed = JSON.stringify(result);
|
|
26
|
-
}
|
|
27
|
-
(0, compress_1.compress)(client, parsed, encoding).then((p) => (0, end_1.default)(client, p));
|
|
28
|
-
};
|
|
29
|
-
const httpFunction = (name, encoding, payload, client, server) => {
|
|
30
|
-
// fix max payload from spec..
|
|
31
|
-
// parse payload
|
|
32
|
-
server.functions
|
|
33
|
-
.install(name)
|
|
34
|
-
.then((spec) => {
|
|
35
|
-
if (!client.res) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (spec && !(0, functions_1.isObservableFunctionSpec)(spec)) {
|
|
39
|
-
server.auth.config
|
|
40
|
-
.authorize(server, client, 'function', name, payload)
|
|
41
|
-
.then((ok) => {
|
|
42
|
-
if (!client.res) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (!ok) {
|
|
46
|
-
(0, sendError_1.sendError)(client, `${name} unauthorized request`, 401, 'Unauthorized');
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
spec
|
|
50
|
-
.function(payload, client)
|
|
51
|
-
.then(async (result) => {
|
|
52
|
-
if (!client.res) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (spec.customHttpResponse) {
|
|
56
|
-
if (await spec.customHttpResponse(result, payload, client)) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
sendResponse(client, encoding, result);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
sendResponse(client, encoding, result);
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
.catch((err) => {
|
|
66
|
-
(0, sendError_1.sendError)(client, err.message);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
.catch((err) => (0, sendError_1.sendError)(client, err.message, 401, 'Unauthorized'));
|
|
71
|
-
}
|
|
72
|
-
else if (spec && (0, functions_1.isObservableFunctionSpec)(spec)) {
|
|
73
|
-
(0, sendError_1.sendError)(client, `function is observable - use /get/${name} instead`, 404, 'Not Found');
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
(0, sendError_1.sendError)(client, `function does not exist ${name}`, 404, 'Not Found');
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
|
-
.catch(() => (0, sendError_1.sendError)(client, `function does not exist ${name}`, 404, 'Not Found'));
|
|
80
|
-
};
|
|
81
|
-
exports.httpFunction = httpFunction;
|
|
82
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/network/http/function/index.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6D;AAG7D,iDAAwB;AACxB,0CAAsC;AACtC,4CAAwC;AAExC,MAAM,YAAY,GAAG,CAAC,MAAkB,EAAE,QAAgB,EAAE,MAAW,EAAE,EAAE;IACzE,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;QACf,OAAM;KACP;IAED,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;IAEhC,uGAAuG;IACvG,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,eAAe,EAAE,4BAA4B,CAAC,CAAA;IAErE,IAAI,MAAc,CAAA;IAElB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,cAAc,EAAE,YAAY,CAAC,CAAA;QACpD,MAAM,GAAG,MAAM,CAAA;KAChB;SAAM;QACL,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAA;QAC1D,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;KAChC;IAED,IAAA,mBAAQ,EAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,aAAG,EAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAA;AAChE,CAAC,CAAA;AAEM,MAAM,YAAY,GAAG,CAC1B,IAAY,EACZ,QAAgB,EAChB,OAAY,EACZ,MAAkB,EAClB,M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ACH,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,qBAAS,EAAC,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,cAAc,CAAC,CAAC,CAAA;SACvE;aAAM,IAAI,IAAI,IAAI,IAAA,oCAAwB,EAAC,IAAI,CAAC,EAAE;YACjD,IAAA,qBAAS,EACP,MAAM,EACN,qCAAqC,IAAI,UAAU,EACnD,GAAG,EACH,WAAW,CACZ,CAAA;SACF;aAAM;YACL,IAAA,qBAAS,EAAC,MAAM,EAAE,2BAA2B,IAAI,EAAE,EAAE,GAAG,EAAE,WAAW,CAAC,CAAA;SACvE;IACH,CAAC,CAAC;SACD,KAAK,CAAC,GAAG,EAAE,CACV,IAAA,qBAAS,EAAC,MAAM,EAAE,2BAA2B,IAAI,EAAE,EAAE,GAAG,EAAE,WAAW,CAAC,CACvE,CAAA;AACL,CAAC,CAAA;AArEY,QAAA,YAAY,gBAqExB"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataStream = void 0;
|
|
4
|
-
const stream_1 = require("stream");
|
|
5
|
-
class DataStream extends stream_1.Duplex {
|
|
6
|
-
_read() { }
|
|
7
|
-
// writableHighWaterMark:
|
|
8
|
-
_write(chunk, encoding, callback) {
|
|
9
|
-
this.push(Buffer.from(chunk));
|
|
10
|
-
callback();
|
|
11
|
-
}
|
|
12
|
-
_final() {
|
|
13
|
-
this.push(null);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.DataStream = DataStream;
|
|
17
|
-
//# sourceMappingURL=DataStream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DataStream.js","sourceRoot":"","sources":["../../../../../src/network/http/function/stream/DataStream.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;AAE/B,MAAa,UAAW,SAAQ,eAAM;IACpC,KAAK,KAAI,CAAC;IAEV,yBAAyB;IACzB,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ;QAC9B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;QAC7B,QAAQ,EAAE,CAAA;IACZ,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACjB,CAAC;CACF;AAZD,gCAYC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import uws from '@based/uws';
|
|
2
|
-
import { HttpClient } from '../../../../types';
|
|
3
|
-
export declare const invalidReqNoCors: (res: uws.HttpResponse) => void;
|
|
4
|
-
export declare type StreamOptions = {
|
|
5
|
-
type: string;
|
|
6
|
-
size: number;
|
|
7
|
-
};
|
|
8
|
-
export declare const readStream: (client: HttpClient, onData: (data: any | void) => void, maxSize?: number) => void;
|
|
@@ -1,93 +0,0 @@
|
|
|
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.readStream = exports.invalidReqNoCors = void 0;
|
|
7
|
-
const end_1 = __importDefault(require("../../end"));
|
|
8
|
-
const invalidReqNoCors = (res) => {
|
|
9
|
-
res.aborted = true;
|
|
10
|
-
res
|
|
11
|
-
.writeStatus('400 Invalid Request')
|
|
12
|
-
.end(`{"code":400,"error":"Invalid Request"}`);
|
|
13
|
-
};
|
|
14
|
-
exports.invalidReqNoCors = invalidReqNoCors;
|
|
15
|
-
const MAX_BODY_SIZE = 4 ** 20; // 2MB
|
|
16
|
-
const readStream = (client, onData, maxSize = MAX_BODY_SIZE // 2MB
|
|
17
|
-
) => {
|
|
18
|
-
let data = Buffer.from([]);
|
|
19
|
-
client.res.onData(async (chunk, isLast) => {
|
|
20
|
-
if (!client.res) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
// STREAM
|
|
24
|
-
// Content type json OR nothing handle total
|
|
25
|
-
// Size add the stream
|
|
26
|
-
data = Buffer.concat([data, Buffer.from(chunk)]);
|
|
27
|
-
if (data.length > MAX_BODY_SIZE) {
|
|
28
|
-
client.res.writeStatus('413 Payload Too Large');
|
|
29
|
-
client.res.writeHeader('Access-Control-Allow-Origin', '*');
|
|
30
|
-
client.res.writeHeader('Access-Control-Allow-Headers', 'content-type');
|
|
31
|
-
(0, end_1.default)(client, `{"code":413,"error":"Payload Too Large"}`);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (isLast) {
|
|
35
|
-
let params;
|
|
36
|
-
const str = data.toString();
|
|
37
|
-
// dont do string just add handlers
|
|
38
|
-
// also check for buffer / binary daya
|
|
39
|
-
// may want to do this differently....
|
|
40
|
-
if (client.context.contentType === 'application/json' ||
|
|
41
|
-
!client.context.contentType) {
|
|
42
|
-
try {
|
|
43
|
-
params = data.length ? JSON.parse(str) : undefined;
|
|
44
|
-
onData(params);
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
console.error(e, str);
|
|
48
|
-
client.res.writeStatus('400 Invalid Request');
|
|
49
|
-
client.res.writeHeader('Access-Control-Allow-Origin', '*');
|
|
50
|
-
client.res.writeHeader('Access-Control-Allow-Headers', 'content-type');
|
|
51
|
-
(0, end_1.default)(client, `{"code":400,"error":"Invalid payload"}`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
onData(str);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
exports.readStream = readStream;
|
|
61
|
-
// export default async (
|
|
62
|
-
// server: BasedServer,
|
|
63
|
-
// name: string,
|
|
64
|
-
// req: uws.HttpRequest,
|
|
65
|
-
// res: uws.HttpResponse
|
|
66
|
-
// ) => {
|
|
67
|
-
// const method = req.getMethod()
|
|
68
|
-
// if (method !== 'post') {
|
|
69
|
-
// console.info('options or get')
|
|
70
|
-
// res.end('')
|
|
71
|
-
// return
|
|
72
|
-
// }
|
|
73
|
-
// const type = req.getHeader('content-type')
|
|
74
|
-
// if (type === 'multipart/form-data') {
|
|
75
|
-
// // formStream(server, res)
|
|
76
|
-
// return
|
|
77
|
-
// }
|
|
78
|
-
// const size = Number(req.getHeader('content-length'))
|
|
79
|
-
// if (!type) {
|
|
80
|
-
// invalidReqNoCors(res)
|
|
81
|
-
// return
|
|
82
|
-
// }
|
|
83
|
-
// const opts: StreamOptions = {
|
|
84
|
-
// size,
|
|
85
|
-
// type,
|
|
86
|
-
// }
|
|
87
|
-
// if (!opts.size) {
|
|
88
|
-
// invalidReqNoCors(res)
|
|
89
|
-
// return
|
|
90
|
-
// }
|
|
91
|
-
// stream(res, size)
|
|
92
|
-
// }
|
|
93
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/network/http/function/stream/index.ts"],"names":[],"mappings":";;;;;;AAGA,oDAA2B;AAIpB,MAAM,gBAAgB,GAAG,CAAC,GAAqB,EAAE,EAAE;IACxD,GAAG,CAAC,OAAO,GAAG,IAAI,CAAA;IAClB,GAAG;SACA,WAAW,CAAC,qBAAqB,CAAC;SAClC,GAAG,CAAC,wCAAwC,CAAC,CAAA;AAClD,CAAC,CAAA;AALY,QAAA,gBAAgB,oBAK5B;AAOD,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,CAAA,CAAC,MAAM;AAE7B,MAAM,UAAU,GAAG,CACxB,MAAkB,EAClB,MAAkC,EAClC,OAAO,GAAG,aAAa,CAAC,MAAM;EAC9B,EAAE;IACF,IAAI,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAE1B,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE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C,WAAW,CAAC,8BAA8B,EAAE,cAAc,CAAC,CAAA;oBACtE,IAAA,aAAG,EAAC,MAAM,EAAE,wCAAwC,CAAC,CAAA;iBACtD;aACF;iBAAM;gBACL,MAAM,CAAC,GAAG,CAAC,CAAA;aACZ;SACF;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAjDY,QAAA,UAAU,cAiDtB;AAED,yBAAyB;AACzB,yBAAyB;AACzB,kBAAkB;AAClB,0BAA0B;AAC1B,0BAA0B;AAC1B,SAAS;AACT,mCAAmC;AAEnC,6BAA6B;AAC7B,qCAAqC;AACrC,kBAAkB;AAClB,aAAa;AACb,MAAM;AAEN,+CAA+C;AAE/C,0CAA0C;AAC1C,iCAAiC;AACjC,aAAa;AACb,MAAM;AAEN,yDAAyD;AAEzD,iBAAiB;AACjB,4BAA4B;AAC5B,aAAa;AACb,MAAM;AAEN,kCAAkC;AAClC,YAAY;AACZ,YAAY;AACZ,MAAM;AAEN,sBAAsB;AACtB,4BAA4B;AAC5B,aAAa;AACb,MAAM;AAEN,sBAAsB;AACtB,IAAI"}
|
|
File without changes
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
// import { DataStream } from './DataStream'
|
|
2
|
-
// import uws from '@based/uws'
|
|
3
|
-
// import { BasedServer } from '../../..'
|
|
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 = (
|
|
18
|
-
// server: BasedServer,
|
|
19
|
-
// file: FileDescriptor,
|
|
20
|
-
// res: uws.HttpResponse
|
|
21
|
-
// ): boolean => {
|
|
22
|
-
// file.headersSet++
|
|
23
|
-
// if (file.headersSet === 2) {
|
|
24
|
-
// const opts = file.opts
|
|
25
|
-
// if (isCompleteOpts(opts)) {
|
|
26
|
-
// if (opts.size < 200000) {
|
|
27
|
-
// file.stream.on('end', () => {
|
|
28
|
-
// const payload: any = {
|
|
29
|
-
// $id: opts.id,
|
|
30
|
-
// progress: 1,
|
|
31
|
-
// size: opts.size,
|
|
32
|
-
// }
|
|
33
|
-
// if (opts.name) {
|
|
34
|
-
// payload.name = opts.name
|
|
35
|
-
// }
|
|
36
|
-
// server.based.set(payload)
|
|
37
|
-
// })
|
|
38
|
-
// } else {
|
|
39
|
-
// let progress = 0
|
|
40
|
-
// let total = 0
|
|
41
|
-
// let setInProgress = false
|
|
42
|
-
// const payload: any = {
|
|
43
|
-
// $id: opts.id,
|
|
44
|
-
// progress: 0,
|
|
45
|
-
// size: opts.size,
|
|
46
|
-
// }
|
|
47
|
-
// if (opts.name) {
|
|
48
|
-
// payload.name = opts.name
|
|
49
|
-
// }
|
|
50
|
-
// server.based.set(payload)
|
|
51
|
-
// const updateProgress = () => {
|
|
52
|
-
// if (!setInProgress) {
|
|
53
|
-
// setInProgress = true
|
|
54
|
-
// setTimeout(() => {
|
|
55
|
-
// const payload: any = {
|
|
56
|
-
// $id: opts.id,
|
|
57
|
-
// progress,
|
|
58
|
-
// }
|
|
59
|
-
// server.based.set(payload)
|
|
60
|
-
// setInProgress = false
|
|
61
|
-
// }, 250)
|
|
62
|
-
// }
|
|
63
|
-
// }
|
|
64
|
-
// file.stream.on('end', () => {
|
|
65
|
-
// progress = 1
|
|
66
|
-
// updateProgress()
|
|
67
|
-
// })
|
|
68
|
-
// file.stream.on('data', (chunk) => {
|
|
69
|
-
// total += chunk.byteLength
|
|
70
|
-
// progress = total / opts.size
|
|
71
|
-
// updateProgress()
|
|
72
|
-
// })
|
|
73
|
-
// }
|
|
74
|
-
// storeFile(server, file.stream, opts)
|
|
75
|
-
// } else {
|
|
76
|
-
// invalidFile(res)
|
|
77
|
-
// return null
|
|
78
|
-
// }
|
|
79
|
-
// return true
|
|
80
|
-
// }
|
|
81
|
-
// return false
|
|
82
|
-
// }
|
|
83
|
-
// const invalidFile = (res: uws.HttpResponse) => {
|
|
84
|
-
// console.info('Invalid file')
|
|
85
|
-
// res.aborted = true
|
|
86
|
-
// res.writeStatus('400 Invalid Request').end('{"error":"invalid file}')
|
|
87
|
-
// }
|
|
88
|
-
// const toBuffer = (str: string, firstWritten: boolean): Buffer => {
|
|
89
|
-
// return Buffer.from(firstWritten ? str + '\r\n' : str, 'binary')
|
|
90
|
-
// }
|
|
91
|
-
// export default async (
|
|
92
|
-
// server: BasedServer,
|
|
93
|
-
// res: uws.HttpResponse
|
|
94
|
-
// ): Promise<void> => {
|
|
95
|
-
// const files: FileDescriptor[] = []
|
|
96
|
-
// let boundary = null
|
|
97
|
-
// let prevLine: string
|
|
98
|
-
// let isWriting = false
|
|
99
|
-
// res.onData((chunk, isLast) => {
|
|
100
|
-
// let firstWritten = false
|
|
101
|
-
// const blocks = Buffer.from(chunk).toString('binary').split('\r\n')
|
|
102
|
-
// if (!boundary) {
|
|
103
|
-
// boundary = blocks[0]
|
|
104
|
-
// }
|
|
105
|
-
// for (let i = 0; i < blocks.length; i++) {
|
|
106
|
-
// const line = blocks[i]
|
|
107
|
-
// if (!boundary) {
|
|
108
|
-
// continue
|
|
109
|
-
// }
|
|
110
|
-
// if (isWriting && (line === boundary || line === boundary + '--')) {
|
|
111
|
-
// isWriting = false
|
|
112
|
-
// const file = files[files.length - 1]
|
|
113
|
-
// if (prevLine) {
|
|
114
|
-
// file.stream.end(toBuffer(prevLine, firstWritten))
|
|
115
|
-
// } else {
|
|
116
|
-
// file.stream.end()
|
|
117
|
-
// }
|
|
118
|
-
// prevLine = null
|
|
119
|
-
// if (line === boundary + '--') {
|
|
120
|
-
// continue
|
|
121
|
-
// }
|
|
122
|
-
// }
|
|
123
|
-
// if (line === boundary && !isWriting) {
|
|
124
|
-
// const file = {
|
|
125
|
-
// stream: new DataStream(),
|
|
126
|
-
// headersSet: 0,
|
|
127
|
-
// opts: {},
|
|
128
|
-
// }
|
|
129
|
-
// files.push(file)
|
|
130
|
-
// // try {
|
|
131
|
-
// // fs.unlinkSync('/Users/jim/Desktop/yes.png')
|
|
132
|
-
// // } catch (err) {}
|
|
133
|
-
// // file.stream.pipe(fs.createWriteStream('/Users/jim/Desktop/yes.png'))
|
|
134
|
-
// continue
|
|
135
|
-
// }
|
|
136
|
-
// const file = files[files.length - 1]
|
|
137
|
-
// if (!file) {
|
|
138
|
-
// return invalidFile(res)
|
|
139
|
-
// }
|
|
140
|
-
// if (!isWriting && line.includes('Content-Disposition')) {
|
|
141
|
-
// const meta = line.match(/name="(.*?)"/)?.[1]
|
|
142
|
-
// if (!meta) {
|
|
143
|
-
// return invalidFile(res)
|
|
144
|
-
// }
|
|
145
|
-
// const [functionName, raw, id, size, ...name] = meta.split('|')
|
|
146
|
-
// const opts = file.opts
|
|
147
|
-
// opts.id = id
|
|
148
|
-
// if (raw) {
|
|
149
|
-
// opts.raw = true
|
|
150
|
-
// }
|
|
151
|
-
// if (name && name.length) {
|
|
152
|
-
// opts.name = name.join('|')
|
|
153
|
-
// } else {
|
|
154
|
-
// opts.name = line.match(/filename="(.*?)"/)?.[1] || 'untitled'
|
|
155
|
-
// }
|
|
156
|
-
// if (functionName) {
|
|
157
|
-
// opts.functionName = functionName
|
|
158
|
-
// }
|
|
159
|
-
// opts.size = Number(size)
|
|
160
|
-
// isWriting = setHeader(server, file, res)
|
|
161
|
-
// if (isWriting === null) {
|
|
162
|
-
// return
|
|
163
|
-
// }
|
|
164
|
-
// continue
|
|
165
|
-
// }
|
|
166
|
-
// if (!isWriting && line.includes('Content-Type')) {
|
|
167
|
-
// const mimeType = line.match(
|
|
168
|
-
// /Content-Type: ([a-zA-Z0-9].+\/[a-zA-Z0-9].+)/
|
|
169
|
-
// )?.[1]
|
|
170
|
-
// if (!mimeType) {
|
|
171
|
-
// return invalidFile(res)
|
|
172
|
-
// }
|
|
173
|
-
// file.opts.type = mimeType
|
|
174
|
-
// file.opts.extension = getExtenstion(mimeType)
|
|
175
|
-
// isWriting = setHeader(server, file, res)
|
|
176
|
-
// if (isWriting === null) {
|
|
177
|
-
// return
|
|
178
|
-
// }
|
|
179
|
-
// continue
|
|
180
|
-
// }
|
|
181
|
-
// if (isWriting) {
|
|
182
|
-
// if (prevLine) {
|
|
183
|
-
// file.stream.write(toBuffer(prevLine, firstWritten))
|
|
184
|
-
// }
|
|
185
|
-
// prevLine = line
|
|
186
|
-
// firstWritten = true
|
|
187
|
-
// }
|
|
188
|
-
// }
|
|
189
|
-
// if (isLast) {
|
|
190
|
-
// res.end('{}')
|
|
191
|
-
// }
|
|
192
|
-
// })
|
|
193
|
-
// }
|
|
194
|
-
//# sourceMappingURL=multipartFormStream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"multipartFormStream.js","sourceRoot":"","sources":["../../../../../src/network/http/function/stream/multipartFormStream.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,+BAA+B;AAC/B,yCAAyC;AACzC,8CAA8C;AAC9C,yBAAyB;AAEzB,0BAA0B;AAC1B,+BAA+B;AAC/B,uBAAuB;AACvB,uBAAuB;AACvB,IAAI;AAEJ,2BAA2B;AAC3B,kCAAkC;AAClC,iCAAiC;AACjC,+EAA+E;AAC/E,IAAI;AAEJ,yBAAyB;AAEzB,sBAAsB;AACtB,yBAAyB;AACzB,0BAA0B;AAC1B,0BAA0B;AAC1B,kBAAkB;AAClB,sBAAsB;AACtB,iCAAiC;AACjC,6BAA6B;AAC7B,kCAAkC;AAClC,kCAAkC;AAClC,wCAAwC;AACxC,mCAAmC;AACnC,4BAA4B;AAC5B,2BAA2B;AAC3B,+BAA+B;AAC/B,cAAc;AACd,6BAA6B;AAC7B,uCAAuC;AACvC,cAAc;AACd,sCAAsC;AACtC,aAAa;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yBAAyB;AACzB,sCAAsC;AACtC,2BAA2B;AAC3B,sBAAsB;AACtB,YAAY;AACZ,2BAA2B;AAC3B,mBAAmB;AACnB,2DAA2D;AAC3D,8BAA8B;AAC9B,kFAAkF;AAClF,mBAAmB;AACnB,UAAU;AAEV,6CAA6C;AAE7C,qBAAqB;AACrB,kCAAkC;AAClC,UAAU;AAEV,kEAAkE;AAClE,uDAAuD;AACvD,uBAAuB;AACvB,oCAAoC;AACpC,YAAY;AACZ,yEAAyE;AACzE,iCAAiC;AACjC,uBAAuB;AACvB,qBAAqB;AACrB,4BAA4B;AAC5B,YAAY;AACZ,qCAAqC;AACrC,uCAAuC;AACvC,mBAAmB;AACnB,0EAA0E;AAC1E,YAAY;AACZ,8BAA8B;AAC9B,6CAA6C;AAC7C,YAAY;AACZ,mCAAmC;AACnC,mDAAmD;AACnD,oCAAoC;AACpC,mBAAmB;AACnB,YAAY;AACZ,mBAAmB;AACnB,UAAU;AAEV,2DAA2D;AAC3D,uCAAuC;AACvC,2DAA2D;AAC3D,iBAAiB;AACjB,2BAA2B;AAC3B,oCAAoC;AACpC,YAAY;AACZ,oCAAoC;AACpC,wDAAwD;AACxD,mDAAmD;AACnD,oCAAoC;AACpC,mBAAmB;AACnB,YAAY;AACZ,mBAAmB;AACnB,UAAU;AAEV,yBAAyB;AACzB,0BAA0B;AAC1B,gEAAgE;AAChE,YAAY;AACZ,0BAA0B;AAC1B,8BAA8B;AAC9B,UAAU;AACV,QAAQ;AAER,oBAAoB;AACpB,sBAAsB;AACtB,QAAQ;AACR,OAAO;AACP,IAAI"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const DataStream_1 = require("./DataStream");
|
|
4
|
-
const smallFile = (res, stream) => {
|
|
5
|
-
stream.emit('progress', 0);
|
|
6
|
-
res.onData(async (chunk, isLast) => {
|
|
7
|
-
const buf = Buffer.from(chunk);
|
|
8
|
-
stream.write(buf);
|
|
9
|
-
if (isLast) {
|
|
10
|
-
stream.emit('progress', 1);
|
|
11
|
-
stream.end();
|
|
12
|
-
res.end(`{}`);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
const largeFile = (res, stream, size) => {
|
|
17
|
-
let progress = 0;
|
|
18
|
-
let total = 0;
|
|
19
|
-
let setInProgress = false;
|
|
20
|
-
stream.emit('progress', progress);
|
|
21
|
-
res.onData(async (chunk, isLast) => {
|
|
22
|
-
const buf = Buffer.from(chunk);
|
|
23
|
-
total += buf.byteLength;
|
|
24
|
-
progress = total / size;
|
|
25
|
-
if (!setInProgress) {
|
|
26
|
-
setInProgress = true;
|
|
27
|
-
setTimeout(() => {
|
|
28
|
-
stream.emit('progress', progress);
|
|
29
|
-
setInProgress = false;
|
|
30
|
-
}, 250);
|
|
31
|
-
}
|
|
32
|
-
stream.write(buf);
|
|
33
|
-
if (isLast) {
|
|
34
|
-
stream.end();
|
|
35
|
-
res.end(`{}`);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
exports.default = async (res, size) => {
|
|
40
|
-
const stream = new DataStream_1.DataStream();
|
|
41
|
-
if (size > 200000) {
|
|
42
|
-
largeFile(res, stream, size);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
smallFile(res, stream);
|
|
46
|
-
}
|
|
47
|
-
return stream;
|
|
48
|
-
};
|
|
49
|
-
//# sourceMappingURL=stream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../../../src/network/http/function/stream/stream.ts"],"names":[],"mappings":";;AAAA,6CAAyC;AAGzC,MAAM,SAAS,GAAG,CAAC,GAAqB,EAAE,MAAkB,EAAE,EAAE;IAC9D,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAA;IAC1B,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,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