jimeng-cli 0.2.0 → 0.2.1
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/dist/{chunk-JZY62VNI.js → chunk-3SUCLOAC.js} +143 -203
- package/dist/chunk-3SUCLOAC.js.map +1 -0
- package/dist/cli/index.cjs +146 -204
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/mcp/index.cjs +136 -198
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-JZY62VNI.js.map +0 -1
|
@@ -12,12 +12,6 @@ var Environment = class {
|
|
|
12
12
|
envVars;
|
|
13
13
|
/** 环境名称 */
|
|
14
14
|
env;
|
|
15
|
-
/** 服务名称 */
|
|
16
|
-
name;
|
|
17
|
-
/** 服务地址 */
|
|
18
|
-
host;
|
|
19
|
-
/** 服务端口 */
|
|
20
|
-
port;
|
|
21
15
|
/** 包参数 */
|
|
22
16
|
package;
|
|
23
17
|
constructor(options = {}) {
|
|
@@ -25,9 +19,6 @@ var Environment = class {
|
|
|
25
19
|
this.cmdArgs = cmdArgs2;
|
|
26
20
|
this.envVars = envVars2;
|
|
27
21
|
this.env = _.defaultTo(cmdArgs2.env || envVars2.SERVER_ENV, "dev");
|
|
28
|
-
this.name = cmdArgs2.name || envVars2.SERVER_NAME || void 0;
|
|
29
|
-
this.host = cmdArgs2.host || envVars2.SERVER_HOST || void 0;
|
|
30
|
-
this.port = Number(cmdArgs2.port || envVars2.SERVER_PORT) ? Number(cmdArgs2.port || envVars2.SERVER_PORT) : void 0;
|
|
31
22
|
this.package = _package;
|
|
32
23
|
}
|
|
33
24
|
};
|
|
@@ -37,26 +28,102 @@ var environment_default = new Environment({
|
|
|
37
28
|
package: JSON.parse(fs.readFileSync(path.join(path.resolve(), "package.json")).toString())
|
|
38
29
|
});
|
|
39
30
|
|
|
40
|
-
// src/lib/configs/
|
|
41
|
-
import
|
|
42
|
-
import
|
|
31
|
+
// src/lib/configs/system-config.ts
|
|
32
|
+
import path2 from "path";
|
|
33
|
+
import fs2 from "fs-extra";
|
|
43
34
|
import yaml from "yaml";
|
|
44
|
-
import
|
|
35
|
+
import _2 from "lodash";
|
|
36
|
+
var CONFIG_PATH = path2.join(path2.resolve(), "configs/", environment_default.env, "/system.yml");
|
|
37
|
+
var SystemConfig = class _SystemConfig {
|
|
38
|
+
/** 是否开启请求日志 */
|
|
39
|
+
requestLog;
|
|
40
|
+
/** 临时目录路径 */
|
|
41
|
+
tmpDir;
|
|
42
|
+
/** 日志目录路径 */
|
|
43
|
+
logDir;
|
|
44
|
+
/** 日志写入间隔(毫秒) */
|
|
45
|
+
logWriteInterval;
|
|
46
|
+
/** 日志文件有效期(毫秒) */
|
|
47
|
+
logFileExpires;
|
|
48
|
+
/** 临时文件有效期(毫秒) */
|
|
49
|
+
tmpFileExpires;
|
|
50
|
+
/** 请求体配置 */
|
|
51
|
+
requestBody;
|
|
52
|
+
/** 是否调试模式 */
|
|
53
|
+
debug;
|
|
54
|
+
/** 日志级别 */
|
|
55
|
+
log_level;
|
|
56
|
+
constructor(options) {
|
|
57
|
+
const { requestLog, tmpDir, logDir, logWriteInterval, logFileExpires, tmpFileExpires, requestBody, debug, log_level } = options || {};
|
|
58
|
+
this.requestLog = _2.defaultTo(requestLog, false);
|
|
59
|
+
this.tmpDir = _2.defaultTo(tmpDir, "./tmp");
|
|
60
|
+
this.logDir = _2.defaultTo(logDir, "./logs");
|
|
61
|
+
this.logWriteInterval = _2.defaultTo(logWriteInterval, 200);
|
|
62
|
+
this.logFileExpires = _2.defaultTo(logFileExpires, 262656e4);
|
|
63
|
+
this.tmpFileExpires = _2.defaultTo(tmpFileExpires, 864e5);
|
|
64
|
+
this.requestBody = Object.assign(requestBody || {}, {
|
|
65
|
+
enableTypes: ["form", "text", "xml"],
|
|
66
|
+
// 移除 json,由自定义中间件处理
|
|
67
|
+
encoding: "utf-8",
|
|
68
|
+
formLimit: "100mb",
|
|
69
|
+
jsonLimit: "100mb",
|
|
70
|
+
textLimit: "100mb",
|
|
71
|
+
xmlLimit: "100mb",
|
|
72
|
+
formidable: {
|
|
73
|
+
maxFileSize: "100mb"
|
|
74
|
+
},
|
|
75
|
+
multipart: true,
|
|
76
|
+
parsedMethods: ["POST", "PUT", "PATCH"]
|
|
77
|
+
});
|
|
78
|
+
this.debug = _2.defaultTo(debug, true);
|
|
79
|
+
this.log_level = _2.defaultTo(log_level, "info");
|
|
80
|
+
}
|
|
81
|
+
get rootDirPath() {
|
|
82
|
+
return path2.resolve();
|
|
83
|
+
}
|
|
84
|
+
get tmpDirPath() {
|
|
85
|
+
return path2.resolve(this.tmpDir);
|
|
86
|
+
}
|
|
87
|
+
get logDirPath() {
|
|
88
|
+
return path2.resolve(this.logDir);
|
|
89
|
+
}
|
|
90
|
+
static load() {
|
|
91
|
+
if (!fs2.pathExistsSync(CONFIG_PATH)) return new _SystemConfig();
|
|
92
|
+
const data = yaml.parse(fs2.readFileSync(CONFIG_PATH).toString());
|
|
93
|
+
return new _SystemConfig(data);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var system_config_default = SystemConfig.load();
|
|
97
|
+
|
|
98
|
+
// src/lib/config.ts
|
|
99
|
+
var Config = class {
|
|
100
|
+
/** 系统配置 */
|
|
101
|
+
system = system_config_default;
|
|
102
|
+
};
|
|
103
|
+
var config_default = new Config();
|
|
104
|
+
|
|
105
|
+
// src/lib/logger.ts
|
|
106
|
+
import path4 from "path";
|
|
107
|
+
import _util from "util";
|
|
108
|
+
import "colors";
|
|
109
|
+
import _4 from "lodash";
|
|
110
|
+
import fs4 from "fs-extra";
|
|
111
|
+
import { format as dateFormat2 } from "date-fns";
|
|
45
112
|
|
|
46
113
|
// src/lib/util.ts
|
|
47
114
|
import os from "os";
|
|
48
|
-
import
|
|
115
|
+
import path3 from "path";
|
|
49
116
|
import crypto from "crypto";
|
|
50
117
|
import { Readable, Writable } from "stream";
|
|
51
118
|
import "colors";
|
|
52
119
|
import mime from "mime";
|
|
53
120
|
import axios from "axios";
|
|
54
|
-
import
|
|
121
|
+
import fs3 from "fs-extra";
|
|
55
122
|
import { v4 as uuid } from "uuid";
|
|
56
123
|
import { format as dateFormat } from "date-fns";
|
|
57
124
|
import CRC32 from "crc-32";
|
|
58
125
|
import randomstring from "randomstring";
|
|
59
|
-
import
|
|
126
|
+
import _3 from "lodash";
|
|
60
127
|
import { CronJob } from "cron";
|
|
61
128
|
|
|
62
129
|
// src/lib/http-status-codes.ts
|
|
@@ -173,7 +240,7 @@ var http_status_codes_default = {
|
|
|
173
240
|
var autoIdMap = /* @__PURE__ */ new Map();
|
|
174
241
|
var util = {
|
|
175
242
|
is2DArrays(value) {
|
|
176
|
-
return
|
|
243
|
+
return _3.isArray(value) && (!value[0] || _3.isArray(value[0]) && _3.isArray(value[value.length - 1]));
|
|
177
244
|
},
|
|
178
245
|
uuid: (separator = true) => separator ? uuid() : uuid().replace(/\-/g, ""),
|
|
179
246
|
autoId: (prefix = "") => {
|
|
@@ -183,8 +250,8 @@ var util = {
|
|
|
183
250
|
return `${prefix}${index || 1}`;
|
|
184
251
|
},
|
|
185
252
|
ignoreJSONParse(value) {
|
|
186
|
-
const result =
|
|
187
|
-
if (
|
|
253
|
+
const result = _3.attempt(() => JSON.parse(value));
|
|
254
|
+
if (_3.isError(result)) return null;
|
|
188
255
|
return result;
|
|
189
256
|
},
|
|
190
257
|
generateRandomString(options) {
|
|
@@ -199,11 +266,11 @@ var util = {
|
|
|
199
266
|
return extension;
|
|
200
267
|
},
|
|
201
268
|
extractURLExtension(value) {
|
|
202
|
-
const extname =
|
|
269
|
+
const extname = path3.extname(new URL(value).pathname);
|
|
203
270
|
return extname.substring(1).toLowerCase();
|
|
204
271
|
},
|
|
205
272
|
createCronJob(cronPatterns, callback) {
|
|
206
|
-
if (!
|
|
273
|
+
if (!_3.isFunction(callback))
|
|
207
274
|
throw new Error("callback must be an Function");
|
|
208
275
|
return new CronJob(
|
|
209
276
|
cronPatterns,
|
|
@@ -256,14 +323,14 @@ retry: ${retry || 3e3}
|
|
|
256
323
|
return os.platform() !== "win32";
|
|
257
324
|
},
|
|
258
325
|
isIPAddress(value) {
|
|
259
|
-
return
|
|
326
|
+
return _3.isString(value) && (/^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/.test(
|
|
260
327
|
value
|
|
261
328
|
) || /\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*/.test(
|
|
262
329
|
value
|
|
263
330
|
));
|
|
264
331
|
},
|
|
265
332
|
isPort(value) {
|
|
266
|
-
return
|
|
333
|
+
return _3.isNumber(value) && value > 0 && value < 65536;
|
|
267
334
|
},
|
|
268
335
|
isReadStream(value) {
|
|
269
336
|
return value && (value instanceof Readable || "readable" in value || value.readable);
|
|
@@ -272,16 +339,16 @@ retry: ${retry || 3e3}
|
|
|
272
339
|
return value && (value instanceof Writable || "writable" in value || value.writable);
|
|
273
340
|
},
|
|
274
341
|
isHttpStatusCode(value) {
|
|
275
|
-
return
|
|
342
|
+
return _3.isNumber(value) && Object.values(http_status_codes_default).includes(value);
|
|
276
343
|
},
|
|
277
344
|
isURL(value) {
|
|
278
|
-
return !
|
|
345
|
+
return !_3.isUndefined(value) && /^(http|https)/.test(value);
|
|
279
346
|
},
|
|
280
347
|
isSrc(value) {
|
|
281
|
-
return !
|
|
348
|
+
return !_3.isUndefined(value) && /^\/.+\.[0-9a-zA-Z]+(\?.+)?$/.test(value);
|
|
282
349
|
},
|
|
283
350
|
isBASE64(value) {
|
|
284
|
-
return !
|
|
351
|
+
return !_3.isUndefined(value) && /^[a-zA-Z0-9\/\+]+(=?)+$/.test(value);
|
|
285
352
|
},
|
|
286
353
|
isBASE64Data(value) {
|
|
287
354
|
return /^data:/.test(value);
|
|
@@ -298,7 +365,7 @@ retry: ${retry || 3e3}
|
|
|
298
365
|
return /^(base64|json):/.test(value);
|
|
299
366
|
},
|
|
300
367
|
isStringNumber(value) {
|
|
301
|
-
return
|
|
368
|
+
return _3.isFinite(Number(value));
|
|
302
369
|
},
|
|
303
370
|
isUnixTimestamp(value) {
|
|
304
371
|
return /^[0-9]{10}$/.test(`${value}`);
|
|
@@ -316,7 +383,7 @@ retry: ${retry || 3e3}
|
|
|
316
383
|
},
|
|
317
384
|
async isAPNG(filePath) {
|
|
318
385
|
let head;
|
|
319
|
-
const readStream =
|
|
386
|
+
const readStream = fs3.createReadStream(filePath, { start: 37, end: 40 });
|
|
320
387
|
const readPromise = new Promise((resolve, reject) => {
|
|
321
388
|
readStream.once("end", resolve);
|
|
322
389
|
readStream.once("error", reject);
|
|
@@ -338,7 +405,7 @@ retry: ${retry || 3e3}
|
|
|
338
405
|
return url;
|
|
339
406
|
},
|
|
340
407
|
millisecondsToHmss(milliseconds) {
|
|
341
|
-
if (
|
|
408
|
+
if (_3.isString(milliseconds)) return milliseconds;
|
|
342
409
|
milliseconds = parseInt(milliseconds);
|
|
343
410
|
const sec = Math.floor(milliseconds / 1e3);
|
|
344
411
|
const hours = Math.floor(sec / 3600);
|
|
@@ -366,10 +433,10 @@ retry: ${retry || 3e3}
|
|
|
366
433
|
return crypto.createHash("md5").update(value).digest("hex");
|
|
367
434
|
},
|
|
368
435
|
crc32(value) {
|
|
369
|
-
return
|
|
436
|
+
return _3.isBuffer(value) ? CRC32.buf(value) : CRC32.str(value);
|
|
370
437
|
},
|
|
371
438
|
arrayParse(value) {
|
|
372
|
-
return
|
|
439
|
+
return _3.isArray(value) ? value : [value];
|
|
373
440
|
},
|
|
374
441
|
booleanParse(value) {
|
|
375
442
|
return value === "true" || value === true ? true : false;
|
|
@@ -410,141 +477,14 @@ retry: ${retry || 3e3}
|
|
|
410
477
|
};
|
|
411
478
|
var util_default = util;
|
|
412
479
|
|
|
413
|
-
// src/lib/configs/service-config.ts
|
|
414
|
-
var CONFIG_PATH = path3.join(path3.resolve(), "configs/", environment_default.env, "/service.yml");
|
|
415
|
-
var ServiceConfig = class _ServiceConfig {
|
|
416
|
-
/** 服务名称 */
|
|
417
|
-
name;
|
|
418
|
-
/** @type {string} 服务绑定主机地址 */
|
|
419
|
-
host;
|
|
420
|
-
/** @type {number} 服务绑定端口 */
|
|
421
|
-
port;
|
|
422
|
-
/** @type {string} 服务路由前缀 */
|
|
423
|
-
urlPrefix;
|
|
424
|
-
/** @type {string} 服务绑定地址(外部访问地址) */
|
|
425
|
-
bindAddress;
|
|
426
|
-
constructor(options) {
|
|
427
|
-
const { name, host, port, urlPrefix, bindAddress } = options || {};
|
|
428
|
-
this.name = _3.defaultTo(name, "jimeng-cli");
|
|
429
|
-
this.host = _3.defaultTo(host, "0.0.0.0");
|
|
430
|
-
this.port = _3.defaultTo(port, 5566);
|
|
431
|
-
this.urlPrefix = _3.defaultTo(urlPrefix, "");
|
|
432
|
-
this.bindAddress = bindAddress;
|
|
433
|
-
}
|
|
434
|
-
get addressHost() {
|
|
435
|
-
if (this.bindAddress) return this.bindAddress;
|
|
436
|
-
const ipAddresses = util_default.getIPAddressesByIPv4();
|
|
437
|
-
for (let ipAddress of ipAddresses) {
|
|
438
|
-
if (ipAddress === this.host)
|
|
439
|
-
return ipAddress;
|
|
440
|
-
}
|
|
441
|
-
return ipAddresses[0] || "127.0.0.1";
|
|
442
|
-
}
|
|
443
|
-
get address() {
|
|
444
|
-
return `${this.addressHost}:${this.port}`;
|
|
445
|
-
}
|
|
446
|
-
get pageDirUrl() {
|
|
447
|
-
return `http://127.0.0.1:${this.port}/page`;
|
|
448
|
-
}
|
|
449
|
-
static load() {
|
|
450
|
-
const external = _3.pickBy(environment_default, (v, k) => ["name", "host", "port"].includes(k) && !_3.isUndefined(v));
|
|
451
|
-
if (!fs3.pathExistsSync(CONFIG_PATH)) return new _ServiceConfig(external);
|
|
452
|
-
const data = yaml.parse(fs3.readFileSync(CONFIG_PATH).toString());
|
|
453
|
-
return new _ServiceConfig({ ...data, ...external });
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
var service_config_default = ServiceConfig.load();
|
|
457
|
-
|
|
458
|
-
// src/lib/configs/system-config.ts
|
|
459
|
-
import path4 from "path";
|
|
460
|
-
import fs4 from "fs-extra";
|
|
461
|
-
import yaml2 from "yaml";
|
|
462
|
-
import _4 from "lodash";
|
|
463
|
-
var CONFIG_PATH2 = path4.join(path4.resolve(), "configs/", environment_default.env, "/system.yml");
|
|
464
|
-
var SystemConfig = class _SystemConfig {
|
|
465
|
-
/** 是否开启请求日志 */
|
|
466
|
-
requestLog;
|
|
467
|
-
/** 临时目录路径 */
|
|
468
|
-
tmpDir;
|
|
469
|
-
/** 日志目录路径 */
|
|
470
|
-
logDir;
|
|
471
|
-
/** 日志写入间隔(毫秒) */
|
|
472
|
-
logWriteInterval;
|
|
473
|
-
/** 日志文件有效期(毫秒) */
|
|
474
|
-
logFileExpires;
|
|
475
|
-
/** 临时文件有效期(毫秒) */
|
|
476
|
-
tmpFileExpires;
|
|
477
|
-
/** 请求体配置 */
|
|
478
|
-
requestBody;
|
|
479
|
-
/** 是否调试模式 */
|
|
480
|
-
debug;
|
|
481
|
-
/** 日志级别 */
|
|
482
|
-
log_level;
|
|
483
|
-
constructor(options) {
|
|
484
|
-
const { requestLog, tmpDir, logDir, logWriteInterval, logFileExpires, tmpFileExpires, requestBody, debug, log_level } = options || {};
|
|
485
|
-
this.requestLog = _4.defaultTo(requestLog, false);
|
|
486
|
-
this.tmpDir = _4.defaultTo(tmpDir, "./tmp");
|
|
487
|
-
this.logDir = _4.defaultTo(logDir, "./logs");
|
|
488
|
-
this.logWriteInterval = _4.defaultTo(logWriteInterval, 200);
|
|
489
|
-
this.logFileExpires = _4.defaultTo(logFileExpires, 262656e4);
|
|
490
|
-
this.tmpFileExpires = _4.defaultTo(tmpFileExpires, 864e5);
|
|
491
|
-
this.requestBody = Object.assign(requestBody || {}, {
|
|
492
|
-
enableTypes: ["form", "text", "xml"],
|
|
493
|
-
// 移除 json,由自定义中间件处理
|
|
494
|
-
encoding: "utf-8",
|
|
495
|
-
formLimit: "100mb",
|
|
496
|
-
jsonLimit: "100mb",
|
|
497
|
-
textLimit: "100mb",
|
|
498
|
-
xmlLimit: "100mb",
|
|
499
|
-
formidable: {
|
|
500
|
-
maxFileSize: "100mb"
|
|
501
|
-
},
|
|
502
|
-
multipart: true,
|
|
503
|
-
parsedMethods: ["POST", "PUT", "PATCH"]
|
|
504
|
-
});
|
|
505
|
-
this.debug = _4.defaultTo(debug, true);
|
|
506
|
-
this.log_level = _4.defaultTo(log_level, "info");
|
|
507
|
-
}
|
|
508
|
-
get rootDirPath() {
|
|
509
|
-
return path4.resolve();
|
|
510
|
-
}
|
|
511
|
-
get tmpDirPath() {
|
|
512
|
-
return path4.resolve(this.tmpDir);
|
|
513
|
-
}
|
|
514
|
-
get logDirPath() {
|
|
515
|
-
return path4.resolve(this.logDir);
|
|
516
|
-
}
|
|
517
|
-
static load() {
|
|
518
|
-
if (!fs4.pathExistsSync(CONFIG_PATH2)) return new _SystemConfig();
|
|
519
|
-
const data = yaml2.parse(fs4.readFileSync(CONFIG_PATH2).toString());
|
|
520
|
-
return new _SystemConfig(data);
|
|
521
|
-
}
|
|
522
|
-
};
|
|
523
|
-
var system_config_default = SystemConfig.load();
|
|
524
|
-
|
|
525
|
-
// src/lib/config.ts
|
|
526
|
-
var Config = class {
|
|
527
|
-
/** 服务配置 */
|
|
528
|
-
service = service_config_default;
|
|
529
|
-
/** 系统配置 */
|
|
530
|
-
system = system_config_default;
|
|
531
|
-
};
|
|
532
|
-
var config_default = new Config();
|
|
533
|
-
|
|
534
480
|
// src/lib/logger.ts
|
|
535
|
-
import path5 from "path";
|
|
536
|
-
import _util from "util";
|
|
537
|
-
import "colors";
|
|
538
|
-
import _5 from "lodash";
|
|
539
|
-
import fs5 from "fs-extra";
|
|
540
|
-
import { format as dateFormat2 } from "date-fns";
|
|
541
481
|
var isVercelEnv = process.env.VERCEL;
|
|
542
482
|
var isCliSilentLogs = () => process.env.JIMENG_CLI_SILENT_LOGS === "true";
|
|
543
483
|
var LogWriter = class {
|
|
544
484
|
#buffers = [];
|
|
545
485
|
#timer = null;
|
|
546
486
|
constructor() {
|
|
547
|
-
!isVercelEnv &&
|
|
487
|
+
!isVercelEnv && fs4.ensureDirSync(config_default.system.logDirPath);
|
|
548
488
|
!isVercelEnv && this.work();
|
|
549
489
|
}
|
|
550
490
|
push(content) {
|
|
@@ -552,14 +492,14 @@ var LogWriter = class {
|
|
|
552
492
|
this.#buffers.push(buffer);
|
|
553
493
|
}
|
|
554
494
|
writeSync(buffer) {
|
|
555
|
-
!isVercelEnv &&
|
|
495
|
+
!isVercelEnv && fs4.appendFileSync(path4.join(config_default.system.logDirPath, `/${util_default.getDateString()}.log`), buffer);
|
|
556
496
|
}
|
|
557
497
|
async write(buffer) {
|
|
558
|
-
!isVercelEnv && await
|
|
498
|
+
!isVercelEnv && await fs4.appendFile(path4.join(config_default.system.logDirPath, `/${util_default.getDateString()}.log`), buffer);
|
|
559
499
|
}
|
|
560
500
|
flush() {
|
|
561
501
|
if (!this.#buffers.length) return;
|
|
562
|
-
!isVercelEnv &&
|
|
502
|
+
!isVercelEnv && fs4.appendFileSync(path4.join(config_default.system.logDirPath, `/${util_default.getDateString()}.log`), Buffer.concat(this.#buffers));
|
|
563
503
|
this.#buffers = [];
|
|
564
504
|
}
|
|
565
505
|
destroy() {
|
|
@@ -598,7 +538,7 @@ var LogText = class {
|
|
|
598
538
|
if (!text)
|
|
599
539
|
return unknownInfo;
|
|
600
540
|
const match = text.match(/at (.+) \((.+)\)/) || text.match(/at (.+)/);
|
|
601
|
-
if (!match || !
|
|
541
|
+
if (!match || !_4.isString(match[2] || match[1]))
|
|
602
542
|
return unknownInfo;
|
|
603
543
|
const temp = match[2] || match[1];
|
|
604
544
|
const _match = temp.match(/([a-zA-Z0-9_\-\.]+)\:(\d+)\:(\d+)$/);
|
|
@@ -703,7 +643,7 @@ var logger_default = new Logger();
|
|
|
703
643
|
// src/api/controllers/core.ts
|
|
704
644
|
import net from "net";
|
|
705
645
|
import dns from "dns/promises";
|
|
706
|
-
import
|
|
646
|
+
import _6 from "lodash";
|
|
707
647
|
import mime2 from "mime";
|
|
708
648
|
import axios2 from "axios";
|
|
709
649
|
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
@@ -711,7 +651,7 @@ import { SocksProxyAgent } from "socks-proxy-agent";
|
|
|
711
651
|
|
|
712
652
|
// src/lib/exceptions/Exception.ts
|
|
713
653
|
import assert from "assert";
|
|
714
|
-
import
|
|
654
|
+
import _5 from "lodash";
|
|
715
655
|
var Exception = class extends Error {
|
|
716
656
|
/** 错误码 */
|
|
717
657
|
errcode;
|
|
@@ -728,10 +668,10 @@ var Exception = class extends Error {
|
|
|
728
668
|
* @param _errmsg 异常消息
|
|
729
669
|
*/
|
|
730
670
|
constructor(exception, _errmsg) {
|
|
731
|
-
assert(
|
|
671
|
+
assert(_5.isArray(exception), "Exception must be Array");
|
|
732
672
|
const [errcode, errmsg] = exception;
|
|
733
|
-
assert(
|
|
734
|
-
assert(
|
|
673
|
+
assert(_5.isFinite(errcode), "Exception errcode invalid");
|
|
674
|
+
assert(_5.isString(errmsg), "Exception errmsg invalid");
|
|
735
675
|
super(_errmsg || errmsg);
|
|
736
676
|
this.errcode = errcode;
|
|
737
677
|
this.errmsg = _errmsg || errmsg;
|
|
@@ -745,7 +685,7 @@ var Exception = class extends Error {
|
|
|
745
685
|
return this;
|
|
746
686
|
}
|
|
747
687
|
setData(value) {
|
|
748
|
-
this.data =
|
|
688
|
+
this.data = _5.defaultTo(value, null);
|
|
749
689
|
return this;
|
|
750
690
|
}
|
|
751
691
|
};
|
|
@@ -1136,7 +1076,7 @@ async function acquireToken(refreshToken) {
|
|
|
1136
1076
|
}
|
|
1137
1077
|
var REGION_PREFIX_PATTERN = /^(us|hk|jp|sg)-/i;
|
|
1138
1078
|
function parseRegionCode(value) {
|
|
1139
|
-
if (!
|
|
1079
|
+
if (!_6.isString(value)) return null;
|
|
1140
1080
|
const normalized = value.trim().toLowerCase();
|
|
1141
1081
|
if (normalized === "cn" || normalized === "us" || normalized === "hk" || normalized === "jp" || normalized === "sg") {
|
|
1142
1082
|
return normalized;
|
|
@@ -1337,7 +1277,7 @@ async function request(method, uri, refreshToken, regionInfo, options = {}) {
|
|
|
1337
1277
|
// 增加超时时间到45秒
|
|
1338
1278
|
validateStatus: () => true,
|
|
1339
1279
|
// 允许任何状态码
|
|
1340
|
-
...
|
|
1280
|
+
..._6.omit(options, "params", "headers"),
|
|
1341
1281
|
...proxyAgent ? { httpAgent: proxyAgent, httpsAgent: proxyAgent, proxy: false } : {}
|
|
1342
1282
|
});
|
|
1343
1283
|
logger_default.info(`\u54CD\u5E94\u72B6\u6001: ${response.status} ${response.statusText}`);
|
|
@@ -1424,7 +1364,7 @@ async function checkImageContent(imageUri, refreshToken, regionInfo) {
|
|
|
1424
1364
|
}
|
|
1425
1365
|
function checkResult(result) {
|
|
1426
1366
|
const { ret, errmsg, data } = result.data;
|
|
1427
|
-
if (!
|
|
1367
|
+
if (!_6.isFinite(Number(ret))) return result.data;
|
|
1428
1368
|
if (ret === "0") return data;
|
|
1429
1369
|
JimengErrorHandler.handleApiResponse(result.data, {
|
|
1430
1370
|
context: "\u5373\u68A6API\u8BF7\u6C42",
|
|
@@ -1453,9 +1393,9 @@ async function getTokenLiveStatus(refreshToken, regionInfo) {
|
|
|
1453
1393
|
}
|
|
1454
1394
|
|
|
1455
1395
|
// src/lib/session-pool.ts
|
|
1456
|
-
import
|
|
1457
|
-
import
|
|
1458
|
-
import
|
|
1396
|
+
import path5 from "path";
|
|
1397
|
+
import fs5 from "fs-extra";
|
|
1398
|
+
import _7 from "lodash";
|
|
1459
1399
|
var DYNAMIC_CAPABILITY_TTL_MS = 30 * 60 * 1e3;
|
|
1460
1400
|
var TokenPool = class {
|
|
1461
1401
|
enabled;
|
|
@@ -1473,7 +1413,7 @@ var TokenPool = class {
|
|
|
1473
1413
|
roundRobinCursor = 0;
|
|
1474
1414
|
constructor() {
|
|
1475
1415
|
this.enabled = process.env.TOKEN_POOL_ENABLED !== "false";
|
|
1476
|
-
this.filePath =
|
|
1416
|
+
this.filePath = path5.resolve(
|
|
1477
1417
|
process.env.TOKEN_POOL_FILE || "configs/token-pool.json"
|
|
1478
1418
|
);
|
|
1479
1419
|
this.healthCheckIntervalMs = Number(
|
|
@@ -1545,7 +1485,7 @@ var TokenPool = class {
|
|
|
1545
1485
|
return this.pickTokenFromAuthorizationDetailed(authorization).token;
|
|
1546
1486
|
}
|
|
1547
1487
|
pickTokenFromAuthorizationDetailed(authorization) {
|
|
1548
|
-
if (
|
|
1488
|
+
if (_7.isString(authorization)) {
|
|
1549
1489
|
if (authorization.trim().length === 0) return { token: this.pickToken(), error: null };
|
|
1550
1490
|
if (!/^Bearer\s+/i.test(authorization)) {
|
|
1551
1491
|
return { token: null, error: "invalid_authorization_format" };
|
|
@@ -1554,7 +1494,7 @@ var TokenPool = class {
|
|
|
1554
1494
|
if (tokens.length === 0) {
|
|
1555
1495
|
return { token: null, error: "empty_authorization_tokens" };
|
|
1556
1496
|
}
|
|
1557
|
-
return { token:
|
|
1497
|
+
return { token: _7.sample(tokens) || null, error: null };
|
|
1558
1498
|
}
|
|
1559
1499
|
return { token: this.pickToken(), error: null };
|
|
1560
1500
|
}
|
|
@@ -1567,7 +1507,7 @@ var TokenPool = class {
|
|
|
1567
1507
|
this.roundRobinCursor++;
|
|
1568
1508
|
return token;
|
|
1569
1509
|
}
|
|
1570
|
-
return
|
|
1510
|
+
return _7.sample(tokens) || null;
|
|
1571
1511
|
}
|
|
1572
1512
|
pickTokenForRequest({
|
|
1573
1513
|
authorization,
|
|
@@ -1577,7 +1517,7 @@ var TokenPool = class {
|
|
|
1577
1517
|
xRegion
|
|
1578
1518
|
}) {
|
|
1579
1519
|
const xRegionCode = parseRegionCode(xRegion);
|
|
1580
|
-
if (
|
|
1520
|
+
if (_7.isString(xRegion) && xRegion.trim().length > 0 && !xRegionCode) {
|
|
1581
1521
|
return { token: null, region: null, error: "unsupported_region", reason: "X-Region \u4EC5\u652F\u6301 cn/us/hk/jp/sg" };
|
|
1582
1522
|
}
|
|
1583
1523
|
const authParseResult = this.parseAuthorizationTokens(authorization);
|
|
@@ -1774,14 +1714,14 @@ var TokenPool = class {
|
|
|
1774
1714
|
if (typeof this.healthCheckTimer.unref === "function") this.healthCheckTimer.unref();
|
|
1775
1715
|
}
|
|
1776
1716
|
async loadFromDisk() {
|
|
1777
|
-
await
|
|
1778
|
-
if (!await
|
|
1717
|
+
await fs5.ensureDir(path5.dirname(this.filePath));
|
|
1718
|
+
if (!await fs5.pathExists(this.filePath)) {
|
|
1779
1719
|
await this.persistToDisk();
|
|
1780
1720
|
return;
|
|
1781
1721
|
}
|
|
1782
1722
|
let data = null;
|
|
1783
1723
|
try {
|
|
1784
|
-
data = await
|
|
1724
|
+
data = await fs5.readJson(this.filePath);
|
|
1785
1725
|
} catch (err) {
|
|
1786
1726
|
logger_default.warn(`Token pool file parse failed, fallback to empty: ${(err == null ? void 0 : err.message) || String(err)}`);
|
|
1787
1727
|
data = null;
|
|
@@ -1796,10 +1736,10 @@ var TokenPool = class {
|
|
|
1796
1736
|
token,
|
|
1797
1737
|
region: parsedRegion || void 0,
|
|
1798
1738
|
enabled: raw.enabled !== false,
|
|
1799
|
-
live:
|
|
1800
|
-
lastCheckedAt:
|
|
1801
|
-
lastError:
|
|
1802
|
-
lastCredit:
|
|
1739
|
+
live: _7.isBoolean(raw.live) ? raw.live : void 0,
|
|
1740
|
+
lastCheckedAt: _7.isFinite(Number(raw.lastCheckedAt)) ? Number(raw.lastCheckedAt) : void 0,
|
|
1741
|
+
lastError: _7.isString(raw.lastError) ? raw.lastError : void 0,
|
|
1742
|
+
lastCredit: _7.isFinite(Number(raw.lastCredit)) ? Number(raw.lastCredit) : void 0,
|
|
1803
1743
|
consecutiveFailures: Math.max(0, Number(raw.consecutiveFailures) || 0),
|
|
1804
1744
|
allowedModels: this.normalizeStringArray(raw.allowedModels),
|
|
1805
1745
|
capabilityTags: this.normalizeStringArray(raw.capabilityTags),
|
|
@@ -1810,19 +1750,19 @@ var TokenPool = class {
|
|
|
1810
1750
|
for (const [token, item] of nextMap.entries()) this.entryMap.set(token, item);
|
|
1811
1751
|
}
|
|
1812
1752
|
async persistToDisk() {
|
|
1813
|
-
await
|
|
1753
|
+
await fs5.ensureDir(path5.dirname(this.filePath));
|
|
1814
1754
|
const payload = {
|
|
1815
1755
|
updatedAt: Date.now(),
|
|
1816
1756
|
tokens: this.getEntries(false)
|
|
1817
1757
|
};
|
|
1818
|
-
await
|
|
1758
|
+
await fs5.writeJson(this.filePath, payload, { spaces: 2 });
|
|
1819
1759
|
}
|
|
1820
1760
|
maskToken(token) {
|
|
1821
1761
|
if (token.length <= 10) return "***";
|
|
1822
1762
|
return `${token.slice(0, 4)}...${token.slice(-4)}`;
|
|
1823
1763
|
}
|
|
1824
1764
|
parseAuthorizationTokens(authorization) {
|
|
1825
|
-
if (!
|
|
1765
|
+
if (!_7.isString(authorization) || authorization.trim().length === 0) {
|
|
1826
1766
|
return { tokens: [], error: null };
|
|
1827
1767
|
}
|
|
1828
1768
|
if (!/^Bearer\s+/i.test(authorization)) {
|
|
@@ -1835,7 +1775,7 @@ var TokenPool = class {
|
|
|
1835
1775
|
normalizeAddTokens(rawTokens, defaultRegion) {
|
|
1836
1776
|
const normalized = [];
|
|
1837
1777
|
for (const item of rawTokens) {
|
|
1838
|
-
if (
|
|
1778
|
+
if (_7.isString(item)) {
|
|
1839
1779
|
const token2 = item.trim();
|
|
1840
1780
|
if (!token2) continue;
|
|
1841
1781
|
if (!defaultRegion) {
|
|
@@ -1873,7 +1813,7 @@ var TokenPool = class {
|
|
|
1873
1813
|
imageModels: this.normalizeStringArray(data.imageModels),
|
|
1874
1814
|
videoModels: this.normalizeStringArray(data.videoModels),
|
|
1875
1815
|
capabilityTags: this.normalizeStringArray(data.capabilityTags),
|
|
1876
|
-
updatedAt:
|
|
1816
|
+
updatedAt: _7.isFinite(Number(data.updatedAt)) ? Number(data.updatedAt) : void 0
|
|
1877
1817
|
};
|
|
1878
1818
|
if (!dynamic.imageModels && !dynamic.videoModels && !dynamic.capabilityTags && !dynamic.updatedAt) {
|
|
1879
1819
|
return void 0;
|
|
@@ -1918,7 +1858,7 @@ var TokenPool = class {
|
|
|
1918
1858
|
this.roundRobinCursor++;
|
|
1919
1859
|
return item;
|
|
1920
1860
|
}
|
|
1921
|
-
return
|
|
1861
|
+
return _7.sample(candidates) || candidates[0];
|
|
1922
1862
|
}
|
|
1923
1863
|
matchesModelAndCapabilities(candidate, requestedModel, taskType, requiredCapabilityTags) {
|
|
1924
1864
|
var _a, _b, _c, _d;
|
|
@@ -2613,9 +2553,9 @@ var RegionUtils = class {
|
|
|
2613
2553
|
/**
|
|
2614
2554
|
* 获取Referer路径
|
|
2615
2555
|
*/
|
|
2616
|
-
static getRefererPath(regionInfo,
|
|
2556
|
+
static getRefererPath(regionInfo, path6 = "/ai-tool/generate") {
|
|
2617
2557
|
const origin = this.getOrigin(regionInfo);
|
|
2618
|
-
return `${origin}${
|
|
2558
|
+
return `${origin}${path6}`;
|
|
2619
2559
|
}
|
|
2620
2560
|
};
|
|
2621
2561
|
|
|
@@ -3158,7 +3098,7 @@ function buildBlendAbilityList(uploadedImageIds, strength) {
|
|
|
3158
3098
|
}));
|
|
3159
3099
|
}
|
|
3160
3100
|
function buildPromptPlaceholderList(count) {
|
|
3161
|
-
return Array.from({ length: count }, (
|
|
3101
|
+
return Array.from({ length: count }, (_8, index) => ({
|
|
3162
3102
|
type: "",
|
|
3163
3103
|
id: util_default.uuid(),
|
|
3164
3104
|
ability_index: index
|
|
@@ -3658,7 +3598,7 @@ async function generateJimeng4xMultiImages(_model, prompt, {
|
|
|
3658
3598
|
}
|
|
3659
3599
|
|
|
3660
3600
|
// src/api/controllers/videos.ts
|
|
3661
|
-
import
|
|
3601
|
+
import fs6 from "fs-extra";
|
|
3662
3602
|
import axios5 from "axios";
|
|
3663
3603
|
|
|
3664
3604
|
// src/lib/video-uploader.ts
|
|
@@ -3950,7 +3890,7 @@ function getVideoBenefitType(model) {
|
|
|
3950
3890
|
async function uploadImageFromFile(file, refreshToken, regionInfo) {
|
|
3951
3891
|
try {
|
|
3952
3892
|
logger_default.info(`\u5F00\u59CB\u4ECE\u672C\u5730\u6587\u4EF6\u4E0A\u4F20\u89C6\u9891\u56FE\u7247: ${file.originalFilename} (\u8DEF\u5F84: ${file.filepath})`);
|
|
3953
|
-
const imageBuffer = await
|
|
3893
|
+
const imageBuffer = await fs6.readFile(file.filepath);
|
|
3954
3894
|
return await uploadImageBuffer(imageBuffer, refreshToken, regionInfo);
|
|
3955
3895
|
} catch (error) {
|
|
3956
3896
|
logger_default.error(`\u4ECE\u672C\u5730\u6587\u4EF6\u4E0A\u4F20\u89C6\u9891\u56FE\u7247\u5931\u8D25: ${error.message}`);
|
|
@@ -4161,7 +4101,7 @@ async function generateVideo(_model, prompt, {
|
|
|
4161
4101
|
throw new APIException(exceptions_default.API_REQUEST_FAILED, `${fieldName} \u4E0D\u652F\u6301\u91CD\u590D\u4E0A\u4F20\u591A\u4E2A\u6587\u4EF6`);
|
|
4162
4102
|
}
|
|
4163
4103
|
if (imageFile) {
|
|
4164
|
-
const buf = await
|
|
4104
|
+
const buf = await fs6.readFile(imageFile.filepath);
|
|
4165
4105
|
imgResult = await uploadImageBuffer(buf, refreshToken, regionInfo);
|
|
4166
4106
|
await checkImageContent(imgResult.uri, refreshToken, regionInfo);
|
|
4167
4107
|
const entry = {
|
|
@@ -4238,7 +4178,7 @@ async function generateVideo(_model, prompt, {
|
|
|
4238
4178
|
throw new APIException(exceptions_default.API_REQUEST_FAILED, `${fieldName} \u4E0D\u652F\u6301\u91CD\u590D\u4E0A\u4F20\u591A\u4E2A\u6587\u4EF6`);
|
|
4239
4179
|
}
|
|
4240
4180
|
if (videoFile) {
|
|
4241
|
-
const buf = await
|
|
4181
|
+
const buf = await fs6.readFile(videoFile.filepath);
|
|
4242
4182
|
vResult = await uploadVideoBuffer(buf, refreshToken, regionInfo);
|
|
4243
4183
|
totalVideoDuration += vResult.videoMeta.duration;
|
|
4244
4184
|
const entry = {
|
|
@@ -4741,8 +4681,8 @@ async function generateVideo(_model, prompt, {
|
|
|
4741
4681
|
|
|
4742
4682
|
export {
|
|
4743
4683
|
environment_default,
|
|
4744
|
-
util_default,
|
|
4745
4684
|
config_default,
|
|
4685
|
+
util_default,
|
|
4746
4686
|
logger_default,
|
|
4747
4687
|
DEFAULT_IMAGE_MODEL,
|
|
4748
4688
|
parseRegionCode,
|
|
@@ -4759,4 +4699,4 @@ export {
|
|
|
4759
4699
|
DEFAULT_MODEL2 as DEFAULT_MODEL,
|
|
4760
4700
|
generateVideo
|
|
4761
4701
|
};
|
|
4762
|
-
//# sourceMappingURL=chunk-
|
|
4702
|
+
//# sourceMappingURL=chunk-3SUCLOAC.js.map
|