@maiyunnet/kebab 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/.VSCodeCounter/2025-02-14_14-46-44/details.md +82 -0
  2. package/.VSCodeCounter/2025-02-14_14-46-44/diff-details.md +15 -0
  3. package/.VSCodeCounter/2025-02-14_14-46-44/diff.csv +2 -0
  4. package/.VSCodeCounter/2025-02-14_14-46-44/diff.md +19 -0
  5. package/.VSCodeCounter/2025-02-14_14-46-44/diff.txt +22 -0
  6. package/.VSCodeCounter/2025-02-14_14-46-44/results.csv +69 -0
  7. package/.VSCodeCounter/2025-02-14_14-46-44/results.json +1 -0
  8. package/.VSCodeCounter/2025-02-14_14-46-44/results.md +48 -0
  9. package/.VSCodeCounter/2025-02-14_14-46-44/results.txt +118 -0
  10. package/.vscode/tasks.json +15 -0
  11. package/LICENSE +201 -0
  12. package/README.md +201 -0
  13. package/bin/kebab.js +2 -0
  14. package/eslint.config.js +22 -0
  15. package/index.js +19 -0
  16. package/index.ts +33 -0
  17. package/lib/buffer.js +108 -0
  18. package/lib/buffer.ts +152 -0
  19. package/lib/captcha/zcool-addict-italic.ttf +0 -0
  20. package/lib/captcha.js +71 -0
  21. package/lib/captcha.ts +63 -0
  22. package/lib/consistent.js +171 -0
  23. package/lib/consistent.ts +219 -0
  24. package/lib/core.js +663 -0
  25. package/lib/core.ts +880 -0
  26. package/lib/crypto.js +256 -0
  27. package/lib/crypto.ts +384 -0
  28. package/lib/db.js +521 -0
  29. package/lib/db.ts +719 -0
  30. package/lib/dns.js +321 -0
  31. package/lib/dns.ts +405 -0
  32. package/lib/fs.js +405 -0
  33. package/lib/fs.ts +527 -0
  34. package/lib/jwt.js +223 -0
  35. package/lib/jwt.ts +276 -0
  36. package/lib/kv.js +1004 -0
  37. package/lib/kv.ts +1489 -0
  38. package/lib/lan.js +99 -0
  39. package/lib/lan.ts +87 -0
  40. package/lib/net/cacert.pem +3480 -0
  41. package/lib/net/formdata.js +137 -0
  42. package/lib/net/formdata.ts +166 -0
  43. package/lib/net/request.js +102 -0
  44. package/lib/net/request.ts +150 -0
  45. package/lib/net/response.js +28 -0
  46. package/lib/net/response.ts +59 -0
  47. package/lib/net.js +462 -0
  48. package/lib/net.ts +662 -0
  49. package/lib/s3.js +180 -0
  50. package/lib/s3.ts +235 -0
  51. package/lib/scan.js +276 -0
  52. package/lib/scan.ts +364 -0
  53. package/lib/session.js +177 -0
  54. package/lib/session.ts +230 -0
  55. package/lib/sql.js +818 -0
  56. package/lib/sql.ts +1151 -0
  57. package/lib/ssh/sftp.js +373 -0
  58. package/lib/ssh/sftp.ts +508 -0
  59. package/lib/ssh/shell.js +109 -0
  60. package/lib/ssh/shell.ts +123 -0
  61. package/lib/ssh.js +171 -0
  62. package/lib/ssh.ts +191 -0
  63. package/lib/text/tld.json +1 -0
  64. package/lib/text.js +452 -0
  65. package/lib/text.ts +607 -0
  66. package/lib/time.js +216 -0
  67. package/lib/time.ts +254 -0
  68. package/lib/ws.js +373 -0
  69. package/lib/ws.ts +523 -0
  70. package/lib/zip.js +381 -0
  71. package/lib/zip.ts +447 -0
  72. package/lib/zlib.js +289 -0
  73. package/lib/zlib.ts +350 -0
  74. package/main.js +51 -0
  75. package/main.ts +27 -0
  76. package/package.json +37 -0
  77. package/sys/child.js +585 -0
  78. package/sys/child.ts +678 -0
  79. package/sys/cmd.js +226 -0
  80. package/sys/cmd.ts +225 -0
  81. package/sys/ctr.js +608 -0
  82. package/sys/ctr.ts +904 -0
  83. package/sys/master.js +314 -0
  84. package/sys/master.ts +355 -0
  85. package/sys/mod.js +1273 -0
  86. package/sys/mod.ts +1871 -0
  87. package/sys/route.js +922 -0
  88. package/sys/route.ts +1113 -0
  89. package/types/index.d.ts +283 -0
  90. package/www/example/ctr/main.js +42 -0
  91. package/www/example/ctr/main.ts +9 -0
  92. package/www/example/ctr/middle.js +57 -0
  93. package/www/example/ctr/middle.ts +26 -0
  94. package/www/example/ctr/test.js +2818 -0
  95. package/www/example/ctr/test.ts +3218 -0
  96. package/www/example/data/locale/en.test.json +8 -0
  97. package/www/example/data/locale/index.html +1 -0
  98. package/www/example/data/locale/ja.test.json +8 -0
  99. package/www/example/data/locale/sc.test.json +8 -0
  100. package/www/example/data/locale/tc.test.json +8 -0
  101. package/www/example/data/test.zip +0 -0
  102. package/www/example/kebab.json +24 -0
  103. package/www/example/mod/test.js +49 -0
  104. package/www/example/mod/test.ts +47 -0
  105. package/www/example/mod/testdata.js +11 -0
  106. package/www/example/mod/testdata.ts +30 -0
  107. package/www/example/route.json +6 -0
  108. package/www/example/view/test.ejs +11 -0
  109. package/www/example/ws/mproxy.js +49 -0
  110. package/www/example/ws/mproxy.ts +16 -0
  111. package/www/example/ws/rproxy.js +47 -0
  112. package/www/example/ws/rproxy.ts +14 -0
  113. package/www/example/ws/test.js +68 -0
  114. package/www/example/ws/test.ts +36 -0
package/sys/ctr.js ADDED
@@ -0,0 +1,608 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Ctr = void 0;
37
+ exports.clearLocaleData = clearLocaleData;
38
+ const ejs = __importStar(require("ejs"));
39
+ const lCore = __importStar(require("../lib/core"));
40
+ const fs = __importStar(require("../lib/fs"));
41
+ const crypto = __importStar(require("../lib/crypto"));
42
+ const session = __importStar(require("../lib/session"));
43
+ const text = __importStar(require("../lib/text"));
44
+ const sRoute = __importStar(require("../sys/route"));
45
+ let loadedData = {};
46
+ let localeFiles = [];
47
+ let localeData = {};
48
+ function clearLocaleData() {
49
+ loadedData = {};
50
+ localeFiles = [];
51
+ localeData = {};
52
+ }
53
+ class Ctr {
54
+ constructor(config, req, res) {
55
+ this._param = [];
56
+ this._action = '';
57
+ this._headers = {};
58
+ this._rawPost = {};
59
+ this._post = {};
60
+ this._input = '';
61
+ this._files = {};
62
+ this._cookie = {};
63
+ this._jwt = {};
64
+ this._session = {};
65
+ this._sess = null;
66
+ this._xsrf = '';
67
+ this._httpCode = 0;
68
+ this._locale = 'en';
69
+ this._localeFiles = [];
70
+ this._localeData = {};
71
+ this._waitInfo = {
72
+ 'asyncTask': {
73
+ 'count': 0,
74
+ 'resolve': () => {
75
+ },
76
+ 'callback': function () {
77
+ return new Promise((resolve) => {
78
+ this.resolve = resolve;
79
+ });
80
+ }
81
+ },
82
+ 'transaction': 0
83
+ };
84
+ this._authorization = null;
85
+ this._config = config;
86
+ this._req = req;
87
+ if (res) {
88
+ this._res = res;
89
+ }
90
+ this._cacheTTL = config.set.cacheTtl;
91
+ }
92
+ get isAvail() {
93
+ return this._req.socket.writable;
94
+ }
95
+ get timeout() {
96
+ return this._timer?.timeout ?? 30_000;
97
+ }
98
+ set timeout(num) {
99
+ if (!this._timer) {
100
+ return;
101
+ }
102
+ this._timer.timeout = num;
103
+ clearTimeout(this._timer.timer);
104
+ this._timer.timer = setTimeout(this._timer.callback, num);
105
+ }
106
+ _asyncTask(func) {
107
+ ++this._waitInfo.asyncTask.count;
108
+ setTimeout(() => {
109
+ (async () => {
110
+ await func();
111
+ --this._waitInfo.asyncTask.count;
112
+ if (!this._waitInfo.asyncTask.count) {
113
+ this._waitInfo.asyncTask.resolve();
114
+ }
115
+ })().catch(async (e) => {
116
+ lCore.display('[ERROR][CTR][ASYNCTASK]', e);
117
+ await lCore.log(this, '(ctr.asyncTask)' + text.stringifyJson(e.stack).slice(1, -1), '-error');
118
+ --this._waitInfo.asyncTask.count;
119
+ if (!this._waitInfo.asyncTask.count) {
120
+ this._waitInfo.asyncTask.resolve();
121
+ }
122
+ });
123
+ }, 0);
124
+ }
125
+ getPrototype(name) {
126
+ return this[name];
127
+ }
128
+ setPrototype(name, val) {
129
+ this[name] = val;
130
+ }
131
+ onLoad() {
132
+ return true;
133
+ }
134
+ onUnload(rtn) {
135
+ return rtn;
136
+ }
137
+ onUpgrade() {
138
+ return {};
139
+ }
140
+ onData() {
141
+ return '';
142
+ }
143
+ onMessage() {
144
+ return;
145
+ }
146
+ onDrain() {
147
+ return;
148
+ }
149
+ onClose() {
150
+ return;
151
+ }
152
+ _getRunTime(ms = false) {
153
+ const t = process.hrtime.bigint() - this._config.const.startTime;
154
+ return ms ? Number(t) / 1000000 : Number(t) / 1000000000;
155
+ }
156
+ _getMemoryUsage() {
157
+ return process.memoryUsage().rss - this._config.const.startMemory;
158
+ }
159
+ async _loadView(path, data = {}) {
160
+ const content = await fs.getContent(this._config.const.viewPath + path + '.ejs', 'utf8');
161
+ if (!content) {
162
+ return '';
163
+ }
164
+ data._urlBase = this._config.const.urlBase;
165
+ data._urlFull = this._config.const.urlFull;
166
+ data._urlStcFill = this._config.const.urlStcFull;
167
+ data._staticVer = this._config.set.staticVer;
168
+ data._staticPath = this._config.set.staticPath;
169
+ data._staticPathFull = this._config.set.staticPathFull;
170
+ data.l = (key, data) => {
171
+ return this._l(key, data);
172
+ };
173
+ return lCore.purify(ejs.render(content, data));
174
+ }
175
+ _checkInput(input, rule, rtn) {
176
+ for (const key in rule) {
177
+ const val = rule[key];
178
+ if (input[key] === undefined) {
179
+ input[key] = null;
180
+ }
181
+ const c = val.length;
182
+ if (c === 0) {
183
+ continue;
184
+ }
185
+ const lastK = c - 1;
186
+ if ((val[lastK][0] === undefined) || (val[lastK][1] === undefined) || !Number.isInteger(val[lastK][0]) || (typeof val[lastK][1] !== 'string')) {
187
+ rtn[0] = 0;
188
+ rtn[1] = 'Param error(' + key + ')';
189
+ return false;
190
+ }
191
+ for (let k = 0; k < lastK; ++k) {
192
+ const v = val[k] ?? '';
193
+ if (Array.isArray(v)) {
194
+ if (v.length === 0) {
195
+ rtn[0] = val[lastK][0];
196
+ rtn[1] = val[lastK][1];
197
+ if (val[lastK][2]) {
198
+ rtn[2] = val[lastK][2];
199
+ }
200
+ return false;
201
+ }
202
+ if (input[key] === null) {
203
+ input[key] = v[0];
204
+ }
205
+ else if (!v.includes(input[key])) {
206
+ rtn[0] = val[lastK][0];
207
+ rtn[1] = val[lastK][1];
208
+ if (val[lastK][2]) {
209
+ rtn[2] = val[lastK][2];
210
+ }
211
+ return false;
212
+ }
213
+ }
214
+ else if (v instanceof RegExp) {
215
+ if (input[key] !== null && !v.test(input[key])) {
216
+ rtn[0] = val[lastK][0];
217
+ rtn[1] = val[lastK][1];
218
+ if (val[lastK][2]) {
219
+ rtn[2] = val[lastK][2];
220
+ }
221
+ return false;
222
+ }
223
+ }
224
+ else if (typeof v === 'object' && v.type !== undefined) {
225
+ if (input[key] !== null) {
226
+ const r = lCore.checkType(input[key], v.type);
227
+ if (r) {
228
+ rtn[0] = val[lastK][0];
229
+ rtn[1] = typeof val[lastK][1] === 'string' ? val[lastK][1] + '(' + r + ')' : val[lastK][1];
230
+ if (val[lastK][2]) {
231
+ rtn[2] = val[lastK][2];
232
+ }
233
+ return false;
234
+ }
235
+ }
236
+ }
237
+ else {
238
+ switch (v) {
239
+ case 'require': {
240
+ if ((input[key] === null) || (input[key] === '')) {
241
+ rtn[0] = val[lastK][0];
242
+ rtn[1] = val[lastK][1];
243
+ if (val[lastK][2]) {
244
+ rtn[2] = val[lastK][2];
245
+ }
246
+ return false;
247
+ }
248
+ break;
249
+ }
250
+ case 'int':
251
+ case 'integer': {
252
+ if (input[key] && (typeof input[key] !== 'number') && !Number.isSafeInteger(input[key])) {
253
+ rtn[0] = val[lastK][0];
254
+ rtn[1] = val[lastK][1];
255
+ if (val[lastK][2]) {
256
+ rtn[2] = val[lastK][2];
257
+ }
258
+ return false;
259
+ }
260
+ break;
261
+ }
262
+ case 'float':
263
+ case 'double': {
264
+ if (input[key] && (typeof input[key] !== 'number')) {
265
+ rtn[0] = val[lastK][0];
266
+ rtn[1] = val[lastK][1];
267
+ if (val[lastK][2]) {
268
+ rtn[2] = val[lastK][2];
269
+ }
270
+ return false;
271
+ }
272
+ break;
273
+ }
274
+ case 'num':
275
+ case 'number': {
276
+ if (input[key] && (typeof input[key] !== 'number') && !/^[0-9]+\.?[0-9]*$/.test(input[key])) {
277
+ rtn[0] = val[lastK][0];
278
+ rtn[1] = val[lastK][1];
279
+ if (val[lastK][2]) {
280
+ rtn[2] = val[lastK][2];
281
+ }
282
+ return false;
283
+ }
284
+ break;
285
+ }
286
+ case 'array': {
287
+ if (input[key] !== null && !Array.isArray(input[key])) {
288
+ rtn[0] = val[lastK][0];
289
+ rtn[1] = val[lastK][1];
290
+ if (val[lastK][2]) {
291
+ rtn[2] = val[lastK][2];
292
+ }
293
+ return false;
294
+ }
295
+ break;
296
+ }
297
+ case 'bool':
298
+ case 'boolean': {
299
+ if (input[key] !== null && (typeof input[key] !== 'boolean')) {
300
+ rtn[0] = val[lastK][0];
301
+ rtn[1] = val[lastK][1];
302
+ if (val[lastK][2]) {
303
+ rtn[2] = val[lastK][2];
304
+ }
305
+ return false;
306
+ }
307
+ break;
308
+ }
309
+ case 'string': {
310
+ if (input[key] !== null && (typeof input[key] !== 'string')) {
311
+ rtn[0] = val[lastK][0];
312
+ rtn[1] = val[lastK][1];
313
+ if (val[lastK][2]) {
314
+ rtn[2] = val[lastK][2];
315
+ }
316
+ return false;
317
+ }
318
+ break;
319
+ }
320
+ default: {
321
+ let match;
322
+ if (input[key] !== null) {
323
+ if (v[0] === '/') {
324
+ if (!(new RegExp(v.slice(1, -1))).test(input[key])) {
325
+ rtn[0] = val[lastK][0];
326
+ rtn[1] = val[lastK][1];
327
+ if (val[lastK][2]) {
328
+ rtn[2] = val[lastK][2];
329
+ }
330
+ return false;
331
+ }
332
+ }
333
+ else if ((match = /^([><=]+) *([0-9]+)$/.exec(v))) {
334
+ let needReturn = false;
335
+ const inputNum = Number(input[key]);
336
+ const num = Number(match[2]);
337
+ switch (match[1]) {
338
+ case '>': {
339
+ if (inputNum <= num) {
340
+ needReturn = true;
341
+ }
342
+ break;
343
+ }
344
+ case '<': {
345
+ if (inputNum >= num) {
346
+ needReturn = true;
347
+ }
348
+ break;
349
+ }
350
+ case '>=': {
351
+ if (inputNum < num) {
352
+ needReturn = true;
353
+ }
354
+ break;
355
+ }
356
+ case '<=': {
357
+ if (inputNum > num) {
358
+ needReturn = true;
359
+ }
360
+ break;
361
+ }
362
+ case '=':
363
+ case '==':
364
+ case '===': {
365
+ if (inputNum !== num) {
366
+ needReturn = true;
367
+ }
368
+ break;
369
+ }
370
+ case '!=':
371
+ case '<>': {
372
+ if (inputNum === num) {
373
+ needReturn = true;
374
+ }
375
+ break;
376
+ }
377
+ }
378
+ if (needReturn) {
379
+ rtn[0] = val[lastK][0];
380
+ rtn[1] = val[lastK][1];
381
+ if (val[lastK][2]) {
382
+ rtn[2] = val[lastK][2];
383
+ }
384
+ return false;
385
+ }
386
+ }
387
+ else {
388
+ if (input[key] !== v) {
389
+ rtn[0] = val[lastK][0];
390
+ rtn[1] = val[lastK][1];
391
+ if (val[lastK][2]) {
392
+ rtn[2] = val[lastK][2];
393
+ }
394
+ return false;
395
+ }
396
+ }
397
+ }
398
+ }
399
+ }
400
+ }
401
+ }
402
+ }
403
+ return true;
404
+ }
405
+ _checkXInput(input, rule, rtn) {
406
+ rule['_xsrf'] ??= ['require', this._cookie['XSRF-TOKEN'], [0, 'Bad request, no permission.']];
407
+ return this._checkInput(input, rule, rtn);
408
+ }
409
+ _enabledXsrf() {
410
+ if (this._cookie['XSRF-TOKEN'] === undefined) {
411
+ const xsrf = lCore.random(16, lCore.RANDOM_LUN);
412
+ this._xsrf = xsrf;
413
+ lCore.setCookie(this, 'XSRF-TOKEN', xsrf, {
414
+ 'path': '/',
415
+ 'httponly': true
416
+ });
417
+ this._cookie['XSRF-TOKEN'] = xsrf;
418
+ }
419
+ else {
420
+ this._xsrf = this._cookie['XSRF-TOKEN'];
421
+ }
422
+ }
423
+ _getBasicAuth(user, pwd) {
424
+ return 'Basic ' + crypto.base64Encode(user + ':' + pwd);
425
+ }
426
+ _device() {
427
+ const ua = this._req.headers['user-agent']?.toLowerCase();
428
+ if (!ua) {
429
+ return 'unknown';
430
+ }
431
+ const list = ['android', 'windows', 'linux', 'macintosh', 'ipad', 'unknown'];
432
+ for (const item of list) {
433
+ if (!ua.includes(item)) {
434
+ continue;
435
+ }
436
+ return item;
437
+ }
438
+ return 'unknown';
439
+ }
440
+ getAuthorization() {
441
+ if (this._authorization !== null) {
442
+ return this._authorization;
443
+ }
444
+ let auth = '';
445
+ if (this._headers['authorization']) {
446
+ auth = this._headers['authorization'];
447
+ }
448
+ else if (this._get['_auth']) {
449
+ auth = this._get['_auth'];
450
+ }
451
+ else if (this._post['_auth']) {
452
+ auth = this._post['_auth'];
453
+ }
454
+ if (typeof auth !== 'string') {
455
+ return false;
456
+ }
457
+ let authArr = auth.split(' ');
458
+ if (authArr[1] === undefined) {
459
+ return false;
460
+ }
461
+ if (authArr[1].includes('.')) {
462
+ return authArr[1];
463
+ }
464
+ if (!(auth = crypto.base64Decode(authArr[1]))) {
465
+ return false;
466
+ }
467
+ authArr = auth.split(':');
468
+ this._authorization = { 'user': authArr[0], 'pwd': authArr[1] ?? '' };
469
+ return this._authorization;
470
+ }
471
+ async _loadData(path) {
472
+ const realPath = this._config.const.dataPath + path + '.json';
473
+ if (loadedData[realPath]) {
474
+ return loadedData[realPath];
475
+ }
476
+ const content = await fs.getContent(realPath, 'utf8');
477
+ if (!content) {
478
+ return null;
479
+ }
480
+ const json = text.parseJson(content);
481
+ loadedData[realPath] = json;
482
+ return json;
483
+ }
484
+ _location(location) {
485
+ if (this._res) {
486
+ this._res.setHeader('location', text.urlResolve(this._config.const.urlBase, location));
487
+ }
488
+ return false;
489
+ }
490
+ async _startSession(link, auth = false, opt = {}) {
491
+ this._sess = new session.Session();
492
+ await this._sess.init(this, link, auth, opt);
493
+ }
494
+ async _loadLocale(loc, pkg = 'default') {
495
+ const lName = loc + '.' + pkg;
496
+ this._locale = loc;
497
+ if (!this._localeFiles.includes(lName)) {
498
+ const lPath = this._config.const.dataPath + 'locale/' + lName;
499
+ if (!localeFiles.includes(lPath)) {
500
+ const locData = await this._loadData('locale/' + lName);
501
+ if (locData === null) {
502
+ return false;
503
+ }
504
+ this._locale = loc;
505
+ localeData[lPath] ??= {};
506
+ this._loadLocaleDeep(lPath, locData);
507
+ localeFiles.push(lPath);
508
+ }
509
+ else {
510
+ this._locale = loc;
511
+ }
512
+ this._localeData[loc] ??= {};
513
+ for (const key in localeData[lPath]) {
514
+ this._localeData[loc][key] = localeData[lPath][key];
515
+ }
516
+ this._localeFiles.push(lName);
517
+ }
518
+ else {
519
+ this._locale = loc;
520
+ }
521
+ return true;
522
+ }
523
+ _loadLocaleDeep(lPath, locData, pre = '') {
524
+ for (const k in locData) {
525
+ const v = locData[k];
526
+ if (typeof v === 'object') {
527
+ this._loadLocaleDeep(lPath, v, pre + k + '.');
528
+ }
529
+ else {
530
+ localeData[lPath][pre + k] = v;
531
+ }
532
+ }
533
+ }
534
+ _getLocaleJsonString() {
535
+ if (this._localeData[this._locale] !== undefined) {
536
+ return text.stringifyJson(this._localeData[this._locale]);
537
+ }
538
+ else {
539
+ return '{}';
540
+ }
541
+ }
542
+ _getLocale() {
543
+ return this._locale;
544
+ }
545
+ _cross() {
546
+ this._res.setHeader('access-control-allow-origin', '*');
547
+ this._res.setHeader('access-control-allow-headers', '*');
548
+ this._res.setHeader('access-control-allow-methods', '*');
549
+ if (this._req.method === 'OPTIONS') {
550
+ this._res.setHeader('access-control-max-age', '600');
551
+ return false;
552
+ }
553
+ return true;
554
+ }
555
+ _l(key, data) {
556
+ if (!this._localeData[this._locale]) {
557
+ return '[LocaleError]' + key;
558
+ }
559
+ if (!this._localeData[this._locale][key]) {
560
+ return '[LocaleError]' + key;
561
+ }
562
+ if (data) {
563
+ let i = -1;
564
+ return this._localeData[this._locale][key].replace(/\?/g, function () {
565
+ ++i;
566
+ if (!data[i]) {
567
+ return '';
568
+ }
569
+ return data[i];
570
+ });
571
+ }
572
+ else {
573
+ return this._localeData[this._locale][key];
574
+ }
575
+ }
576
+ _writeText(data) {
577
+ return this._socket.writeText(data);
578
+ }
579
+ _writeResult(data) {
580
+ return this._socket.writeResult(data);
581
+ }
582
+ _writeBinary(data) {
583
+ return this._socket.writeBinary(data);
584
+ }
585
+ _ping() {
586
+ return this._socket.ping();
587
+ }
588
+ _pong() {
589
+ return this._socket.pong();
590
+ }
591
+ _end() {
592
+ this._socket.end();
593
+ }
594
+ async _handleFormData(events = {}) {
595
+ const rtn = await sRoute.getFormData(this._req, events);
596
+ if (!rtn) {
597
+ return false;
598
+ }
599
+ for (const key in rtn.post) {
600
+ this._post[key] = rtn.post[key];
601
+ }
602
+ for (const key in rtn.files) {
603
+ this._files[key] = rtn.files[key];
604
+ }
605
+ return true;
606
+ }
607
+ }
608
+ exports.Ctr = Ctr;