@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.
- package/.VSCodeCounter/2025-02-14_14-46-44/details.md +82 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/diff-details.md +15 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.csv +2 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.md +19 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.txt +22 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/results.csv +69 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/results.json +1 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/results.md +48 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/results.txt +118 -0
- package/.vscode/tasks.json +15 -0
- package/LICENSE +201 -0
- package/README.md +201 -0
- package/bin/kebab.js +2 -0
- package/eslint.config.js +22 -0
- package/index.js +19 -0
- package/index.ts +33 -0
- package/lib/buffer.js +108 -0
- package/lib/buffer.ts +152 -0
- package/lib/captcha/zcool-addict-italic.ttf +0 -0
- package/lib/captcha.js +71 -0
- package/lib/captcha.ts +63 -0
- package/lib/consistent.js +171 -0
- package/lib/consistent.ts +219 -0
- package/lib/core.js +663 -0
- package/lib/core.ts +880 -0
- package/lib/crypto.js +256 -0
- package/lib/crypto.ts +384 -0
- package/lib/db.js +521 -0
- package/lib/db.ts +719 -0
- package/lib/dns.js +321 -0
- package/lib/dns.ts +405 -0
- package/lib/fs.js +405 -0
- package/lib/fs.ts +527 -0
- package/lib/jwt.js +223 -0
- package/lib/jwt.ts +276 -0
- package/lib/kv.js +1004 -0
- package/lib/kv.ts +1489 -0
- package/lib/lan.js +99 -0
- package/lib/lan.ts +87 -0
- package/lib/net/cacert.pem +3480 -0
- package/lib/net/formdata.js +137 -0
- package/lib/net/formdata.ts +166 -0
- package/lib/net/request.js +102 -0
- package/lib/net/request.ts +150 -0
- package/lib/net/response.js +28 -0
- package/lib/net/response.ts +59 -0
- package/lib/net.js +462 -0
- package/lib/net.ts +662 -0
- package/lib/s3.js +180 -0
- package/lib/s3.ts +235 -0
- package/lib/scan.js +276 -0
- package/lib/scan.ts +364 -0
- package/lib/session.js +177 -0
- package/lib/session.ts +230 -0
- package/lib/sql.js +818 -0
- package/lib/sql.ts +1151 -0
- package/lib/ssh/sftp.js +373 -0
- package/lib/ssh/sftp.ts +508 -0
- package/lib/ssh/shell.js +109 -0
- package/lib/ssh/shell.ts +123 -0
- package/lib/ssh.js +171 -0
- package/lib/ssh.ts +191 -0
- package/lib/text/tld.json +1 -0
- package/lib/text.js +452 -0
- package/lib/text.ts +607 -0
- package/lib/time.js +216 -0
- package/lib/time.ts +254 -0
- package/lib/ws.js +373 -0
- package/lib/ws.ts +523 -0
- package/lib/zip.js +381 -0
- package/lib/zip.ts +447 -0
- package/lib/zlib.js +289 -0
- package/lib/zlib.ts +350 -0
- package/main.js +51 -0
- package/main.ts +27 -0
- package/package.json +37 -0
- package/sys/child.js +585 -0
- package/sys/child.ts +678 -0
- package/sys/cmd.js +226 -0
- package/sys/cmd.ts +225 -0
- package/sys/ctr.js +608 -0
- package/sys/ctr.ts +904 -0
- package/sys/master.js +314 -0
- package/sys/master.ts +355 -0
- package/sys/mod.js +1273 -0
- package/sys/mod.ts +1871 -0
- package/sys/route.js +922 -0
- package/sys/route.ts +1113 -0
- package/types/index.d.ts +283 -0
- package/www/example/ctr/main.js +42 -0
- package/www/example/ctr/main.ts +9 -0
- package/www/example/ctr/middle.js +57 -0
- package/www/example/ctr/middle.ts +26 -0
- package/www/example/ctr/test.js +2818 -0
- package/www/example/ctr/test.ts +3218 -0
- package/www/example/data/locale/en.test.json +8 -0
- package/www/example/data/locale/index.html +1 -0
- package/www/example/data/locale/ja.test.json +8 -0
- package/www/example/data/locale/sc.test.json +8 -0
- package/www/example/data/locale/tc.test.json +8 -0
- package/www/example/data/test.zip +0 -0
- package/www/example/kebab.json +24 -0
- package/www/example/mod/test.js +49 -0
- package/www/example/mod/test.ts +47 -0
- package/www/example/mod/testdata.js +11 -0
- package/www/example/mod/testdata.ts +30 -0
- package/www/example/route.json +6 -0
- package/www/example/view/test.ejs +11 -0
- package/www/example/ws/mproxy.js +49 -0
- package/www/example/ws/mproxy.ts +16 -0
- package/www/example/ws/rproxy.js +47 -0
- package/www/example/ws/rproxy.ts +14 -0
- package/www/example/ws/test.js +68 -0
- package/www/example/ws/test.ts +36 -0
package/lib/fs.js
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
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.getContent = getContent;
|
|
37
|
+
exports.putContent = putContent;
|
|
38
|
+
exports.readLink = readLink;
|
|
39
|
+
exports.symlink = symlink;
|
|
40
|
+
exports.unlink = unlink;
|
|
41
|
+
exports.stats = stats;
|
|
42
|
+
exports.isDir = isDir;
|
|
43
|
+
exports.isFile = isFile;
|
|
44
|
+
exports.mkdir = mkdir;
|
|
45
|
+
exports.rmdir = rmdir;
|
|
46
|
+
exports.rmdirDeep = rmdirDeep;
|
|
47
|
+
exports.chmod = chmod;
|
|
48
|
+
exports.rename = rename;
|
|
49
|
+
exports.readDir = readDir;
|
|
50
|
+
exports.copyFolder = copyFolder;
|
|
51
|
+
exports.copyFile = copyFile;
|
|
52
|
+
exports.createReadStream = createReadStream;
|
|
53
|
+
exports.pipe = pipe;
|
|
54
|
+
exports.createWriteStream = createWriteStream;
|
|
55
|
+
exports.readToResponse = readToResponse;
|
|
56
|
+
const fs = __importStar(require("fs"));
|
|
57
|
+
const http2 = __importStar(require("http2"));
|
|
58
|
+
const mime = __importStar(require("@litert/mime"));
|
|
59
|
+
const text = __importStar(require("./text"));
|
|
60
|
+
const core = __importStar(require("./core"));
|
|
61
|
+
const zlib = __importStar(require("./zlib"));
|
|
62
|
+
async function getContent(path, options) {
|
|
63
|
+
if (typeof options === 'string') {
|
|
64
|
+
options = {
|
|
65
|
+
'encoding': options
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
else if (!options) {
|
|
69
|
+
options = {};
|
|
70
|
+
}
|
|
71
|
+
const encoding = options.encoding;
|
|
72
|
+
const start = options.start;
|
|
73
|
+
const end = options.end;
|
|
74
|
+
if (start ?? end) {
|
|
75
|
+
return new Promise(function (resolve) {
|
|
76
|
+
const rs = createReadStream(path, {
|
|
77
|
+
'encoding': encoding,
|
|
78
|
+
'start': start,
|
|
79
|
+
'end': end
|
|
80
|
+
});
|
|
81
|
+
const data = [];
|
|
82
|
+
rs.on('data', (chunk) => {
|
|
83
|
+
if (!(chunk instanceof Buffer)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
data.push(chunk);
|
|
87
|
+
}).on('end', function () {
|
|
88
|
+
const buf = Buffer.concat(data);
|
|
89
|
+
if (encoding) {
|
|
90
|
+
resolve(buf.toString());
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
resolve(buf);
|
|
94
|
+
}
|
|
95
|
+
}).on('error', function () {
|
|
96
|
+
resolve(null);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
try {
|
|
102
|
+
if (encoding) {
|
|
103
|
+
return await fs.promises.readFile(path, {
|
|
104
|
+
'encoding': encoding
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
return await fs.promises.readFile(path);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function putContent(path, data, options = {}) {
|
|
117
|
+
try {
|
|
118
|
+
await fs.promises.writeFile(path, data, options);
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async function readLink(path, encoding) {
|
|
126
|
+
try {
|
|
127
|
+
return await fs.promises.readlink(path, {
|
|
128
|
+
'encoding': encoding
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async function symlink(filePath, linkPath, type) {
|
|
136
|
+
try {
|
|
137
|
+
await fs.promises.symlink(filePath, linkPath, type);
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async function unlink(path) {
|
|
145
|
+
for (let i = 0; i <= 2; ++i) {
|
|
146
|
+
try {
|
|
147
|
+
await fs.promises.unlink(path);
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
await core.sleep(250);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
await fs.promises.unlink(path);
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async function stats(path) {
|
|
163
|
+
try {
|
|
164
|
+
return await fs.promises.lstat(path);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async function isDir(path) {
|
|
171
|
+
const pstats = await stats(path);
|
|
172
|
+
if (!pstats?.isDirectory()) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return pstats;
|
|
176
|
+
}
|
|
177
|
+
async function isFile(path) {
|
|
178
|
+
const pstats = await stats(path);
|
|
179
|
+
if (!pstats?.isFile()) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
return pstats;
|
|
183
|
+
}
|
|
184
|
+
async function mkdir(path, mode = 0o755) {
|
|
185
|
+
if (await isDir(path)) {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
await fs.promises.mkdir(path, {
|
|
190
|
+
'recursive': true,
|
|
191
|
+
'mode': mode
|
|
192
|
+
});
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
async function rmdir(path) {
|
|
200
|
+
if (!(await isDir(path))) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
await fs.promises.rmdir(path);
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async function rmdirDeep(path) {
|
|
212
|
+
if (!path.endsWith('/')) {
|
|
213
|
+
path += '/';
|
|
214
|
+
}
|
|
215
|
+
const list = await readDir(path);
|
|
216
|
+
for (const item of list) {
|
|
217
|
+
const stat = await stats(item.name);
|
|
218
|
+
if (!stat) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
if (stat.isDirectory()) {
|
|
222
|
+
const rtn = await rmdirDeep(path + item.name);
|
|
223
|
+
if (!rtn) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
const rtn = await unlink(path + item.name);
|
|
229
|
+
if (!rtn) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return rmdir(path);
|
|
235
|
+
}
|
|
236
|
+
async function chmod(path, mod) {
|
|
237
|
+
try {
|
|
238
|
+
await fs.promises.chmod(path, mod);
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function rename(oldPath, newPath) {
|
|
246
|
+
try {
|
|
247
|
+
await fs.promises.rename(oldPath, newPath);
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
async function readDir(path, encoding) {
|
|
255
|
+
try {
|
|
256
|
+
const list = [];
|
|
257
|
+
const dlist = await fs.promises.readdir(path, {
|
|
258
|
+
'encoding': encoding,
|
|
259
|
+
'withFileTypes': true
|
|
260
|
+
});
|
|
261
|
+
for (const item of dlist) {
|
|
262
|
+
if (item.name === '.' || item.name === '..') {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
list.push(item);
|
|
266
|
+
}
|
|
267
|
+
return list;
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return [];
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async function copyFolder(from, to, ignore = []) {
|
|
274
|
+
let num = 0;
|
|
275
|
+
if (!await isDir(from)) {
|
|
276
|
+
return 0;
|
|
277
|
+
}
|
|
278
|
+
const flist = await readDir(from);
|
|
279
|
+
let checkTo = false;
|
|
280
|
+
for (const item of flist) {
|
|
281
|
+
if (item.isDirectory()) {
|
|
282
|
+
const r = await copyFolder(from + item.name + '/', to + item.name + '/', ignore);
|
|
283
|
+
if (r === -1) {
|
|
284
|
+
return r;
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
num += r;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
else if (item.isFile()) {
|
|
291
|
+
if (ignore.length > 0 && text.match(item.name, ignore)) {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (!checkTo) {
|
|
295
|
+
if (!await mkdir(to)) {
|
|
296
|
+
return -1;
|
|
297
|
+
}
|
|
298
|
+
checkTo = true;
|
|
299
|
+
}
|
|
300
|
+
if (!(await copyFile(from + item.name, to + item.name))) {
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
++num;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return num;
|
|
307
|
+
}
|
|
308
|
+
async function copyFile(src, dest) {
|
|
309
|
+
try {
|
|
310
|
+
await fs.promises.copyFile(src, dest);
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
catch {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function createReadStream(path, options) {
|
|
318
|
+
if (typeof options === 'string') {
|
|
319
|
+
options = {
|
|
320
|
+
'encoding': options
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
else if (!options) {
|
|
324
|
+
options = {};
|
|
325
|
+
}
|
|
326
|
+
return fs.createReadStream(path, {
|
|
327
|
+
'flags': options.flags,
|
|
328
|
+
'encoding': options.encoding,
|
|
329
|
+
'autoClose': options.autoClose,
|
|
330
|
+
'start': options.start,
|
|
331
|
+
'end': options.end
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
function pipe(path, destination, options) {
|
|
335
|
+
return new Promise((resolve) => {
|
|
336
|
+
createReadStream(path).on('error', function () {
|
|
337
|
+
resolve(false);
|
|
338
|
+
}).on('end', function () {
|
|
339
|
+
resolve(true);
|
|
340
|
+
}).pipe(destination, options);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
function createWriteStream(path, options) {
|
|
344
|
+
if (typeof options === 'string') {
|
|
345
|
+
options = {
|
|
346
|
+
'encoding': options
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
else if (!options) {
|
|
350
|
+
options = {};
|
|
351
|
+
}
|
|
352
|
+
return fs.createWriteStream(path, {
|
|
353
|
+
'flags': options.flags,
|
|
354
|
+
'encoding': options.encoding,
|
|
355
|
+
'mode': options.mode,
|
|
356
|
+
'autoClose': options.autoClose,
|
|
357
|
+
'start': options.start
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
async function readToResponse(path, req, res, stat) {
|
|
361
|
+
if (!stat) {
|
|
362
|
+
stat = await stats(path);
|
|
363
|
+
}
|
|
364
|
+
if (!stat) {
|
|
365
|
+
res.setHeader('content-length', 22);
|
|
366
|
+
res.writeHead(404);
|
|
367
|
+
res.end('<h1>404 Not found</h1><hr>Kebab');
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
let charset = '';
|
|
371
|
+
const mimeData = mime.getData(path);
|
|
372
|
+
if (['htm', 'html', 'css', 'js', 'xml', 'jpg', 'jpeg', 'svg', 'gif', 'png'].includes(mimeData.extension)) {
|
|
373
|
+
charset = '; charset=utf-8';
|
|
374
|
+
const hash = `W/"${stat.size.toString(16)}-${stat.mtime.getTime().toString(16)}"`;
|
|
375
|
+
const lastModified = stat.mtime.toUTCString();
|
|
376
|
+
res.setHeader('etag', hash);
|
|
377
|
+
res.setHeader('cache-control', 'public, max-age=600');
|
|
378
|
+
const noneMatch = req.headers['if-none-match'];
|
|
379
|
+
const modifiedSince = req.headers['if-modified-since'];
|
|
380
|
+
if ((hash === noneMatch) && (lastModified === modifiedSince)) {
|
|
381
|
+
res.writeHead(304);
|
|
382
|
+
res.end();
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
res.setHeader('last-modified', lastModified);
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
res.setHeader('cache-control', 'no-cache, must-revalidate');
|
|
389
|
+
}
|
|
390
|
+
res.setHeader('content-type', mimeData.mime + charset);
|
|
391
|
+
const encoding = req.headers['accept-encoding'] ?? '';
|
|
392
|
+
if (mimeData.compressible && (stat.size >= 1024)) {
|
|
393
|
+
const compress = await zlib.compress(encoding, await getContent(path));
|
|
394
|
+
if (compress) {
|
|
395
|
+
res.setHeader('content-encoding', compress.type);
|
|
396
|
+
res.setHeader('content-length', Buffer.byteLength(compress.buffer));
|
|
397
|
+
res.writeHead(200);
|
|
398
|
+
res.end(compress.buffer);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
res.setHeader('content-length', stat.size);
|
|
403
|
+
res.writeHead(200);
|
|
404
|
+
await pipe(path, res instanceof http2.Http2ServerResponse ? (res.stream ?? res) : res);
|
|
405
|
+
}
|