@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.
Files changed (168) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/handlers/removeField/index.js +1 -0
  3. package/dist/handlers/removeField/index.js.map +1 -1
  4. package/dist/secrets.js +6 -3
  5. package/dist/secrets.js.map +1 -1
  6. package/package.json +1 -1
  7. package/dist/auth/authorize.d.ts +0 -2
  8. package/dist/auth/authorize.js +0 -8
  9. package/dist/auth/authorize.js.map +0 -1
  10. package/dist/auth/authorizeAdvanced.d.ts +0 -2
  11. package/dist/auth/authorizeAdvanced.js +0 -10
  12. package/dist/auth/authorizeAdvanced.js.map +0 -1
  13. package/dist/auth/defaults/authorize.d.ts +0 -2
  14. package/dist/auth/defaults/authorize.js +0 -8
  15. package/dist/auth/defaults/authorize.js.map +0 -1
  16. package/dist/auth/defaults/authorizeAdvanced.d.ts +0 -2
  17. package/dist/auth/defaults/authorizeAdvanced.js +0 -8
  18. package/dist/auth/defaults/authorizeAdvanced.js.map +0 -1
  19. package/dist/auth/defaults/index.d.ts +0 -2
  20. package/dist/auth/defaults/index.js +0 -19
  21. package/dist/auth/defaults/index.js.map +0 -1
  22. package/dist/auth/index.d.ts +0 -10
  23. package/dist/auth/index.js +0 -23
  24. package/dist/auth/index.js.map +0 -1
  25. package/dist/error.d.ts +0 -34
  26. package/dist/error.js +0 -107
  27. package/dist/error.js.map +0 -1
  28. package/dist/functions/index.d.ts +0 -31
  29. package/dist/functions/index.js +0 -200
  30. package/dist/functions/index.js.map +0 -1
  31. package/dist/functions/timeout.d.ts +0 -3
  32. package/dist/functions/timeout.js +0 -23
  33. package/dist/functions/timeout.js.map +0 -1
  34. package/dist/network/http/authorize.d.ts +0 -3
  35. package/dist/network/http/authorize.js +0 -30
  36. package/dist/network/http/authorize.js.map +0 -1
  37. package/dist/network/http/compress.d.ts +0 -6
  38. package/dist/network/http/compress.js +0 -47
  39. package/dist/network/http/compress.js.map +0 -1
  40. package/dist/network/http/end.d.ts +0 -4
  41. package/dist/network/http/end.js +0 -19
  42. package/dist/network/http/end.js.map +0 -1
  43. package/dist/network/http/function/index.d.ts +0 -3
  44. package/dist/network/http/function/index.js +0 -82
  45. package/dist/network/http/function/index.js.map +0 -1
  46. package/dist/network/http/function/stream/DataStream.d.ts +0 -7
  47. package/dist/network/http/function/stream/DataStream.js +0 -17
  48. package/dist/network/http/function/stream/DataStream.js.map +0 -1
  49. package/dist/network/http/function/stream/index.d.ts +0 -8
  50. package/dist/network/http/function/stream/index.js +0 -93
  51. package/dist/network/http/function/stream/index.js.map +0 -1
  52. package/dist/network/http/function/stream/multipartFormStream.d.ts +0 -0
  53. package/dist/network/http/function/stream/multipartFormStream.js +0 -194
  54. package/dist/network/http/function/stream/multipartFormStream.js.map +0 -1
  55. package/dist/network/http/function/stream/stream.d.ts +0 -4
  56. package/dist/network/http/function/stream/stream.js +0 -49
  57. package/dist/network/http/function/stream/stream.js.map +0 -1
  58. package/dist/network/http/function.d.ts +0 -3
  59. package/dist/network/http/function.js +0 -46
  60. package/dist/network/http/function.js.map +0 -1
  61. package/dist/network/http/get.d.ts +0 -3
  62. package/dist/network/http/get.js +0 -143
  63. package/dist/network/http/get.js.map +0 -1
  64. package/dist/network/http/index.d.ts +0 -3
  65. package/dist/network/http/index.js +0 -125
  66. package/dist/network/http/index.js.map +0 -1
  67. package/dist/network/http/readBody.d.ts +0 -2
  68. package/dist/network/http/readBody.js +0 -134
  69. package/dist/network/http/readBody.js.map +0 -1
  70. package/dist/network/http/readPostData.d.ts +0 -3
  71. package/dist/network/http/readPostData.js +0 -50
  72. package/dist/network/http/readPostData.js.map +0 -1
  73. package/dist/network/http/send.d.ts +0 -6
  74. package/dist/network/http/send.js +0 -65
  75. package/dist/network/http/send.js.map +0 -1
  76. package/dist/network/http/sendError.d.ts +0 -4
  77. package/dist/network/http/sendError.js +0 -27
  78. package/dist/network/http/sendError.js.map +0 -1
  79. package/dist/network/http/stream/DataStream.d.ts +0 -7
  80. package/dist/network/http/stream/DataStream.js +0 -17
  81. package/dist/network/http/stream/DataStream.js.map +0 -1
  82. package/dist/network/http/stream/formStream.d.ts +0 -4
  83. package/dist/network/http/stream/formStream.js +0 -184
  84. package/dist/network/http/stream/formStream.js.map +0 -1
  85. package/dist/network/http/stream/getExtenstion.d.ts +0 -2
  86. package/dist/network/http/stream/getExtenstion.js +0 -22
  87. package/dist/network/http/stream/getExtenstion.js.map +0 -1
  88. package/dist/network/http/stream/index.d.ts +0 -9
  89. package/dist/network/http/stream/index.js +0 -42
  90. package/dist/network/http/stream/index.js.map +0 -1
  91. package/dist/network/http/stream/multipartFormStream.d.ts +0 -0
  92. package/dist/network/http/stream/multipartFormStream.js +0 -194
  93. package/dist/network/http/stream/multipartFormStream.js.map +0 -1
  94. package/dist/network/http/stream/storeFile.d.ts +0 -5
  95. package/dist/network/http/stream/storeFile.js +0 -30
  96. package/dist/network/http/stream/storeFile.js.map +0 -1
  97. package/dist/network/http/stream/stream.d.ts +0 -4
  98. package/dist/network/http/stream/stream.js +0 -49
  99. package/dist/network/http/stream/stream.js.map +0 -1
  100. package/dist/network/http/stream/types.d.ts +0 -9
  101. package/dist/network/http/stream/types.js +0 -3
  102. package/dist/network/http/stream/types.js.map +0 -1
  103. package/dist/network/http/streamFunction/DataStream.d.ts +0 -7
  104. package/dist/network/http/streamFunction/DataStream.js +0 -17
  105. package/dist/network/http/streamFunction/DataStream.js.map +0 -1
  106. package/dist/network/http/streamFunction/endStreamRequest.d.ts +0 -3
  107. package/dist/network/http/streamFunction/endStreamRequest.js +0 -20
  108. package/dist/network/http/streamFunction/endStreamRequest.js.map +0 -1
  109. package/dist/network/http/streamFunction/getExtension.d.ts +0 -2
  110. package/dist/network/http/streamFunction/getExtension.js +0 -22
  111. package/dist/network/http/streamFunction/getExtension.js.map +0 -1
  112. package/dist/network/http/streamFunction/index.d.ts +0 -3
  113. package/dist/network/http/streamFunction/index.js +0 -71
  114. package/dist/network/http/streamFunction/index.js.map +0 -1
  115. package/dist/network/http/streamFunction/multipartFormStream.d.ts +0 -5
  116. package/dist/network/http/streamFunction/multipartFormStream.js +0 -189
  117. package/dist/network/http/streamFunction/multipartFormStream.js.map +0 -1
  118. package/dist/network/http/streamFunction/multipartStream.d.ts +0 -13
  119. package/dist/network/http/streamFunction/multipartStream.js +0 -166
  120. package/dist/network/http/streamFunction/multipartStream.js.map +0 -1
  121. package/dist/network/http/streamFunction/stream.d.ts +0 -4
  122. package/dist/network/http/streamFunction/stream.js +0 -106
  123. package/dist/network/http/streamFunction/stream.js.map +0 -1
  124. package/dist/network/index.d.ts +0 -4
  125. package/dist/network/index.js +0 -84
  126. package/dist/network/index.js.map +0 -1
  127. package/dist/network/message/auth.d.ts +0 -4
  128. package/dist/network/message/auth.js +0 -35
  129. package/dist/network/message/auth.js.map +0 -1
  130. package/dist/network/message/function.d.ts +0 -3
  131. package/dist/network/message/function.js +0 -70
  132. package/dist/network/message/function.js.map +0 -1
  133. package/dist/network/message/get.d.ts +0 -3
  134. package/dist/network/message/get.js +0 -111
  135. package/dist/network/message/get.js.map +0 -1
  136. package/dist/network/message/index.d.ts +0 -3
  137. package/dist/network/message/index.js +0 -61
  138. package/dist/network/message/index.js.map +0 -1
  139. package/dist/network/message/observable.d.ts +0 -5
  140. package/dist/network/message/observable.js +0 -105
  141. package/dist/network/message/observable.js.map +0 -1
  142. package/dist/network/message/send.d.ts +0 -3
  143. package/dist/network/message/send.js +0 -11
  144. package/dist/network/message/send.js.map +0 -1
  145. package/dist/network/rest/function.d.ts +0 -3
  146. package/dist/network/rest/function.js +0 -85
  147. package/dist/network/rest/function.js.map +0 -1
  148. package/dist/network/rest/index.d.ts +0 -3
  149. package/dist/network/rest/index.js +0 -65
  150. package/dist/network/rest/index.js.map +0 -1
  151. package/dist/network/upgrade.d.ts +0 -4
  152. package/dist/network/upgrade.js +0 -48
  153. package/dist/network/upgrade.js.map +0 -1
  154. package/dist/observable/index.d.ts +0 -8
  155. package/dist/observable/index.js +0 -224
  156. package/dist/observable/index.js.map +0 -1
  157. package/dist/protocol.d.ts +0 -18
  158. package/dist/protocol.js +0 -206
  159. package/dist/protocol.js.map +0 -1
  160. package/dist/server.d.ts +0 -28
  161. package/dist/server.js +0 -96
  162. package/dist/server.js.map +0 -1
  163. package/dist/workers/index.d.ts +0 -0
  164. package/dist/workers/index.js +0 -20
  165. package/dist/workers/index.js.map +0 -1
  166. package/dist/workers/workerCode.d.ts +0 -12
  167. package/dist/workers/workerCode.js +0 -46
  168. package/dist/workers/workerCode.js.map +0 -1
@@ -1,27 +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.sendErrorRaw = exports.sendError = void 0;
7
- const end_1 = __importDefault(require("./end"));
8
- const sendError = (client, error, code = 400, status = 'Bad Request') => {
9
- if (!client.res) {
10
- return;
11
- }
12
- client.res.writeStatus(`${code} ${status}`);
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, JSON.stringify({ error, code }));
17
- };
18
- exports.sendError = sendError;
19
- const sendErrorRaw = (res, error, code = 400, status = 'Bad Request') => {
20
- res.writeStatus(`${code} ${status}`);
21
- res.writeHeader('Access-Control-Allow-Origin', '*');
22
- res.writeHeader('Access-Control-Allow-Headers', 'content-type');
23
- res.writeHeader('Content-Type', 'application/json');
24
- res.end(JSON.stringify({ error, code }));
25
- };
26
- exports.sendErrorRaw = sendErrorRaw;
27
- //# sourceMappingURL=sendError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sendError.js","sourceRoot":"","sources":["../../../src/network/http/sendError.ts"],"names":[],"mappings":";;;;;;AAEA,gDAAuB;AAEhB,MAAM,SAAS,GAAG,CACvB,MAAkB,EAClB,KAAU,EACV,OAAe,GAAG,EAClB,SAAiB,aAAa,EAC9B,EAAE;IACF,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;QACf,OAAM;KACP;IACD,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,IAAI,IAAI,MAAM,EAAE,CAAC,CAAA;IAC3C,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;IAC1D,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,8BAA8B,EAAE,cAAc,CAAC,CAAA;IACtE,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAA;IAC1D,IAAA,aAAG,EAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AAC9C,CAAC,CAAA;AAdY,QAAA,SAAS,aAcrB;AAEM,MAAM,YAAY,GAAG,CAC1B,GAAqB,EACrB,KAAU,EACV,OAAe,GAAG,EAClB,SAAiB,aAAa,EAC9B,EAAE;IACF,GAAG,CAAC,WAAW,CAAC,GAAG,IAAI,IAAI,MAAM,EAAE,CAAC,CAAA;IACpC,GAAG,CAAC,WAAW,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;IACnD,GAAG,CAAC,WAAW,CAAC,8BAA8B,EAAE,cAAc,CAAC,CAAA;IAC/D,GAAG,CAAC,WAAW,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAA;IACnD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AAC1C,CAAC,CAAA;AAXY,QAAA,YAAY,gBAWxB"}
@@ -1,7 +0,0 @@
1
- /// <reference types="node" />
2
- import { Duplex } from 'stream';
3
- export declare class DataStream extends Duplex {
4
- _read(): void;
5
- _write(chunk: any, encoding: any, callback: any): void;
6
- _final(): void;
7
- }
@@ -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/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,4 +0,0 @@
1
- import uws from '@based/uws';
2
- import { BasedServer } from '../../..';
3
- declare const _default: (server: BasedServer, res: uws.HttpResponse) => Promise<void>;
4
- export default _default;
@@ -1,184 +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
- const DataStream_1 = require("./DataStream");
7
- const storeFile_1 = __importDefault(require("./storeFile"));
8
- const getExtenstion_1 = __importDefault(require("./getExtenstion"));
9
- const isCompleteOpts = (options) => {
10
- return !!(options.id && options.size && options.type && options.extension);
11
- };
12
- const setHeader = (server, file, res) => {
13
- file.headersSet++;
14
- if (file.headersSet === 2) {
15
- const opts = file.opts;
16
- if (isCompleteOpts(opts)) {
17
- if (opts.size < 200000) {
18
- file.stream.on('end', () => {
19
- const payload = {
20
- $id: opts.id,
21
- progress: 1,
22
- size: opts.size,
23
- };
24
- if (opts.name) {
25
- payload.name = opts.name;
26
- }
27
- server.based.set(payload);
28
- });
29
- }
30
- else {
31
- let progress = 0;
32
- let total = 0;
33
- let setInProgress = false;
34
- const payload = {
35
- $id: opts.id,
36
- progress: 0,
37
- size: opts.size,
38
- };
39
- if (opts.name) {
40
- payload.name = opts.name;
41
- }
42
- server.based.set(payload);
43
- const updateProgress = () => {
44
- if (!setInProgress) {
45
- setInProgress = true;
46
- setTimeout(() => {
47
- const payload = {
48
- $id: opts.id,
49
- progress,
50
- };
51
- server.based.set(payload);
52
- setInProgress = false;
53
- }, 250);
54
- }
55
- };
56
- file.stream.on('end', () => {
57
- progress = 1;
58
- updateProgress();
59
- });
60
- file.stream.on('data', (chunk) => {
61
- total += chunk.byteLength;
62
- progress = total / opts.size;
63
- updateProgress();
64
- });
65
- }
66
- (0, storeFile_1.default)(server, file.stream, opts);
67
- }
68
- else {
69
- invalidFile(res);
70
- return null;
71
- }
72
- return true;
73
- }
74
- return false;
75
- };
76
- const invalidFile = (res) => {
77
- console.info('Invalid file');
78
- res.aborted = true;
79
- res.writeStatus('400 Invalid Request').end('{"error":"invalid file}');
80
- };
81
- const toBuffer = (str, firstWritten) => {
82
- return Buffer.from(firstWritten ? str + '\r\n' : str, 'binary');
83
- };
84
- exports.default = async (server, res) => {
85
- const files = [];
86
- let boundary = null;
87
- let prevLine;
88
- let isWriting = false;
89
- res.onData((chunk, isLast) => {
90
- let firstWritten = false;
91
- const blocks = Buffer.from(chunk).toString('binary').split('\r\n');
92
- if (!boundary) {
93
- boundary = blocks[0];
94
- }
95
- for (let i = 0; i < blocks.length; i++) {
96
- const line = blocks[i];
97
- if (!boundary) {
98
- continue;
99
- }
100
- if (isWriting && (line === boundary || line === boundary + '--')) {
101
- isWriting = false;
102
- const file = files[files.length - 1];
103
- if (prevLine) {
104
- file.stream.end(toBuffer(prevLine, firstWritten));
105
- }
106
- else {
107
- file.stream.end();
108
- }
109
- prevLine = null;
110
- if (line === boundary + '--') {
111
- continue;
112
- }
113
- }
114
- if (line === boundary && !isWriting) {
115
- const file = {
116
- stream: new DataStream_1.DataStream(),
117
- headersSet: 0,
118
- opts: {},
119
- };
120
- files.push(file);
121
- // try {
122
- // fs.unlinkSync('/Users/jim/Desktop/yes.png')
123
- // } catch (err) {}
124
- // file.stream.pipe(fs.createWriteStream('/Users/jim/Desktop/yes.png'))
125
- continue;
126
- }
127
- const file = files[files.length - 1];
128
- if (!file) {
129
- return invalidFile(res);
130
- }
131
- if (!isWriting && line.includes('Content-Disposition')) {
132
- const meta = line.match(/name="(.*?)"/)?.[1];
133
- if (!meta) {
134
- return invalidFile(res);
135
- }
136
- const [functionName, raw, id, size, ...name] = meta.split('|');
137
- const opts = file.opts;
138
- opts.id = id;
139
- if (raw) {
140
- opts.raw = true;
141
- }
142
- if (name && name.length) {
143
- opts.name = name.join('|');
144
- }
145
- else {
146
- opts.name = line.match(/filename="(.*?)"/)?.[1] || 'untitled';
147
- }
148
- if (functionName) {
149
- opts.functionName = functionName;
150
- }
151
- opts.size = Number(size);
152
- isWriting = setHeader(server, file, res);
153
- if (isWriting === null) {
154
- return;
155
- }
156
- continue;
157
- }
158
- if (!isWriting && line.includes('Content-Type')) {
159
- const mimeType = line.match(/Content-Type: ([a-zA-Z0-9].+\/[a-zA-Z0-9].+)/)?.[1];
160
- if (!mimeType) {
161
- return invalidFile(res);
162
- }
163
- file.opts.type = mimeType;
164
- file.opts.extension = (0, getExtenstion_1.default)(mimeType);
165
- isWriting = setHeader(server, file, res);
166
- if (isWriting === null) {
167
- return;
168
- }
169
- continue;
170
- }
171
- if (isWriting) {
172
- if (prevLine) {
173
- file.stream.write(toBuffer(prevLine, firstWritten));
174
- }
175
- prevLine = line;
176
- firstWritten = true;
177
- }
178
- }
179
- if (isLast) {
180
- res.end('{}');
181
- }
182
- });
183
- };
184
- //# sourceMappingURL=formStream.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formStream.js","sourceRoot":"","sources":["../../../../src/network/http/stream/formStream.ts"],"names":[],"mappings":";;;;;AAAA,6CAAyC;AACzC,4DAAmC;AAInC,oEAA2C;AAS3C,MAAM,cAAc,GAAG,CACrB,OAA6B,EACL,EAAE;IAC1B,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,SAAS,CAAC,CAAA;AAC5E,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,CAChB,MAAmB,EACnB,IAAoB,EACpB,GAAqB,EACZ,EAAE;IACX,IAAI,CAAC,UAAU,EAAE,CAAA;IACjB,IAAI,IAAI,CAAC,UAAU,KAAK,CAAC,EAAE;QACzB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACtB,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE;YACxB,IAAI,IAAI,CAAC,IAAI,GAAG,MAAM,EAAE;gBACtB,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;oBACzB,MAAM,OAAO,GAAQ;wBACnB,GAAG,EAAE,IAAI,CAAC,EAAE;wBACZ,QAAQ,EAAE,CAAC;wBACX,IAAI,EAAE,IAAI,CAAC,IAAI;qBAChB,CAAA;oBACD,IAAI,IAAI,CAAC,IAAI,EAAE;wBACb,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;qBACzB;oBACD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;gBAC3B,CAAC,CAAC,CAAA;aACH;iBAAM;gBACL,IAAI,QAAQ,GAAG,CAAC,CAAA;gBAChB,IAAI,KAAK,GAAG,CAAC,CAAA;gBACb,IAAI,aAAa,GAAG,KAAK,CAAA;gBACzB,MAAM,OAAO,GAAQ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AA;gBACxC,IAAI,SAAS,KAAK,IAAI,EAAE;oBACtB,OAAM;iBACP;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,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;SACd;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- declare const _default: (mimeType: string) => any;
2
- export default _default;
@@ -1,22 +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
- 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=getExtenstion.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getExtenstion.js","sourceRoot":"","sources":["../../../../src/network/http/stream/getExtenstion.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"}
@@ -1,9 +0,0 @@
1
- import uws from '@based/uws';
2
- import { BasedServer } from '../../..';
3
- export declare const invalidReqNoCors: (res: uws.HttpResponse) => void;
4
- export declare type StreamOptions = {
5
- type: string;
6
- size: number;
7
- };
8
- declare const _default: (server: BasedServer, name: string, req: uws.HttpRequest, res: uws.HttpResponse) => Promise<void>;
9
- export default _default;
@@ -1,42 +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.invalidReqNoCors = void 0;
7
- const stream_1 = __importDefault(require("./stream"));
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
- exports.default = async (server, name, req, res) => {
16
- const method = req.getMethod();
17
- if (method !== 'post') {
18
- console.info('options or get');
19
- res.end('');
20
- return;
21
- }
22
- const type = req.getHeader('content-type');
23
- if (type === 'multipart/form-data') {
24
- // formStream(server, res)
25
- return;
26
- }
27
- const size = Number(req.getHeader('content-length'));
28
- if (!type) {
29
- (0, exports.invalidReqNoCors)(res);
30
- return;
31
- }
32
- const opts = {
33
- size,
34
- type,
35
- };
36
- if (!opts.size) {
37
- (0, exports.invalidReqNoCors)(res);
38
- return;
39
- }
40
- (0, stream_1.default)(res, size);
41
- };
42
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/network/http/stream/index.ts"],"names":[],"mappings":";;;;;;AAEA,sDAA6B;AAEtB,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,kBAAe,KAAK,EAClB,MAAmB,EACnB,IAAY,EACZ,GAAoB,EACpB,GAAqB,EACrB,EAAE;IACF,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,EAAE,CAAA;IAE9B,IAAI,MAAM,KAAK,MAAM,EAAE;QACrB,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;QAC9B,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACX,OAAM;KACP;IAED,MAAM,IAAI,GAAG,GAAG,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;IAE1C,IAAI,IAAI,KAAK,qBAAqB,EAAE;QAClC,0BAA0B;QAC1B,OAAM;KACP;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,CAAA;IAEpD,IAAI,CAAC,IAAI,EAAE;QACT,IAAA,wBAAgB,EAAC,GAAG,CAAC,CAAA;QACrB,OAAM;KACP;IAED,MAAM,IAAI,GAAkB;QAC1B,IAAI;QACJ,IAAI;KACL,CAAA;IAED,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;QACd,IAAA,wBAAgB,EAAC,GAAG,CAAC,CAAA;QACrB,OAAM;KACP;IAED,IAAA,gBAAM,EAAC,GAAG,EAAE,IAAI,CAAC,CAAA;AACnB,CAAC,CAAA"}
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/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;AACx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AAsB;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,5 +0,0 @@
1
- import { Readable } from 'stream';
2
- import { BasedServer } from '../../..';
3
- import { FileOptions } from './types';
4
- declare const _default: (server: BasedServer, stream: Readable, opts: FileOptions) => Promise<void>;
5
- export default _default;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = async (server, stream, opts) => {
4
- const storeFile = server.config.storeFile;
5
- if (!storeFile) {
6
- throw new Error('No file upload handler available!');
7
- }
8
- const result = await storeFile({
9
- based: server.based,
10
- stream,
11
- id: opts.id,
12
- mimeType: opts.type,
13
- extension: opts.extension,
14
- size: opts.size,
15
- });
16
- // thumb
17
- const setObj = {
18
- $id: opts.id,
19
- src: result.src,
20
- origin: result.origin,
21
- version: result.version,
22
- mimeType: result.mimeType || opts.type,
23
- };
24
- if (result.thumb) {
25
- setObj.thumb = result.thumb;
26
- }
27
- // add version
28
- server.based.set(setObj);
29
- };
30
- //# sourceMappingURL=storeFile.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storeFile.js","sourceRoot":"","sources":["../../../../src/network/http/stream/storeFile.ts"],"names":[],"mappings":";;AAIA,kBAAe,KAAK,EAClB,MAAmB,EACnB,MAAgB,EAChB,IAAiB,EACF,EAAE;IACjB,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAA;IAEzC,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;KACrD;IAED,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC;QAC7B,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,MAAM;QACN,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,QAAQ,EAAE,IAAI,CAAC,IAAI;QACnB,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC,CAAA;IAEF,QAAQ;IAER,MAAM,MAAM,GAAQ;QAClB,GAAG,EAAE,IAAI,CAAC,EAAE;QACZ,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI;KACvC,CAAA;IAED,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAA;KAC5B;IAED,cAAc;IACd,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AAC1B,CAAC,CAAA"}
@@ -1,4 +0,0 @@
1
- import { DataStream } from './DataStream';
2
- import uws from '@based/uws';
3
- declare const _default: (res: uws.HttpResponse, size: number) => Promise<DataStream>;
4
- export default _default;
@@ -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