@based/server 3.3.6 → 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,93 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;QACxC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,OAAM;SACP;QAED,SAAS;QAET,4CAA4C;QAC5C,sBAAsB;QACtB,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAChD,IAAI,IA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AU,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
|
|
@@ -0,0 +1,194 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;AACb,iBAAiB;AACjB,2BAA2B;AAC3B,wBAAwB;AACxB,oCAAoC;AACpC,iCAAiC;AACjC,0BAA0B;AAC1B,yBAAyB;AACzB,6BAA6B;AAC7B,YAAY;AACZ,2BAA2B;AAC3B,qCAAqC;AACrC,YAAY;AACZ,oCAAoC;AACpC,yCAAyC;AACzC,kCAAkC;AAClC,mCAAm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V,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"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,MAAM,EAAE,EAAE;QACjC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAC9B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACjB,IAAI,MAAM,EAAE;YACV,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAA;YAC1B,MAA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ACL,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;KACvB;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.httpFunction = void 0;
|
|
4
|
+
const functions_1 = require("../../functions");
|
|
5
|
+
const send_1 = require("./send");
|
|
6
|
+
const error_1 = require("../../error");
|
|
7
|
+
const httpFunction = (route, payload, client, server) => {
|
|
8
|
+
if (!client.res) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const name = route.name;
|
|
12
|
+
server.functions
|
|
13
|
+
.install(name)
|
|
14
|
+
.then((spec) => {
|
|
15
|
+
if (!client.res) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (spec && !(0, functions_1.isObservableFunctionSpec)(spec)) {
|
|
19
|
+
spec
|
|
20
|
+
.function(payload, client)
|
|
21
|
+
.then(async (result) => {
|
|
22
|
+
if (!client.res) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (spec.customHttpResponse) {
|
|
26
|
+
if (await spec.customHttpResponse(result, payload, client)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
(0, send_1.sendHttpResponse)(client, result);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
(0, send_1.sendHttpResponse)(client, result);
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
.catch((err) => {
|
|
36
|
+
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.FunctionError, {
|
|
37
|
+
err,
|
|
38
|
+
name,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
.catch(() => (0, send_1.sendHttpError)(client, error_1.BasedErrorCode.FunctionNotFound, { name }));
|
|
44
|
+
};
|
|
45
|
+
exports.httpFunction = httpFunction;
|
|
46
|
+
//# sourceMappingURL=function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../../src/network/http/function.ts"],"names":[],"mappings":";;;AAAA,+CAA0D;AAG1D,iCAAwD;AACxD,uCAA4C;AAErC,MAAM,YAAY,GAAG,CAC1B,KAAyB,EACzB,OAAY,EACZ,MAAkB,EAClB,MAAmB,EACb,EAAE;IACR,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;QACf,OAAM;KACP;IACD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;IACvB,MAAM,CAAC,SAAS;SACb,OAAO,CAAC,IAAI,CAAC;SACb,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACb,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,OAAM;SACP;QACD,IAAI,IAAI,IAAI,CAAC,IAAA,oCAAwB,EAAC,IAAI,CAAC,EAAE;YAC3C,IAAI;iBACD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;iBACzB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;gBACrB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;oBACf,OAAM;iBACP;gBACD,IAAI,IAAI,CAAC,kBAAkB,EAAE;oBAC3B,IAAI,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE;wBAC1D,OAAM;qBACP;oBACD,IAAA,uBAAgB,EAAC,MAAM,EAAE,MAAM,CAAC,CAAA;iBACjC;qBAAM;oBACL,IAAA,uBAAgB,EAAC,MAAM,EAAE,MAAM,CAAC,CAAA;iBACjC;YACH,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACb,IAAA,oBAAa,EAAC,MAAM,EAAE,sBAAc,CAAC,aAAa,EAAE;oBAClD,GAAG;oBACH,IAAI;iBACL,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;SACL;IACH,CAAC,CAAC;SACD,KAAK,CAAC,GAAG,EAAE,CACV,IAAA,oBAAa,EAAC,MAAM,EAAE,sBAAc,CAAC,gBAAgB,EAAE,EAAE,IAAI,EAAE,CAAC,CACjE,CAAA;AACL,CAAC,CAAA;AA3CY,QAAA,YAAY,gBA2CxB"}
|
|
@@ -0,0 +1,143 @@
|
|
|
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.httpGet = void 0;
|
|
7
|
+
const functions_1 = require("../../functions");
|
|
8
|
+
const end_1 = __importDefault(require("./end"));
|
|
9
|
+
const compress_1 = require("./compress");
|
|
10
|
+
const send_1 = require("./send");
|
|
11
|
+
const hash_1 = require("@saulx/hash");
|
|
12
|
+
const observable_1 = require("../../observable");
|
|
13
|
+
const node_zlib_1 = __importDefault(require("node:zlib"));
|
|
14
|
+
const error_1 = require("../../error");
|
|
15
|
+
const sendGetResponse = (server, id, obs, checksum, client) => {
|
|
16
|
+
if (!client.res) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const encoding = client.context.headers.encoding;
|
|
20
|
+
try {
|
|
21
|
+
if (checksum === 0 || checksum !== obs.checksum) {
|
|
22
|
+
if (!obs.cache) {
|
|
23
|
+
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.NoOservableCacheAvailable, {
|
|
24
|
+
observableId: id,
|
|
25
|
+
name: obs.name,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (obs.isDeflate) {
|
|
30
|
+
if (typeof encoding === 'string' && encoding.includes('deflate')) {
|
|
31
|
+
client.res.cork(() => {
|
|
32
|
+
client.res.writeStatus('200 OK');
|
|
33
|
+
client.res.writeHeader('ETag', String(obs.checksum));
|
|
34
|
+
client.res.writeHeader('Content-Encoding', 'deflate');
|
|
35
|
+
(0, end_1.default)(client, obs.cache.slice(4 + 8 + 8));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else if (obs.rawData) {
|
|
39
|
+
(0, compress_1.compress)(client, JSON.stringify(obs.rawData), encoding).then(({ payload, encoding }) => {
|
|
40
|
+
if (client.res) {
|
|
41
|
+
client.res.cork(() => {
|
|
42
|
+
client.res.writeStatus('200 OK');
|
|
43
|
+
if (encoding) {
|
|
44
|
+
client.res.writeHeader('Content-Encoding', encoding);
|
|
45
|
+
}
|
|
46
|
+
client.res.writeHeader('ETag', String(obs.checksum));
|
|
47
|
+
(0, end_1.default)(client, payload);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
(0, compress_1.compress)(client, node_zlib_1.default.inflateRawSync(obs.cache.slice(4 + 8 + 8)), encoding).then(({ payload, encoding }) => {
|
|
54
|
+
client.res.cork(() => {
|
|
55
|
+
client.res.writeStatus('200 OK');
|
|
56
|
+
if (encoding) {
|
|
57
|
+
client.res.writeHeader('Content-Encoding', encoding);
|
|
58
|
+
}
|
|
59
|
+
client.res.writeHeader('ETag', String(obs.checksum));
|
|
60
|
+
(0, end_1.default)(client, payload);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
client.res.cork(() => {
|
|
67
|
+
client.res.writeStatus('200 OK');
|
|
68
|
+
client.res.writeHeader('ETag', String(obs.checksum));
|
|
69
|
+
(0, end_1.default)(client, obs.cache.slice(4 + 8 + 8));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
client.res.cork(() => {
|
|
76
|
+
client.res.writeStatus('304 Not Modified');
|
|
77
|
+
(0, end_1.default)(client);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.FunctionError, {
|
|
83
|
+
err,
|
|
84
|
+
observableId: id,
|
|
85
|
+
name: obs.name,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (obs.clients.size === 0) {
|
|
89
|
+
(0, observable_1.destroy)(server, id);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const httpGet = (route, payload, client, server, checksum) => {
|
|
93
|
+
if (!client.res) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const name = route.name;
|
|
97
|
+
server.functions
|
|
98
|
+
.install(name)
|
|
99
|
+
.then((spec) => {
|
|
100
|
+
if (!client.res) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (spec && (0, functions_1.isObservableFunctionSpec)(spec)) {
|
|
104
|
+
const id = (0, hash_1.hashObjectIgnoreKeyOrder)([name, payload]);
|
|
105
|
+
if (server.activeObservablesById.has(id)) {
|
|
106
|
+
const obs = server.activeObservablesById.get(id);
|
|
107
|
+
if (obs.beingDestroyed) {
|
|
108
|
+
clearTimeout(obs.beingDestroyed);
|
|
109
|
+
obs.beingDestroyed = null;
|
|
110
|
+
}
|
|
111
|
+
if (obs.cache) {
|
|
112
|
+
sendGetResponse(server, id, obs, checksum, client);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
if (!obs.onNextData) {
|
|
116
|
+
obs.onNextData = new Set();
|
|
117
|
+
}
|
|
118
|
+
obs.onNextData.add(() => {
|
|
119
|
+
sendGetResponse(server, id, obs, checksum, client);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const obs = (0, observable_1.create)(server, name, id, payload);
|
|
125
|
+
if (!obs.onNextData) {
|
|
126
|
+
obs.onNextData = new Set();
|
|
127
|
+
}
|
|
128
|
+
obs.onNextData.add(() => {
|
|
129
|
+
sendGetResponse(server, id, obs, checksum, client);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if (spec && (0, functions_1.isObservableFunctionSpec)(spec)) {
|
|
134
|
+
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.FunctionIsNotObservable, { name });
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
(0, send_1.sendHttpError)(client, error_1.BasedErrorCode.FunctionNotFound, { name });
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
.catch(() => (0, send_1.sendHttpError)(client, error_1.BasedErrorCode.FunctionNotFound, { name }));
|
|
141
|
+
};
|
|
142
|
+
exports.httpGet = httpGet;
|
|
143
|
+
//# sourceMappingURL=get.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../../src/network/http/get.ts"],"names":[],"mappings":";;;;;;AAAA,+CAA0D;AAG1D,gDAAuB;AACvB,yCAAqC;AACrC,iCAAsC;AACtC,sCAAsD;AACtD,iDAAkD;AAClD,0DAA4B;AAC5B,uCAA4C;AAE5C,MAAM,eAAe,GAAG,CACtB,MAAmB,EACnB,EAAU,EACV,GAAqB,EACrB,QAAgB,EAChB,MAAkB,EAClB,EAAE;IACF,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;QACf,OAAM;KACP;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAA;IAEhD,IAAI;QACF,IAAI,QAAQ,KAAK,CAAC,IAAI,QAAQ,KAAK,GAAG,CAAC,QAAQ,EAAE;YAC/C,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE;gBACd,IAAA,oBAAa,EAAC,MAAM,EAAE,sBAAc,CAAC,yBAAyB,EAAE;oBAC9D,YAAY,EAAE,EAAE;oBAChB,IAAI,EAAE,GAAG,CAAC,IAAI;iBACf,CAAC,CAAA;aACH;iBAAM;gBACL,IAAI,GAAG,CAAC,SAAS,EAAE;oBACjB,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAA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