@kevisual/cli 0.1.5 → 0.1.6
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/assistant-opencode.js +273 -148
- package/dist/assistant-server.js +263 -159
- package/dist/assistant.js +115 -63
- package/dist/envision.js +1482 -1368
- package/package.json +4 -5
package/dist/envision.js
CHANGED
|
@@ -21754,7 +21754,8 @@ var {
|
|
|
21754
21754
|
// src/program.ts
|
|
21755
21755
|
import fs from "fs";
|
|
21756
21756
|
|
|
21757
|
-
// node_modules/.pnpm/@kevisual+context@0.0.
|
|
21757
|
+
// node_modules/.pnpm/@kevisual+context@0.0.8/node_modules/@kevisual/context/dist/app.js
|
|
21758
|
+
var isBrowser2 = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
21758
21759
|
function getDefaultExportFromCjs(x) {
|
|
21759
21760
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
21760
21761
|
}
|
|
@@ -22218,7 +22219,7 @@ var useEnv = (initEnv, initKey = "config", isOverwrite) => {
|
|
|
22218
22219
|
}
|
|
22219
22220
|
return gt[initKey];
|
|
22220
22221
|
};
|
|
22221
|
-
var useEnvKey = (key, init, initKey = "config") => {
|
|
22222
|
+
var useEnvKey = (key, init, initKey = "config", opts = {}) => {
|
|
22222
22223
|
const _env = useEnv({}, initKey);
|
|
22223
22224
|
if (key && typeof _env[key] !== "undefined") {
|
|
22224
22225
|
return _env[key];
|
|
@@ -22244,12 +22245,13 @@ var useEnvKey = (key, init, initKey = "config") => {
|
|
|
22244
22245
|
const voidFn = async () => {
|
|
22245
22246
|
return _env[key];
|
|
22246
22247
|
};
|
|
22248
|
+
const timeout = opts.timeout || 5 * 60 * 1000;
|
|
22247
22249
|
const checkFn = async () => {
|
|
22248
22250
|
const loadRes = await baseLoad.load(voidFn, {
|
|
22249
22251
|
key,
|
|
22250
22252
|
isReRun: true,
|
|
22251
22253
|
checkSuccess: () => _env[key],
|
|
22252
|
-
timeout
|
|
22254
|
+
timeout,
|
|
22253
22255
|
interval: 1000
|
|
22254
22256
|
});
|
|
22255
22257
|
if (loadRes.code !== 200) {
|
|
@@ -22265,27 +22267,28 @@ var useEnvKey = (key, init, initKey = "config") => {
|
|
|
22265
22267
|
};
|
|
22266
22268
|
var useEnvKeyNew = (key, initKey = "config", opts) => {
|
|
22267
22269
|
const _env = useEnv({}, initKey);
|
|
22270
|
+
const timeout = opts?.timeout;
|
|
22268
22271
|
if (key) {
|
|
22269
22272
|
delete _env[key];
|
|
22270
22273
|
}
|
|
22271
22274
|
if (opts?.getNew && opts.init) {
|
|
22272
|
-
return useEnvKey(key, opts.init, initKey);
|
|
22275
|
+
return useEnvKey(key, opts.init, initKey, { timeout });
|
|
22273
22276
|
} else if (opts?.getNew) {
|
|
22274
|
-
return useEnvKey(key, null, initKey);
|
|
22277
|
+
return useEnvKey(key, null, initKey, { timeout });
|
|
22275
22278
|
}
|
|
22276
22279
|
};
|
|
22277
|
-
var useContextKey = (key, init,
|
|
22278
|
-
if (isNew) {
|
|
22279
|
-
return useEnvKeyNew(key, "context", { getNew: true, init });
|
|
22280
|
+
var useContextKey = (key, init, opts) => {
|
|
22281
|
+
if (opts?.isNew) {
|
|
22282
|
+
return useEnvKeyNew(key, "context", { getNew: true, init, ...opts });
|
|
22280
22283
|
}
|
|
22281
|
-
return useEnvKey(key, init, "context");
|
|
22284
|
+
return useEnvKey(key, init, "context", opts);
|
|
22282
22285
|
};
|
|
22283
22286
|
var use = useContextKey;
|
|
22284
|
-
var useConfigKey = (key, init,
|
|
22285
|
-
if (isNew) {
|
|
22286
|
-
return useEnvKeyNew(key, "config", { getNew: true, init });
|
|
22287
|
+
var useConfigKey = (key, init, opts) => {
|
|
22288
|
+
if (opts?.isNew) {
|
|
22289
|
+
return useEnvKeyNew(key, "config", { getNew: true, init, ...opts });
|
|
22287
22290
|
}
|
|
22288
|
-
return useEnvKey(key, init, "config");
|
|
22291
|
+
return useEnvKey(key, init, "config", opts);
|
|
22289
22292
|
};
|
|
22290
22293
|
|
|
22291
22294
|
class InitEnv {
|
|
@@ -22309,8 +22312,8 @@ InitEnv.init();
|
|
|
22309
22312
|
var version = useContextKey("version", () => {
|
|
22310
22313
|
let version2 = "0.0.64";
|
|
22311
22314
|
try {
|
|
22312
|
-
if ("0.1.
|
|
22313
|
-
version2 = "0.1.
|
|
22315
|
+
if ("0.1.6")
|
|
22316
|
+
version2 = "0.1.6";
|
|
22314
22317
|
} catch (e) {}
|
|
22315
22318
|
return version2;
|
|
22316
22319
|
});
|
|
@@ -25123,23 +25126,17 @@ var dist_default6 = createPrompt((config, done) => {
|
|
|
25123
25126
|
var import_md5 = __toESM(require_md5(), 1);
|
|
25124
25127
|
var import_jsonwebtoken = __toESM(require_jsonwebtoken(), 1);
|
|
25125
25128
|
|
|
25126
|
-
// node_modules/.pnpm/@kevisual+query@0.0.
|
|
25129
|
+
// node_modules/.pnpm/@kevisual+query@0.0.49/node_modules/@kevisual/query/dist/query.js
|
|
25127
25130
|
var isTextForContentType = (contentType) => {
|
|
25128
25131
|
if (!contentType)
|
|
25129
25132
|
return false;
|
|
25130
|
-
const textTypes = ["text/", "xml", "html", "javascript", "css", "csv", "plain", "x-www-form-urlencoded", "md"];
|
|
25133
|
+
const textTypes = ["text/", "xml", "html", "javascript", "css", "csv", "plain", "x-www-form-urlencoded", "md", "json"];
|
|
25131
25134
|
return textTypes.some((type) => contentType.includes(type));
|
|
25132
25135
|
};
|
|
25133
25136
|
var adapter = async (opts = {}, overloadOpts) => {
|
|
25134
25137
|
const controller = new AbortController;
|
|
25135
25138
|
const signal = controller.signal;
|
|
25136
25139
|
const isPostFile = opts.isPostFile || false;
|
|
25137
|
-
let responseType = opts.responseType || "json";
|
|
25138
|
-
if (opts.isBlob) {
|
|
25139
|
-
responseType = "blob";
|
|
25140
|
-
} else if (opts.isText) {
|
|
25141
|
-
responseType = "text";
|
|
25142
|
-
}
|
|
25143
25140
|
const timeout = opts.timeout || 60000 * 3;
|
|
25144
25141
|
const timer = setTimeout(() => {
|
|
25145
25142
|
controller.abort();
|
|
@@ -25198,21 +25195,31 @@ var adapter = async (opts = {}, overloadOpts) => {
|
|
|
25198
25195
|
headers
|
|
25199
25196
|
}).then(async (response) => {
|
|
25200
25197
|
const contentType = response.headers.get("Content-Type");
|
|
25201
|
-
if (responseType === "blob") {
|
|
25202
|
-
return await response.blob();
|
|
25203
|
-
}
|
|
25204
|
-
const isText = responseType === "text";
|
|
25205
25198
|
const isJson = contentType && contentType.includes("application/json");
|
|
25206
|
-
|
|
25207
|
-
|
|
25199
|
+
const isSuccess = response.ok;
|
|
25200
|
+
if (isJson) {
|
|
25201
|
+
const json = await response.json();
|
|
25202
|
+
if (json?.code) {
|
|
25203
|
+
return json;
|
|
25204
|
+
}
|
|
25205
|
+
return {
|
|
25206
|
+
code: isSuccess ? 200 : response.status,
|
|
25207
|
+
status: response.status,
|
|
25208
|
+
data: json
|
|
25209
|
+
};
|
|
25208
25210
|
} else if (isTextForContentType(contentType)) {
|
|
25209
25211
|
return {
|
|
25210
|
-
code: response.status,
|
|
25212
|
+
code: isSuccess ? 200 : response.status,
|
|
25211
25213
|
status: response.status,
|
|
25212
25214
|
data: await response.text()
|
|
25213
25215
|
};
|
|
25214
25216
|
} else {
|
|
25215
|
-
return
|
|
25217
|
+
return {
|
|
25218
|
+
code: isSuccess ? 200 : response.status,
|
|
25219
|
+
status: response.status,
|
|
25220
|
+
data: "非文本非JSON响应, 请手动处理response。",
|
|
25221
|
+
response
|
|
25222
|
+
};
|
|
25216
25223
|
}
|
|
25217
25224
|
}).catch((err) => {
|
|
25218
25225
|
if (err.name === "AbortError") {
|
|
@@ -25229,28 +25236,17 @@ var adapter = async (opts = {}, overloadOpts) => {
|
|
|
25229
25236
|
clearTimeout(timer);
|
|
25230
25237
|
});
|
|
25231
25238
|
};
|
|
25232
|
-
var setBaseResponse = (res) => {
|
|
25233
|
-
res.success = res.code === 200;
|
|
25234
|
-
res.showError = (fn) => {
|
|
25235
|
-
if (!res.success && !res.noMsg) {
|
|
25236
|
-
fn?.();
|
|
25237
|
-
}
|
|
25238
|
-
};
|
|
25239
|
-
return res;
|
|
25240
|
-
};
|
|
25241
25239
|
var wrapperError = ({ code, message }) => {
|
|
25242
25240
|
const result = {
|
|
25243
25241
|
code: code || 500,
|
|
25244
|
-
|
|
25245
|
-
message: message || "api request error",
|
|
25246
|
-
showError: (fn) => {},
|
|
25247
|
-
noMsg: true
|
|
25242
|
+
message: message || "请求错误"
|
|
25248
25243
|
};
|
|
25249
25244
|
return result;
|
|
25250
25245
|
};
|
|
25251
25246
|
|
|
25252
25247
|
class Query {
|
|
25253
25248
|
adapter;
|
|
25249
|
+
baseURL;
|
|
25254
25250
|
url;
|
|
25255
25251
|
beforeRequest;
|
|
25256
25252
|
afterResponse;
|
|
@@ -25258,11 +25254,20 @@ class Query {
|
|
|
25258
25254
|
timeout;
|
|
25259
25255
|
stop;
|
|
25260
25256
|
qws;
|
|
25261
|
-
|
|
25257
|
+
tokenName;
|
|
25258
|
+
storage;
|
|
25259
|
+
token;
|
|
25262
25260
|
constructor(opts) {
|
|
25263
25261
|
this.adapter = opts?.adapter || adapter;
|
|
25262
|
+
this.tokenName = opts?.tokenName || "token";
|
|
25263
|
+
this.storage = opts?.storage || globalThis?.localStorage;
|
|
25264
25264
|
const defaultURL = opts?.isClient ? "/client/router" : "/api/router";
|
|
25265
25265
|
this.url = opts?.url || defaultURL;
|
|
25266
|
+
if (this.url.startsWith("http")) {
|
|
25267
|
+
const urlObj = new URL(this.url);
|
|
25268
|
+
this.baseURL = urlObj.origin;
|
|
25269
|
+
}
|
|
25270
|
+
this.baseURL = opts?.baseURL || this.baseURL;
|
|
25266
25271
|
this.headers = opts?.headers || {
|
|
25267
25272
|
"Content-Type": "application/json"
|
|
25268
25273
|
};
|
|
@@ -25271,7 +25276,7 @@ class Query {
|
|
|
25271
25276
|
this.beforeRequest = opts.beforeRequest;
|
|
25272
25277
|
} else {
|
|
25273
25278
|
this.beforeRequest = async (opts2) => {
|
|
25274
|
-
const token =
|
|
25279
|
+
const token = this.token || this.storage?.getItem?.(this.tokenName);
|
|
25275
25280
|
if (token) {
|
|
25276
25281
|
opts2.headers = {
|
|
25277
25282
|
...opts2.headers,
|
|
@@ -25293,7 +25298,6 @@ class Query {
|
|
|
25293
25298
|
}
|
|
25294
25299
|
async post(body, options) {
|
|
25295
25300
|
const url = options?.url || this.url;
|
|
25296
|
-
console.log("query post", url, body, options);
|
|
25297
25301
|
const { headers, adapter: adapter2, beforeRequest, afterResponse, timeout, ...rest } = options || {};
|
|
25298
25302
|
const _headers = { ...this.headers, ...headers };
|
|
25299
25303
|
const _adapter = adapter2 || this.adapter;
|
|
@@ -25307,13 +25311,20 @@ class Query {
|
|
|
25307
25311
|
timeout: _timeout,
|
|
25308
25312
|
...rest
|
|
25309
25313
|
};
|
|
25314
|
+
const isStartsWithHttp = req.url.startsWith("http");
|
|
25315
|
+
if (!isStartsWithHttp) {
|
|
25316
|
+
if (this.baseURL) {
|
|
25317
|
+
const baseURL = new URL(this.baseURL || globalThis?.location?.origin).origin;
|
|
25318
|
+
req.url = baseURL + req.url;
|
|
25319
|
+
}
|
|
25320
|
+
}
|
|
25310
25321
|
try {
|
|
25311
25322
|
if (_beforeRequest) {
|
|
25312
25323
|
const res = await _beforeRequest(req);
|
|
25313
25324
|
if (res === false) {
|
|
25314
25325
|
return wrapperError({
|
|
25315
25326
|
code: 500,
|
|
25316
|
-
message: "
|
|
25327
|
+
message: "请求取消",
|
|
25317
25328
|
req
|
|
25318
25329
|
});
|
|
25319
25330
|
}
|
|
@@ -25322,13 +25333,13 @@ class Query {
|
|
|
25322
25333
|
console.error("request beforeFn error", e, req);
|
|
25323
25334
|
return wrapperError({
|
|
25324
25335
|
code: 500,
|
|
25325
|
-
message: "
|
|
25336
|
+
message: "请求在请求前处理时发生错误",
|
|
25326
25337
|
req
|
|
25327
25338
|
});
|
|
25328
25339
|
}
|
|
25329
25340
|
if (this.stop && !options?.noStop) {
|
|
25330
25341
|
const that = this;
|
|
25331
|
-
await new Promise((resolve) => {
|
|
25342
|
+
const res = await new Promise((resolve) => {
|
|
25332
25343
|
let timer = 0;
|
|
25333
25344
|
const detect = setInterval(() => {
|
|
25334
25345
|
if (!that.stop) {
|
|
@@ -25336,11 +25347,20 @@ class Query {
|
|
|
25336
25347
|
resolve(true);
|
|
25337
25348
|
}
|
|
25338
25349
|
timer++;
|
|
25339
|
-
if (timer >
|
|
25340
|
-
console.error("
|
|
25350
|
+
if (timer > 5) {
|
|
25351
|
+
console.error("等待请求失败:", req.url, timer);
|
|
25352
|
+
clearInterval(detect);
|
|
25353
|
+
resolve(false);
|
|
25341
25354
|
}
|
|
25342
25355
|
}, 1000);
|
|
25343
25356
|
});
|
|
25357
|
+
if (!res) {
|
|
25358
|
+
return wrapperError({
|
|
25359
|
+
code: 500,
|
|
25360
|
+
message: "请求取消,可能是因为用户未登录或者token过期",
|
|
25361
|
+
req
|
|
25362
|
+
});
|
|
25363
|
+
}
|
|
25344
25364
|
}
|
|
25345
25365
|
return _adapter(req).then(async (res) => {
|
|
25346
25366
|
try {
|
|
@@ -25353,10 +25373,10 @@ class Query {
|
|
|
25353
25373
|
}
|
|
25354
25374
|
return res;
|
|
25355
25375
|
} catch (e) {
|
|
25356
|
-
console.error("
|
|
25376
|
+
console.error("请求在响应后处理时发生错误", e, req);
|
|
25357
25377
|
return wrapperError({
|
|
25358
25378
|
code: 500,
|
|
25359
|
-
message: "
|
|
25379
|
+
message: "请求在响应后处理时发生错误",
|
|
25360
25380
|
req
|
|
25361
25381
|
});
|
|
25362
25382
|
}
|
|
@@ -25394,23 +25414,17 @@ class Query {
|
|
|
25394
25414
|
}
|
|
25395
25415
|
}
|
|
25396
25416
|
|
|
25397
|
-
// node_modules/.pnpm/@kevisual+query@0.0.
|
|
25417
|
+
// node_modules/.pnpm/@kevisual+query@0.0.49/node_modules/@kevisual/query/dist/query-browser.js
|
|
25398
25418
|
var isTextForContentType2 = (contentType) => {
|
|
25399
25419
|
if (!contentType)
|
|
25400
25420
|
return false;
|
|
25401
|
-
const textTypes = ["text/", "xml", "html", "javascript", "css", "csv", "plain", "x-www-form-urlencoded", "md"];
|
|
25421
|
+
const textTypes = ["text/", "xml", "html", "javascript", "css", "csv", "plain", "x-www-form-urlencoded", "md", "json"];
|
|
25402
25422
|
return textTypes.some((type) => contentType.includes(type));
|
|
25403
25423
|
};
|
|
25404
25424
|
var adapter2 = async (opts = {}, overloadOpts) => {
|
|
25405
25425
|
const controller = new AbortController;
|
|
25406
25426
|
const signal = controller.signal;
|
|
25407
25427
|
const isPostFile = opts.isPostFile || false;
|
|
25408
|
-
let responseType = opts.responseType || "json";
|
|
25409
|
-
if (opts.isBlob) {
|
|
25410
|
-
responseType = "blob";
|
|
25411
|
-
} else if (opts.isText) {
|
|
25412
|
-
responseType = "text";
|
|
25413
|
-
}
|
|
25414
25428
|
const timeout = opts.timeout || 60000 * 3;
|
|
25415
25429
|
const timer = setTimeout(() => {
|
|
25416
25430
|
controller.abort();
|
|
@@ -25469,21 +25483,31 @@ var adapter2 = async (opts = {}, overloadOpts) => {
|
|
|
25469
25483
|
headers
|
|
25470
25484
|
}).then(async (response) => {
|
|
25471
25485
|
const contentType = response.headers.get("Content-Type");
|
|
25472
|
-
if (responseType === "blob") {
|
|
25473
|
-
return await response.blob();
|
|
25474
|
-
}
|
|
25475
|
-
const isText = responseType === "text";
|
|
25476
25486
|
const isJson = contentType && contentType.includes("application/json");
|
|
25477
|
-
|
|
25478
|
-
|
|
25487
|
+
const isSuccess = response.ok;
|
|
25488
|
+
if (isJson) {
|
|
25489
|
+
const json = await response.json();
|
|
25490
|
+
if (json?.code) {
|
|
25491
|
+
return json;
|
|
25492
|
+
}
|
|
25493
|
+
return {
|
|
25494
|
+
code: isSuccess ? 200 : response.status,
|
|
25495
|
+
status: response.status,
|
|
25496
|
+
data: json
|
|
25497
|
+
};
|
|
25479
25498
|
} else if (isTextForContentType2(contentType)) {
|
|
25480
25499
|
return {
|
|
25481
|
-
code: response.status,
|
|
25500
|
+
code: isSuccess ? 200 : response.status,
|
|
25482
25501
|
status: response.status,
|
|
25483
25502
|
data: await response.text()
|
|
25484
25503
|
};
|
|
25485
25504
|
} else {
|
|
25486
|
-
return
|
|
25505
|
+
return {
|
|
25506
|
+
code: isSuccess ? 200 : response.status,
|
|
25507
|
+
status: response.status,
|
|
25508
|
+
data: "非文本非JSON响应, 请手动处理response。",
|
|
25509
|
+
response
|
|
25510
|
+
};
|
|
25487
25511
|
}
|
|
25488
25512
|
}).catch((err) => {
|
|
25489
25513
|
if (err.name === "AbortError") {
|
|
@@ -25503,16 +25527,14 @@ var adapter2 = async (opts = {}, overloadOpts) => {
|
|
|
25503
25527
|
var wrapperError2 = ({ code, message }) => {
|
|
25504
25528
|
const result = {
|
|
25505
25529
|
code: code || 500,
|
|
25506
|
-
|
|
25507
|
-
message: message || "api request error",
|
|
25508
|
-
showError: (fn) => {},
|
|
25509
|
-
noMsg: true
|
|
25530
|
+
message: message || "请求错误"
|
|
25510
25531
|
};
|
|
25511
25532
|
return result;
|
|
25512
25533
|
};
|
|
25513
25534
|
|
|
25514
25535
|
class Query2 {
|
|
25515
25536
|
adapter;
|
|
25537
|
+
baseURL;
|
|
25516
25538
|
url;
|
|
25517
25539
|
beforeRequest;
|
|
25518
25540
|
afterResponse;
|
|
@@ -25520,11 +25542,20 @@ class Query2 {
|
|
|
25520
25542
|
timeout;
|
|
25521
25543
|
stop;
|
|
25522
25544
|
qws;
|
|
25523
|
-
|
|
25545
|
+
tokenName;
|
|
25546
|
+
storage;
|
|
25547
|
+
token;
|
|
25524
25548
|
constructor(opts) {
|
|
25525
25549
|
this.adapter = opts?.adapter || adapter2;
|
|
25550
|
+
this.tokenName = opts?.tokenName || "token";
|
|
25551
|
+
this.storage = opts?.storage || globalThis?.localStorage;
|
|
25526
25552
|
const defaultURL = opts?.isClient ? "/client/router" : "/api/router";
|
|
25527
25553
|
this.url = opts?.url || defaultURL;
|
|
25554
|
+
if (this.url.startsWith("http")) {
|
|
25555
|
+
const urlObj = new URL(this.url);
|
|
25556
|
+
this.baseURL = urlObj.origin;
|
|
25557
|
+
}
|
|
25558
|
+
this.baseURL = opts?.baseURL || this.baseURL;
|
|
25528
25559
|
this.headers = opts?.headers || {
|
|
25529
25560
|
"Content-Type": "application/json"
|
|
25530
25561
|
};
|
|
@@ -25533,7 +25564,7 @@ class Query2 {
|
|
|
25533
25564
|
this.beforeRequest = opts.beforeRequest;
|
|
25534
25565
|
} else {
|
|
25535
25566
|
this.beforeRequest = async (opts2) => {
|
|
25536
|
-
const token =
|
|
25567
|
+
const token = this.token || this.storage?.getItem?.(this.tokenName);
|
|
25537
25568
|
if (token) {
|
|
25538
25569
|
opts2.headers = {
|
|
25539
25570
|
...opts2.headers,
|
|
@@ -25555,7 +25586,6 @@ class Query2 {
|
|
|
25555
25586
|
}
|
|
25556
25587
|
async post(body, options) {
|
|
25557
25588
|
const url = options?.url || this.url;
|
|
25558
|
-
console.log("query post", url, body, options);
|
|
25559
25589
|
const { headers, adapter: adapter22, beforeRequest, afterResponse, timeout, ...rest } = options || {};
|
|
25560
25590
|
const _headers = { ...this.headers, ...headers };
|
|
25561
25591
|
const _adapter = adapter22 || this.adapter;
|
|
@@ -25569,13 +25599,20 @@ class Query2 {
|
|
|
25569
25599
|
timeout: _timeout,
|
|
25570
25600
|
...rest
|
|
25571
25601
|
};
|
|
25602
|
+
const isStartsWithHttp = req.url.startsWith("http");
|
|
25603
|
+
if (!isStartsWithHttp) {
|
|
25604
|
+
if (this.baseURL) {
|
|
25605
|
+
const baseURL = new URL(this.baseURL || globalThis?.location?.origin).origin;
|
|
25606
|
+
req.url = baseURL + req.url;
|
|
25607
|
+
}
|
|
25608
|
+
}
|
|
25572
25609
|
try {
|
|
25573
25610
|
if (_beforeRequest) {
|
|
25574
25611
|
const res = await _beforeRequest(req);
|
|
25575
25612
|
if (res === false) {
|
|
25576
25613
|
return wrapperError2({
|
|
25577
25614
|
code: 500,
|
|
25578
|
-
message: "
|
|
25615
|
+
message: "请求取消",
|
|
25579
25616
|
req
|
|
25580
25617
|
});
|
|
25581
25618
|
}
|
|
@@ -25584,13 +25621,13 @@ class Query2 {
|
|
|
25584
25621
|
console.error("request beforeFn error", e, req);
|
|
25585
25622
|
return wrapperError2({
|
|
25586
25623
|
code: 500,
|
|
25587
|
-
message: "
|
|
25624
|
+
message: "请求在请求前处理时发生错误",
|
|
25588
25625
|
req
|
|
25589
25626
|
});
|
|
25590
25627
|
}
|
|
25591
25628
|
if (this.stop && !options?.noStop) {
|
|
25592
25629
|
const that = this;
|
|
25593
|
-
await new Promise((resolve) => {
|
|
25630
|
+
const res = await new Promise((resolve) => {
|
|
25594
25631
|
let timer = 0;
|
|
25595
25632
|
const detect = setInterval(() => {
|
|
25596
25633
|
if (!that.stop) {
|
|
@@ -25598,11 +25635,20 @@ class Query2 {
|
|
|
25598
25635
|
resolve(true);
|
|
25599
25636
|
}
|
|
25600
25637
|
timer++;
|
|
25601
|
-
if (timer >
|
|
25602
|
-
console.error("
|
|
25638
|
+
if (timer > 5) {
|
|
25639
|
+
console.error("等待请求失败:", req.url, timer);
|
|
25640
|
+
clearInterval(detect);
|
|
25641
|
+
resolve(false);
|
|
25603
25642
|
}
|
|
25604
25643
|
}, 1000);
|
|
25605
25644
|
});
|
|
25645
|
+
if (!res) {
|
|
25646
|
+
return wrapperError2({
|
|
25647
|
+
code: 500,
|
|
25648
|
+
message: "请求取消,可能是因为用户未登录或者token过期",
|
|
25649
|
+
req
|
|
25650
|
+
});
|
|
25651
|
+
}
|
|
25606
25652
|
}
|
|
25607
25653
|
return _adapter(req).then(async (res) => {
|
|
25608
25654
|
try {
|
|
@@ -25615,10 +25661,10 @@ class Query2 {
|
|
|
25615
25661
|
}
|
|
25616
25662
|
return res;
|
|
25617
25663
|
} catch (e) {
|
|
25618
|
-
console.error("
|
|
25664
|
+
console.error("请求在响应后处理时发生错误", e, req);
|
|
25619
25665
|
return wrapperError2({
|
|
25620
25666
|
code: 500,
|
|
25621
|
-
message: "
|
|
25667
|
+
message: "请求在响应后处理时发生错误",
|
|
25622
25668
|
req
|
|
25623
25669
|
});
|
|
25624
25670
|
}
|
|
@@ -25681,13 +25727,8 @@ class BaseQuery {
|
|
|
25681
25727
|
}
|
|
25682
25728
|
}
|
|
25683
25729
|
|
|
25684
|
-
// node_modules/.pnpm/@kevisual+
|
|
25685
|
-
|
|
25686
|
-
import { join, dirname } from "path";
|
|
25687
|
-
import fs4 from "fs";
|
|
25688
|
-
import { readFileSync, writeFileSync, accessSync } from "fs";
|
|
25689
|
-
import { readFile, writeFile, unlink, mkdir } from "fs/promises";
|
|
25690
|
-
var LoginCacheStore = class {
|
|
25730
|
+
// node_modules/.pnpm/@kevisual+api@0.0.52_@types+react@19.2.10_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/@kevisual/api/query/query-login/login-cache.ts
|
|
25731
|
+
class LoginCacheStore {
|
|
25691
25732
|
cache;
|
|
25692
25733
|
name;
|
|
25693
25734
|
cacheData;
|
|
@@ -25745,6 +25786,8 @@ var LoginCacheStore = class {
|
|
|
25745
25786
|
this.cacheData.id = user.id;
|
|
25746
25787
|
this.cacheData.accessToken = user.accessToken;
|
|
25747
25788
|
this.cacheData.refreshToken = user.refreshToken;
|
|
25789
|
+
this.cacheData.accessTokenExpiresIn = user.accessTokenExpiresIn;
|
|
25790
|
+
this.cacheData.createdAt = user.createdAt;
|
|
25748
25791
|
await this.setValue(this.cacheData);
|
|
25749
25792
|
}
|
|
25750
25793
|
getCurrentUser() {
|
|
@@ -25782,1408 +25825,1479 @@ var LoginCacheStore = class {
|
|
|
25782
25825
|
this.cacheData.refreshToken = undefined;
|
|
25783
25826
|
await this.setValue(this.cacheData);
|
|
25784
25827
|
}
|
|
25785
|
-
}
|
|
25786
|
-
|
|
25787
|
-
|
|
25788
|
-
|
|
25789
|
-
|
|
25790
|
-
|
|
25791
|
-
|
|
25792
|
-
|
|
25793
|
-
|
|
25794
|
-
|
|
25795
|
-
|
|
25796
|
-
|
|
25797
|
-
|
|
25798
|
-
|
|
25799
|
-
|
|
25800
|
-
|
|
25801
|
-
|
|
25802
|
-
|
|
25803
|
-
|
|
25804
|
-
}
|
|
25805
|
-
async init() {
|
|
25806
|
-
await this.cacheStore.init();
|
|
25807
|
-
this.load = true;
|
|
25808
|
-
this.onLoad?.();
|
|
25809
|
-
}
|
|
25810
|
-
async post(data, opts) {
|
|
25811
|
-
try {
|
|
25812
|
-
return this.query.post({ path: "user", ...data }, opts);
|
|
25813
|
-
} catch (error) {
|
|
25814
|
-
console.log("error", error);
|
|
25815
|
-
return {
|
|
25816
|
-
code: 400
|
|
25817
|
-
};
|
|
25818
|
-
}
|
|
25819
|
-
}
|
|
25820
|
-
async login(data) {
|
|
25821
|
-
const res = await this.post({ key: "login", ...data });
|
|
25822
|
-
if (res.code === 200) {
|
|
25823
|
-
const { accessToken, refreshToken } = res?.data || {};
|
|
25824
|
-
this.storage.setItem("token", accessToken || "");
|
|
25825
|
-
await this.beforeSetLoginUser({ accessToken, refreshToken });
|
|
25826
|
-
}
|
|
25827
|
-
return res;
|
|
25828
|
-
}
|
|
25829
|
-
async loginByCode(data) {
|
|
25830
|
-
const res = await this.post({ path: "sms", key: "login", data });
|
|
25831
|
-
if (res.code === 200) {
|
|
25832
|
-
const { accessToken, refreshToken } = res?.data || {};
|
|
25833
|
-
this.storage.setItem("token", accessToken || "");
|
|
25834
|
-
await this.beforeSetLoginUser({ accessToken, refreshToken });
|
|
25828
|
+
}
|
|
25829
|
+
|
|
25830
|
+
// node_modules/.pnpm/@kevisual+load@0.0.6/node_modules/@kevisual/load/dist/load.js
|
|
25831
|
+
function getDefaultExportFromCjs3(x) {
|
|
25832
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
25833
|
+
}
|
|
25834
|
+
var eventemitter33 = { exports: {} };
|
|
25835
|
+
var hasRequiredEventemitter33;
|
|
25836
|
+
function requireEventemitter33() {
|
|
25837
|
+
if (hasRequiredEventemitter33)
|
|
25838
|
+
return eventemitter33.exports;
|
|
25839
|
+
hasRequiredEventemitter33 = 1;
|
|
25840
|
+
(function(module) {
|
|
25841
|
+
var has = Object.prototype.hasOwnProperty, prefix = "~";
|
|
25842
|
+
function Events() {}
|
|
25843
|
+
if (Object.create) {
|
|
25844
|
+
Events.prototype = Object.create(null);
|
|
25845
|
+
if (!new Events().__proto__)
|
|
25846
|
+
prefix = false;
|
|
25835
25847
|
}
|
|
25836
|
-
|
|
25837
|
-
|
|
25838
|
-
|
|
25839
|
-
|
|
25840
|
-
this.storage.setItem("token", accessToken || "");
|
|
25841
|
-
await this.beforeSetLoginUser({ accessToken, refreshToken });
|
|
25842
|
-
}
|
|
25843
|
-
async loginByWechat(data) {
|
|
25844
|
-
const res = await this.post({ path: "wx", key: "open-login", code: data.code });
|
|
25845
|
-
if (res.code === 200) {
|
|
25846
|
-
const { accessToken, refreshToken } = res?.data || {};
|
|
25847
|
-
this.storage.setItem("token", accessToken || "");
|
|
25848
|
-
await this.beforeSetLoginUser({ accessToken, refreshToken });
|
|
25848
|
+
function EE(fn, context, once) {
|
|
25849
|
+
this.fn = fn;
|
|
25850
|
+
this.context = context;
|
|
25851
|
+
this.once = once || false;
|
|
25849
25852
|
}
|
|
25850
|
-
|
|
25851
|
-
|
|
25852
|
-
|
|
25853
|
-
const url = new URL(window.location.href);
|
|
25854
|
-
const code = url.searchParams.get("code");
|
|
25855
|
-
const state = url.searchParams.get("state");
|
|
25856
|
-
if (code && state) {
|
|
25857
|
-
const res = await this.loginByWechat({ code });
|
|
25858
|
-
if (res.code === 200) {
|
|
25859
|
-
onSuccess?.(res.data);
|
|
25860
|
-
} else {
|
|
25861
|
-
onError?.(res);
|
|
25853
|
+
function addListener(emitter, event, fn, context, once) {
|
|
25854
|
+
if (typeof fn !== "function") {
|
|
25855
|
+
throw new TypeError("The listener must be a function");
|
|
25862
25856
|
}
|
|
25857
|
+
var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
|
|
25858
|
+
if (!emitter._events[evt])
|
|
25859
|
+
emitter._events[evt] = listener, emitter._eventsCount++;
|
|
25860
|
+
else if (!emitter._events[evt].fn)
|
|
25861
|
+
emitter._events[evt].push(listener);
|
|
25862
|
+
else
|
|
25863
|
+
emitter._events[evt] = [emitter._events[evt], listener];
|
|
25864
|
+
return emitter;
|
|
25863
25865
|
}
|
|
25864
|
-
|
|
25865
|
-
|
|
25866
|
-
|
|
25867
|
-
|
|
25868
|
-
|
|
25869
|
-
const user = resUser.data;
|
|
25870
|
-
if (user) {
|
|
25871
|
-
this.cacheStore.setLoginUser({
|
|
25872
|
-
user,
|
|
25873
|
-
id: user.id,
|
|
25874
|
-
accessToken,
|
|
25875
|
-
refreshToken
|
|
25876
|
-
});
|
|
25877
|
-
} else {
|
|
25878
|
-
console.error("登录失败");
|
|
25879
|
-
}
|
|
25880
|
-
}
|
|
25866
|
+
function clearEvent(emitter, evt) {
|
|
25867
|
+
if (--emitter._eventsCount === 0)
|
|
25868
|
+
emitter._events = new Events;
|
|
25869
|
+
else
|
|
25870
|
+
delete emitter._events[evt];
|
|
25881
25871
|
}
|
|
25882
|
-
|
|
25883
|
-
|
|
25884
|
-
|
|
25885
|
-
let data = { refreshToken: _refreshToken };
|
|
25886
|
-
if (!_refreshToken) {
|
|
25887
|
-
await this.cacheStore.clearCurrentUser();
|
|
25888
|
-
return {
|
|
25889
|
-
code: 401,
|
|
25890
|
-
message: "请先登录",
|
|
25891
|
-
data: {}
|
|
25892
|
-
};
|
|
25872
|
+
function EventEmitter3() {
|
|
25873
|
+
this._events = new Events;
|
|
25874
|
+
this._eventsCount = 0;
|
|
25893
25875
|
}
|
|
25894
|
-
|
|
25895
|
-
|
|
25896
|
-
|
|
25897
|
-
return
|
|
25876
|
+
EventEmitter3.prototype.eventNames = function eventNames() {
|
|
25877
|
+
var names = [], events, name;
|
|
25878
|
+
if (this._eventsCount === 0)
|
|
25879
|
+
return names;
|
|
25880
|
+
for (name in events = this._events) {
|
|
25881
|
+
if (has.call(events, name))
|
|
25882
|
+
names.push(prefix ? name.slice(1) : name);
|
|
25898
25883
|
}
|
|
25899
|
-
|
|
25900
|
-
|
|
25901
|
-
|
|
25902
|
-
|
|
25903
|
-
|
|
25904
|
-
|
|
25905
|
-
|
|
25906
|
-
|
|
25907
|
-
|
|
25908
|
-
|
|
25909
|
-
|
|
25910
|
-
|
|
25911
|
-
|
|
25912
|
-
|
|
25913
|
-
|
|
25914
|
-
|
|
25915
|
-
|
|
25916
|
-
|
|
25917
|
-
|
|
25918
|
-
|
|
25919
|
-
|
|
25920
|
-
|
|
25921
|
-
|
|
25922
|
-
|
|
25923
|
-
|
|
25924
|
-
|
|
25925
|
-
|
|
25926
|
-
|
|
25884
|
+
if (Object.getOwnPropertySymbols) {
|
|
25885
|
+
return names.concat(Object.getOwnPropertySymbols(events));
|
|
25886
|
+
}
|
|
25887
|
+
return names;
|
|
25888
|
+
};
|
|
25889
|
+
EventEmitter3.prototype.listeners = function listeners(event) {
|
|
25890
|
+
var evt = prefix ? prefix + event : event, handlers = this._events[evt];
|
|
25891
|
+
if (!handlers)
|
|
25892
|
+
return [];
|
|
25893
|
+
if (handlers.fn)
|
|
25894
|
+
return [handlers.fn];
|
|
25895
|
+
for (var i = 0, l = handlers.length, ee = new Array(l);i < l; i++) {
|
|
25896
|
+
ee[i] = handlers[i].fn;
|
|
25897
|
+
}
|
|
25898
|
+
return ee;
|
|
25899
|
+
};
|
|
25900
|
+
EventEmitter3.prototype.listenerCount = function listenerCount(event) {
|
|
25901
|
+
var evt = prefix ? prefix + event : event, listeners = this._events[evt];
|
|
25902
|
+
if (!listeners)
|
|
25903
|
+
return 0;
|
|
25904
|
+
if (listeners.fn)
|
|
25905
|
+
return 1;
|
|
25906
|
+
return listeners.length;
|
|
25907
|
+
};
|
|
25908
|
+
EventEmitter3.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
25909
|
+
var evt = prefix ? prefix + event : event;
|
|
25910
|
+
if (!this._events[evt])
|
|
25911
|
+
return false;
|
|
25912
|
+
var listeners = this._events[evt], len = arguments.length, args, i;
|
|
25913
|
+
if (listeners.fn) {
|
|
25914
|
+
if (listeners.once)
|
|
25915
|
+
this.removeListener(event, listeners.fn, undefined, true);
|
|
25916
|
+
switch (len) {
|
|
25917
|
+
case 1:
|
|
25918
|
+
return listeners.fn.call(listeners.context), true;
|
|
25919
|
+
case 2:
|
|
25920
|
+
return listeners.fn.call(listeners.context, a1), true;
|
|
25921
|
+
case 3:
|
|
25922
|
+
return listeners.fn.call(listeners.context, a1, a2), true;
|
|
25923
|
+
case 4:
|
|
25924
|
+
return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
25925
|
+
case 5:
|
|
25926
|
+
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
25927
|
+
case 6:
|
|
25928
|
+
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
25927
25929
|
}
|
|
25928
|
-
|
|
25930
|
+
for (i = 1, args = new Array(len - 1);i < len; i++) {
|
|
25931
|
+
args[i - 1] = arguments[i];
|
|
25932
|
+
}
|
|
25933
|
+
listeners.fn.apply(listeners.context, args);
|
|
25934
|
+
} else {
|
|
25935
|
+
var length = listeners.length, j;
|
|
25936
|
+
for (i = 0;i < length; i++) {
|
|
25937
|
+
if (listeners[i].once)
|
|
25938
|
+
this.removeListener(event, listeners[i].fn, undefined, true);
|
|
25939
|
+
switch (len) {
|
|
25940
|
+
case 1:
|
|
25941
|
+
listeners[i].fn.call(listeners[i].context);
|
|
25942
|
+
break;
|
|
25943
|
+
case 2:
|
|
25944
|
+
listeners[i].fn.call(listeners[i].context, a1);
|
|
25945
|
+
break;
|
|
25946
|
+
case 3:
|
|
25947
|
+
listeners[i].fn.call(listeners[i].context, a1, a2);
|
|
25948
|
+
break;
|
|
25949
|
+
case 4:
|
|
25950
|
+
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
|
|
25951
|
+
break;
|
|
25952
|
+
default:
|
|
25953
|
+
if (!args)
|
|
25954
|
+
for (j = 1, args = new Array(len - 1);j < len; j++) {
|
|
25955
|
+
args[j - 1] = arguments[j];
|
|
25956
|
+
}
|
|
25957
|
+
listeners[i].fn.apply(listeners[i].context, args);
|
|
25958
|
+
}
|
|
25959
|
+
}
|
|
25960
|
+
}
|
|
25961
|
+
return true;
|
|
25962
|
+
};
|
|
25963
|
+
EventEmitter3.prototype.on = function on(event, fn, context) {
|
|
25964
|
+
return addListener(this, event, fn, context, false);
|
|
25965
|
+
};
|
|
25966
|
+
EventEmitter3.prototype.once = function once(event, fn, context) {
|
|
25967
|
+
return addListener(this, event, fn, context, true);
|
|
25968
|
+
};
|
|
25969
|
+
EventEmitter3.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
25970
|
+
var evt = prefix ? prefix + event : event;
|
|
25971
|
+
if (!this._events[evt])
|
|
25972
|
+
return this;
|
|
25973
|
+
if (!fn) {
|
|
25974
|
+
clearEvent(this, evt);
|
|
25975
|
+
return this;
|
|
25976
|
+
}
|
|
25977
|
+
var listeners = this._events[evt];
|
|
25978
|
+
if (listeners.fn) {
|
|
25979
|
+
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
|
|
25980
|
+
clearEvent(this, evt);
|
|
25981
|
+
}
|
|
25982
|
+
} else {
|
|
25983
|
+
for (var i = 0, events = [], length = listeners.length;i < length; i++) {
|
|
25984
|
+
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
|
|
25985
|
+
events.push(listeners[i]);
|
|
25986
|
+
}
|
|
25987
|
+
}
|
|
25988
|
+
if (events.length)
|
|
25989
|
+
this._events[evt] = events.length === 1 ? events[0] : events;
|
|
25990
|
+
else
|
|
25991
|
+
clearEvent(this, evt);
|
|
25992
|
+
}
|
|
25993
|
+
return this;
|
|
25994
|
+
};
|
|
25995
|
+
EventEmitter3.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
25996
|
+
var evt;
|
|
25997
|
+
if (event) {
|
|
25998
|
+
evt = prefix ? prefix + event : event;
|
|
25999
|
+
if (this._events[evt])
|
|
26000
|
+
clearEvent(this, evt);
|
|
26001
|
+
} else {
|
|
26002
|
+
this._events = new Events;
|
|
26003
|
+
this._eventsCount = 0;
|
|
25929
26004
|
}
|
|
26005
|
+
return this;
|
|
26006
|
+
};
|
|
26007
|
+
EventEmitter3.prototype.off = EventEmitter3.prototype.removeListener;
|
|
26008
|
+
EventEmitter3.prototype.addListener = EventEmitter3.prototype.on;
|
|
26009
|
+
EventEmitter3.prefixed = prefix;
|
|
26010
|
+
EventEmitter3.EventEmitter = EventEmitter3;
|
|
26011
|
+
{
|
|
26012
|
+
module.exports = EventEmitter3;
|
|
25930
26013
|
}
|
|
25931
|
-
|
|
25932
|
-
|
|
25933
|
-
|
|
25934
|
-
|
|
25935
|
-
|
|
25936
|
-
|
|
25937
|
-
|
|
25938
|
-
|
|
26014
|
+
})(eventemitter33);
|
|
26015
|
+
return eventemitter33.exports;
|
|
26016
|
+
}
|
|
26017
|
+
var eventemitter3Exports3 = requireEventemitter33();
|
|
26018
|
+
var EventEmitter3 = /* @__PURE__ */ getDefaultExportFromCjs3(eventemitter3Exports3);
|
|
26019
|
+
var reRunFn3 = (promiseOpts) => {
|
|
26020
|
+
const timeout = promiseOpts.timeout || 5 * 60 * 1000;
|
|
26021
|
+
const interval = promiseOpts.interval || 1000;
|
|
26022
|
+
const checkSuccess = promiseOpts?.checkSuccess || (() => true);
|
|
26023
|
+
const signal = promiseOpts.signal;
|
|
26024
|
+
return new Promise(async (resolve, reject) => {
|
|
26025
|
+
let intervalId;
|
|
26026
|
+
let timeoutId = setTimeout(() => {
|
|
26027
|
+
clearTimeout(intervalId);
|
|
26028
|
+
resolve({
|
|
26029
|
+
code: 500,
|
|
26030
|
+
message: "timeout"
|
|
26031
|
+
});
|
|
26032
|
+
}, timeout);
|
|
26033
|
+
const fn = promiseOpts.fn || (() => true);
|
|
26034
|
+
const runFn = async () => {
|
|
26035
|
+
if (signal?.aborted) {
|
|
26036
|
+
clearInterval(intervalId);
|
|
26037
|
+
clearTimeout(timeoutId);
|
|
26038
|
+
return resolve({
|
|
26039
|
+
code: 499,
|
|
26040
|
+
message: "operation cancelled"
|
|
26041
|
+
});
|
|
25939
26042
|
}
|
|
25940
|
-
|
|
25941
|
-
|
|
25942
|
-
|
|
25943
|
-
|
|
25944
|
-
|
|
25945
|
-
|
|
26043
|
+
const res = await fn();
|
|
26044
|
+
if (!!checkSuccess(res)) {
|
|
26045
|
+
clearInterval(intervalId);
|
|
26046
|
+
clearTimeout(timeoutId);
|
|
26047
|
+
resolve({
|
|
26048
|
+
code: 200,
|
|
26049
|
+
data: res
|
|
26050
|
+
});
|
|
26051
|
+
} else {
|
|
26052
|
+
setTimeout(() => {
|
|
26053
|
+
runFn();
|
|
26054
|
+
}, interval);
|
|
25946
26055
|
}
|
|
25947
|
-
|
|
25948
|
-
|
|
25949
|
-
|
|
26056
|
+
};
|
|
26057
|
+
if (signal) {
|
|
26058
|
+
signal.addEventListener("abort", () => {
|
|
26059
|
+
clearInterval(intervalId);
|
|
26060
|
+
clearTimeout(timeoutId);
|
|
26061
|
+
resolve({
|
|
26062
|
+
code: 499,
|
|
26063
|
+
message: "operation cancelled"
|
|
26064
|
+
});
|
|
26065
|
+
});
|
|
25950
26066
|
}
|
|
26067
|
+
runFn();
|
|
26068
|
+
});
|
|
26069
|
+
};
|
|
26070
|
+
|
|
26071
|
+
class BaseLoad3 {
|
|
26072
|
+
modules = new Map;
|
|
26073
|
+
event;
|
|
26074
|
+
loading;
|
|
26075
|
+
static reRunFn = reRunFn3;
|
|
26076
|
+
timeout = 5 * 60 * 1000;
|
|
26077
|
+
constructor() {
|
|
26078
|
+
this.event = new EventEmitter3;
|
|
26079
|
+
this.loading = false;
|
|
25951
26080
|
}
|
|
25952
|
-
|
|
25953
|
-
const
|
|
25954
|
-
|
|
25955
|
-
|
|
25956
|
-
|
|
25957
|
-
|
|
25958
|
-
|
|
26081
|
+
listenKey(key, listenOpts) {
|
|
26082
|
+
const timeout = listenOpts?.timeout ?? this.timeout;
|
|
26083
|
+
return new Promise((resolve) => {
|
|
26084
|
+
const timeoutId = setTimeout(() => {
|
|
26085
|
+
this.event.removeListener(key, onEvent);
|
|
26086
|
+
resolve({
|
|
26087
|
+
code: 500,
|
|
26088
|
+
message: "timeout"
|
|
26089
|
+
});
|
|
26090
|
+
}, timeout);
|
|
26091
|
+
const onEvent = (error) => {
|
|
26092
|
+
clearTimeout(timeoutId);
|
|
26093
|
+
if (error) {
|
|
26094
|
+
return resolve({
|
|
26095
|
+
code: 500,
|
|
26096
|
+
message: error
|
|
26097
|
+
});
|
|
25959
26098
|
}
|
|
25960
|
-
|
|
25961
|
-
|
|
25962
|
-
|
|
25963
|
-
afterResponse: async (response, ctx) => {
|
|
25964
|
-
if (response?.code === 401 && check401 && !token) {
|
|
25965
|
-
return await that.afterCheck401ToRefreshToken(response, ctx);
|
|
26099
|
+
const data = this.modules.get(key);
|
|
26100
|
+
if (data?.loadSuccessClear) {
|
|
26101
|
+
this.remove(key);
|
|
25966
26102
|
}
|
|
25967
|
-
|
|
25968
|
-
|
|
26103
|
+
resolve({
|
|
26104
|
+
code: 200,
|
|
26105
|
+
data: data?.modules
|
|
26106
|
+
});
|
|
26107
|
+
};
|
|
26108
|
+
this.event.once(key, onEvent);
|
|
25969
26109
|
});
|
|
25970
26110
|
}
|
|
25971
|
-
async
|
|
25972
|
-
|
|
25973
|
-
|
|
25974
|
-
|
|
25975
|
-
|
|
25976
|
-
|
|
25977
|
-
|
|
25978
|
-
|
|
25979
|
-
|
|
25980
|
-
|
|
25981
|
-
|
|
25982
|
-
|
|
25983
|
-
|
|
25984
|
-
|
|
25985
|
-
|
|
25986
|
-
|
|
25987
|
-
|
|
25988
|
-
|
|
25989
|
-
|
|
25990
|
-
|
|
26111
|
+
async hasLoaded(key, hasLoadOpts) {
|
|
26112
|
+
if (!key) {
|
|
26113
|
+
return {
|
|
26114
|
+
code: 404,
|
|
26115
|
+
message: "key is required"
|
|
26116
|
+
};
|
|
26117
|
+
}
|
|
26118
|
+
const has = this.modules.has(key);
|
|
26119
|
+
if (!has) {
|
|
26120
|
+
const isExist = hasLoadOpts?.isExist ?? true;
|
|
26121
|
+
const timeout = hasLoadOpts?.timeout ?? this.timeout;
|
|
26122
|
+
if (isExist) {
|
|
26123
|
+
return await this.listenKey(key, { timeout });
|
|
26124
|
+
}
|
|
26125
|
+
return {
|
|
26126
|
+
code: 404
|
|
26127
|
+
};
|
|
26128
|
+
}
|
|
26129
|
+
const data = this.modules.get(key);
|
|
26130
|
+
if (data?.status === "loaded") {
|
|
25991
26131
|
return {
|
|
25992
26132
|
code: 200,
|
|
25993
|
-
data:
|
|
25994
|
-
accessToken: user.accessToken,
|
|
25995
|
-
refreshToken: user.refreshToken
|
|
25996
|
-
},
|
|
25997
|
-
success: true,
|
|
25998
|
-
message: "切换用户成功"
|
|
26133
|
+
data: data.modules
|
|
25999
26134
|
};
|
|
26000
26135
|
}
|
|
26001
|
-
|
|
26002
|
-
|
|
26003
|
-
const { accessToken, refreshToken } = res?.data || {};
|
|
26004
|
-
this.storage.setItem("token", accessToken || "");
|
|
26005
|
-
await this.beforeSetLoginUser({ accessToken, refreshToken });
|
|
26136
|
+
if (data?.status === "loading") {
|
|
26137
|
+
return await this.listenKey(key, { timeout: hasLoadOpts?.timeout ?? this.timeout });
|
|
26006
26138
|
}
|
|
26007
|
-
|
|
26008
|
-
|
|
26009
|
-
|
|
26010
|
-
|
|
26011
|
-
|
|
26012
|
-
|
|
26013
|
-
|
|
26014
|
-
|
|
26015
|
-
|
|
26016
|
-
|
|
26139
|
+
if (data?.status === "error") {
|
|
26140
|
+
return {
|
|
26141
|
+
code: 500,
|
|
26142
|
+
message: "load error"
|
|
26143
|
+
};
|
|
26144
|
+
}
|
|
26145
|
+
if (data?.status === "cancel") {
|
|
26146
|
+
return {
|
|
26147
|
+
code: 499,
|
|
26148
|
+
message: "operation cancelled"
|
|
26149
|
+
};
|
|
26150
|
+
}
|
|
26151
|
+
return {
|
|
26152
|
+
code: 404
|
|
26153
|
+
};
|
|
26017
26154
|
}
|
|
26018
|
-
async
|
|
26019
|
-
const
|
|
26020
|
-
|
|
26021
|
-
|
|
26022
|
-
|
|
26023
|
-
|
|
26024
|
-
|
|
26025
|
-
|
|
26026
|
-
|
|
26027
|
-
|
|
26028
|
-
|
|
26029
|
-
|
|
26030
|
-
|
|
26155
|
+
async loadFn(loadContent, opts) {
|
|
26156
|
+
const key = opts.key;
|
|
26157
|
+
if (!key) {
|
|
26158
|
+
return {
|
|
26159
|
+
code: 404,
|
|
26160
|
+
message: "key is required"
|
|
26161
|
+
};
|
|
26162
|
+
}
|
|
26163
|
+
const newModule = {
|
|
26164
|
+
key: opts.key,
|
|
26165
|
+
status: "loading",
|
|
26166
|
+
loading: true,
|
|
26167
|
+
loadSuccessClear: opts.loadSuccessClear ?? true
|
|
26168
|
+
};
|
|
26169
|
+
let errorMessage = "";
|
|
26170
|
+
try {
|
|
26171
|
+
const isReRun = opts.isReRun ?? false;
|
|
26172
|
+
let res;
|
|
26173
|
+
if (!isReRun) {
|
|
26174
|
+
this.modules.set(key, newModule);
|
|
26175
|
+
res = await loadContent();
|
|
26176
|
+
} else {
|
|
26177
|
+
newModule.controller = new AbortController;
|
|
26178
|
+
const signal = newModule.controller.signal;
|
|
26179
|
+
this.modules.set(key, newModule);
|
|
26180
|
+
const data = await reRunFn3({
|
|
26181
|
+
timeout: opts.timeout,
|
|
26182
|
+
interval: opts.interval,
|
|
26183
|
+
checkSuccess: opts.checkSuccess,
|
|
26184
|
+
fn: loadContent,
|
|
26185
|
+
signal
|
|
26186
|
+
});
|
|
26187
|
+
newModule.controller = null;
|
|
26188
|
+
if (data.code === 499) {
|
|
26189
|
+
newModule.status = "cancel";
|
|
26190
|
+
return {
|
|
26191
|
+
code: 499,
|
|
26192
|
+
message: "operation cancelled"
|
|
26193
|
+
};
|
|
26031
26194
|
}
|
|
26032
|
-
|
|
26195
|
+
if (data.code !== 200) {
|
|
26196
|
+
throw new Error(data.message);
|
|
26197
|
+
}
|
|
26198
|
+
res = data.data;
|
|
26199
|
+
}
|
|
26200
|
+
newModule.modules = res;
|
|
26201
|
+
newModule.status = "loaded";
|
|
26202
|
+
return {
|
|
26203
|
+
code: 200,
|
|
26204
|
+
data: res
|
|
26205
|
+
};
|
|
26206
|
+
} catch (error) {
|
|
26207
|
+
errorMessage = error.message;
|
|
26208
|
+
newModule.status = "error";
|
|
26209
|
+
return {
|
|
26210
|
+
code: 500,
|
|
26211
|
+
message: error
|
|
26212
|
+
};
|
|
26213
|
+
} finally {
|
|
26214
|
+
newModule.loading = false;
|
|
26215
|
+
this.modules.set(opts.key, newModule);
|
|
26216
|
+
if (!errorMessage) {
|
|
26217
|
+
this.event.emit(opts.key);
|
|
26218
|
+
} else {
|
|
26219
|
+
this.event.emit(opts.key, errorMessage);
|
|
26033
26220
|
}
|
|
26034
|
-
});
|
|
26035
|
-
}
|
|
26036
|
-
async checkLoginStatus(token) {
|
|
26037
|
-
const res = await this.post({
|
|
26038
|
-
path: "user",
|
|
26039
|
-
key: "checkLoginStatus",
|
|
26040
|
-
loginToken: token
|
|
26041
|
-
});
|
|
26042
|
-
if (res.code === 200) {
|
|
26043
|
-
const accessToken = res.data?.accessToken;
|
|
26044
|
-
this.storage.setItem("token", accessToken || "");
|
|
26045
|
-
await this.beforeSetLoginUser({ accessToken, refreshToken: res.data?.refreshToken });
|
|
26046
|
-
return res;
|
|
26047
26221
|
}
|
|
26048
|
-
return false;
|
|
26049
26222
|
}
|
|
26050
|
-
|
|
26051
|
-
|
|
26052
|
-
const
|
|
26053
|
-
|
|
26054
|
-
|
|
26055
|
-
|
|
26056
|
-
|
|
26057
|
-
|
|
26058
|
-
|
|
26059
|
-
|
|
26223
|
+
async load(loadContent, opts) {
|
|
26224
|
+
this.loading = true;
|
|
26225
|
+
const key = opts.key;
|
|
26226
|
+
if (!key) {
|
|
26227
|
+
return {
|
|
26228
|
+
code: 404,
|
|
26229
|
+
message: "key is required"
|
|
26230
|
+
};
|
|
26231
|
+
}
|
|
26232
|
+
if (opts?.force) {
|
|
26233
|
+
this.remove(key);
|
|
26234
|
+
}
|
|
26235
|
+
const has = this.modules.has(key);
|
|
26236
|
+
if (has) {
|
|
26237
|
+
return await this.hasLoaded(key);
|
|
26238
|
+
}
|
|
26239
|
+
if (typeof loadContent === "function") {
|
|
26240
|
+
return this.loadFn(loadContent, opts);
|
|
26241
|
+
}
|
|
26242
|
+
console.error("loadContent is not a function and not has loaded");
|
|
26060
26243
|
}
|
|
26061
|
-
|
|
26062
|
-
|
|
26063
|
-
|
|
26064
|
-
|
|
26065
|
-
|
|
26066
|
-
} catch (error) {
|
|
26067
|
-
if (createIfNotExists && isDir) {
|
|
26068
|
-
await mkdir(filePath, { recursive: true });
|
|
26069
|
-
return true;
|
|
26070
|
-
} else if (createIfNotExists && isFile) {
|
|
26071
|
-
await mkdir(dirname(filePath), { recursive: true });
|
|
26072
|
-
return false;
|
|
26244
|
+
remove(key) {
|
|
26245
|
+
const has = this.modules.has(key);
|
|
26246
|
+
if (has) {
|
|
26247
|
+
this.checkRemoveController(key);
|
|
26248
|
+
this.modules.delete(key);
|
|
26073
26249
|
}
|
|
26074
|
-
return false;
|
|
26075
26250
|
}
|
|
26076
|
-
|
|
26077
|
-
|
|
26078
|
-
|
|
26079
|
-
const data = readFileSync(filePath, "utf-8");
|
|
26080
|
-
const jsonData = JSON.parse(data);
|
|
26081
|
-
return jsonData;
|
|
26082
|
-
} catch (error) {
|
|
26083
|
-
return {};
|
|
26251
|
+
emitLoaded(key) {
|
|
26252
|
+
this.checkRemoveController(key);
|
|
26253
|
+
this.event.emit(key);
|
|
26084
26254
|
}
|
|
26085
|
-
|
|
26086
|
-
|
|
26087
|
-
|
|
26088
|
-
|
|
26089
|
-
|
|
26090
|
-
|
|
26091
|
-
|
|
26092
|
-
|
|
26093
|
-
|
|
26094
|
-
|
|
26095
|
-
|
|
26096
|
-
};
|
|
26097
|
-
var StorageNode = class {
|
|
26098
|
-
cacheData;
|
|
26099
|
-
filePath;
|
|
26100
|
-
constructor() {
|
|
26101
|
-
this.cacheData = {};
|
|
26102
|
-
const configDir = join(homedir(), ".config", "envision");
|
|
26103
|
-
const hostname = getHostName();
|
|
26104
|
-
this.filePath = join(configDir, "config", `${hostname}-storage.json`);
|
|
26105
|
-
fileExists(this.filePath, { isFile: true });
|
|
26255
|
+
setModule(key, data, loadData) {
|
|
26256
|
+
const newModule = {
|
|
26257
|
+
key,
|
|
26258
|
+
status: "loaded",
|
|
26259
|
+
loading: false,
|
|
26260
|
+
modules: data || {},
|
|
26261
|
+
...loadData
|
|
26262
|
+
};
|
|
26263
|
+
this.modules.set(key, newModule);
|
|
26264
|
+
this.emitLoaded(key);
|
|
26265
|
+
return newModule;
|
|
26106
26266
|
}
|
|
26107
|
-
|
|
26108
|
-
|
|
26109
|
-
try {
|
|
26110
|
-
const data = await readConfigFile(filePath);
|
|
26111
|
-
this.cacheData = data;
|
|
26112
|
-
} catch (error) {
|
|
26113
|
-
this.cacheData = {};
|
|
26114
|
-
await writeFile(filePath, JSON.stringify(this.cacheData, null, 2));
|
|
26115
|
-
}
|
|
26267
|
+
cancel(key) {
|
|
26268
|
+
this.checkRemoveController(key);
|
|
26116
26269
|
}
|
|
26117
|
-
|
|
26118
|
-
|
|
26119
|
-
|
|
26120
|
-
|
|
26121
|
-
|
|
26122
|
-
|
|
26123
|
-
|
|
26124
|
-
this.cacheData[key] = value;
|
|
26125
|
-
writeFile(this.filePath, JSON.stringify(this.cacheData, null, 2));
|
|
26126
|
-
}
|
|
26127
|
-
removeItem(key) {
|
|
26128
|
-
delete this.cacheData[key];
|
|
26129
|
-
writeFile(this.filePath, JSON.stringify(this.cacheData, null, 2));
|
|
26270
|
+
checkRemoveController(key) {
|
|
26271
|
+
const data = this.modules.get(key);
|
|
26272
|
+
if (data?.controller) {
|
|
26273
|
+
data.controller?.abort?.();
|
|
26274
|
+
delete data.controller;
|
|
26275
|
+
this.modules.set(key, data);
|
|
26276
|
+
}
|
|
26130
26277
|
}
|
|
26131
|
-
|
|
26132
|
-
|
|
26133
|
-
|
|
26278
|
+
}
|
|
26279
|
+
|
|
26280
|
+
// node_modules/.pnpm/@kevisual+api@0.0.52_@types+react@19.2.10_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/@kevisual/api/query/query-login/query-login.ts
|
|
26281
|
+
class QueryLogin extends BaseQuery {
|
|
26282
|
+
cacheStore;
|
|
26283
|
+
isBrowser;
|
|
26284
|
+
load;
|
|
26285
|
+
storage;
|
|
26286
|
+
onLoad;
|
|
26287
|
+
constructor(opts) {
|
|
26288
|
+
super({
|
|
26289
|
+
query: opts?.query || new Query2
|
|
26290
|
+
});
|
|
26291
|
+
this.cacheStore = new LoginCacheStore({ name: "login", cache: opts?.cache });
|
|
26292
|
+
this.isBrowser = opts?.isBrowser ?? true;
|
|
26293
|
+
this.init();
|
|
26294
|
+
this.onLoad = opts?.onLoad;
|
|
26295
|
+
this.storage = opts?.storage || globalThis?.localStorage;
|
|
26134
26296
|
}
|
|
26135
|
-
|
|
26136
|
-
|
|
26297
|
+
setQuery(query) {
|
|
26298
|
+
this.query = query;
|
|
26137
26299
|
}
|
|
26138
|
-
|
|
26139
|
-
|
|
26140
|
-
|
|
26141
|
-
|
|
26142
|
-
this.filepath = filepath || join(homedir(), ".config", "envision", "config", `${getHostName()}-login.json`);
|
|
26143
|
-
fileExists(this.filepath, { isFile: true });
|
|
26300
|
+
async init() {
|
|
26301
|
+
await this.cacheStore.init();
|
|
26302
|
+
this.load = true;
|
|
26303
|
+
this.onLoad?.();
|
|
26144
26304
|
}
|
|
26145
|
-
async
|
|
26305
|
+
async post(data, opts) {
|
|
26146
26306
|
try {
|
|
26147
|
-
|
|
26148
|
-
const data = readConfigFile(filePath);
|
|
26149
|
-
return data;
|
|
26307
|
+
return this.query.post({ path: "user", ...data }, opts);
|
|
26150
26308
|
} catch (error) {
|
|
26151
|
-
console.log("
|
|
26152
|
-
return {
|
|
26309
|
+
console.log("error", error);
|
|
26310
|
+
return {
|
|
26311
|
+
code: 400
|
|
26312
|
+
};
|
|
26153
26313
|
}
|
|
26154
26314
|
}
|
|
26155
|
-
async
|
|
26156
|
-
|
|
26157
|
-
|
|
26158
|
-
const
|
|
26159
|
-
|
|
26160
|
-
|
|
26161
|
-
console.log("set error", error);
|
|
26315
|
+
async login(data) {
|
|
26316
|
+
const res = await this.post({ key: "login", ...data });
|
|
26317
|
+
if (res.code === 200) {
|
|
26318
|
+
const { accessToken, refreshToken, accessTokenExpiresIn } = res?.data || {};
|
|
26319
|
+
this.storage.setItem("token", accessToken || "");
|
|
26320
|
+
await this.beforeSetLoginUser({ accessToken, refreshToken, accessTokenExpiresIn });
|
|
26162
26321
|
}
|
|
26322
|
+
return res;
|
|
26163
26323
|
}
|
|
26164
|
-
async
|
|
26165
|
-
await
|
|
26324
|
+
async loginByCode(data) {
|
|
26325
|
+
const res = await this.post({ path: "sms", key: "login", data });
|
|
26326
|
+
if (res.code === 200) {
|
|
26327
|
+
const { accessToken, refreshToken, accessTokenExpiresIn } = res?.data || {};
|
|
26328
|
+
this.storage.setItem("token", accessToken || "");
|
|
26329
|
+
await this.beforeSetLoginUser({ accessToken, refreshToken, accessTokenExpiresIn });
|
|
26330
|
+
}
|
|
26331
|
+
return res;
|
|
26166
26332
|
}
|
|
26167
|
-
async
|
|
26168
|
-
|
|
26169
|
-
|
|
26170
|
-
|
|
26171
|
-
|
|
26172
|
-
|
|
26173
|
-
|
|
26174
|
-
|
|
26175
|
-
|
|
26176
|
-
|
|
26333
|
+
async setLoginToken(token) {
|
|
26334
|
+
const { accessToken, refreshToken, accessTokenExpiresIn } = token;
|
|
26335
|
+
this.storage.setItem("token", accessToken || "");
|
|
26336
|
+
await this.beforeSetLoginUser({ accessToken, refreshToken, accessTokenExpiresIn });
|
|
26337
|
+
}
|
|
26338
|
+
async loginByWechat(data) {
|
|
26339
|
+
const res = await this.post({ path: "wx", key: "open-login", code: data.code });
|
|
26340
|
+
if (res.code === 200) {
|
|
26341
|
+
const { accessToken, refreshToken, accessTokenExpiresIn } = res?.data || {};
|
|
26342
|
+
this.storage.setItem("token", accessToken || "");
|
|
26343
|
+
await this.beforeSetLoginUser({ accessToken, refreshToken, accessTokenExpiresIn });
|
|
26177
26344
|
}
|
|
26345
|
+
return res;
|
|
26178
26346
|
}
|
|
26179
|
-
async
|
|
26180
|
-
|
|
26347
|
+
async checkWechat({ onSuccess, onError }) {
|
|
26348
|
+
const url = new URL(window.location.href);
|
|
26349
|
+
const code = url.searchParams.get("code");
|
|
26350
|
+
const state = url.searchParams.get("state");
|
|
26351
|
+
if (code && state) {
|
|
26352
|
+
const res = await this.loginByWechat({ code });
|
|
26353
|
+
if (res.code === 200) {
|
|
26354
|
+
onSuccess?.(res.data);
|
|
26355
|
+
} else {
|
|
26356
|
+
onError?.(res);
|
|
26357
|
+
}
|
|
26358
|
+
}
|
|
26181
26359
|
}
|
|
26182
|
-
}
|
|
26183
|
-
|
|
26184
|
-
await
|
|
26185
|
-
|
|
26186
|
-
|
|
26187
|
-
|
|
26188
|
-
|
|
26189
|
-
|
|
26190
|
-
|
|
26191
|
-
|
|
26360
|
+
async beforeSetLoginUser({ accessToken, refreshToken, check401, accessTokenExpiresIn }) {
|
|
26361
|
+
if (accessToken && refreshToken) {
|
|
26362
|
+
const resUser = await this.getMe(accessToken, check401);
|
|
26363
|
+
if (resUser.code === 200) {
|
|
26364
|
+
const user = resUser.data;
|
|
26365
|
+
if (user) {
|
|
26366
|
+
this.cacheStore.setLoginUser({
|
|
26367
|
+
user,
|
|
26368
|
+
id: user.id,
|
|
26369
|
+
accessToken,
|
|
26370
|
+
refreshToken,
|
|
26371
|
+
accessTokenExpiresIn,
|
|
26372
|
+
createdAt: Date.now()
|
|
26373
|
+
});
|
|
26374
|
+
} else {
|
|
26375
|
+
console.error("登录失败");
|
|
26376
|
+
}
|
|
26377
|
+
}
|
|
26378
|
+
}
|
|
26192
26379
|
}
|
|
26193
|
-
|
|
26194
|
-
|
|
26195
|
-
|
|
26196
|
-
|
|
26197
|
-
|
|
26198
|
-
|
|
26199
|
-
|
|
26200
|
-
|
|
26201
|
-
|
|
26202
|
-
|
|
26203
|
-
}
|
|
26204
|
-
|
|
26205
|
-
|
|
26206
|
-
|
|
26207
|
-
|
|
26208
|
-
|
|
26209
|
-
if (!token) {
|
|
26210
|
-
token = await storage.getItem("token");
|
|
26380
|
+
async queryRefreshToken(refreshToken) {
|
|
26381
|
+
const _refreshToken = refreshToken || this.cacheStore.getRefreshToken();
|
|
26382
|
+
let data = { refreshToken: _refreshToken };
|
|
26383
|
+
if (!_refreshToken) {
|
|
26384
|
+
await this.cacheStore.clearCurrentUser();
|
|
26385
|
+
return {
|
|
26386
|
+
code: 401,
|
|
26387
|
+
message: "请先登录",
|
|
26388
|
+
data: {}
|
|
26389
|
+
};
|
|
26390
|
+
}
|
|
26391
|
+
return this.post({ key: "refreshToken", data }, {
|
|
26392
|
+
afterResponse: async (response, ctx) => {
|
|
26393
|
+
return response;
|
|
26394
|
+
}
|
|
26395
|
+
});
|
|
26211
26396
|
}
|
|
26212
|
-
|
|
26213
|
-
|
|
26397
|
+
async afterCheck401ToRefreshToken(response, ctx, refetch) {
|
|
26398
|
+
const that = this;
|
|
26399
|
+
if (response?.code === 401) {
|
|
26400
|
+
const hasRefreshToken = await that.cacheStore.getRefreshToken();
|
|
26401
|
+
if (hasRefreshToken) {
|
|
26402
|
+
const res = await that.queryRefreshToken(hasRefreshToken);
|
|
26403
|
+
if (res.code === 200) {
|
|
26404
|
+
const { accessToken, refreshToken, accessTokenExpiresIn } = res?.data || {};
|
|
26405
|
+
that.storage.setItem("token", accessToken || "");
|
|
26406
|
+
await that.beforeSetLoginUser({ accessToken, refreshToken, accessTokenExpiresIn, check401: false });
|
|
26407
|
+
if (refetch && ctx && ctx.req && ctx.req.url && ctx.fetch) {
|
|
26408
|
+
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
26409
|
+
const url = ctx.req?.url;
|
|
26410
|
+
const body = ctx.req?.body;
|
|
26411
|
+
const headers = ctx.req?.headers;
|
|
26412
|
+
const res2 = await ctx.fetch(url, {
|
|
26413
|
+
method: "POST",
|
|
26414
|
+
body,
|
|
26415
|
+
headers: { ...headers, Authorization: `Bearer ${accessToken}` }
|
|
26416
|
+
});
|
|
26417
|
+
return res2;
|
|
26418
|
+
}
|
|
26419
|
+
} else {
|
|
26420
|
+
that.storage.removeItem("token");
|
|
26421
|
+
await that.cacheStore.clearCurrentUser();
|
|
26422
|
+
}
|
|
26423
|
+
return res;
|
|
26424
|
+
}
|
|
26425
|
+
}
|
|
26426
|
+
return response;
|
|
26214
26427
|
}
|
|
26215
|
-
|
|
26216
|
-
|
|
26217
|
-
|
|
26218
|
-
|
|
26219
|
-
|
|
26220
|
-
|
|
26221
|
-
|
|
26428
|
+
async run401Action(response, ctx, opts) {
|
|
26429
|
+
const that = this;
|
|
26430
|
+
const refetch = opts?.refetch ?? false;
|
|
26431
|
+
if (response?.code === 401) {
|
|
26432
|
+
if (that.query.stop === true) {
|
|
26433
|
+
return { code: 500, success: false, message: "refresh token loading..." };
|
|
26434
|
+
}
|
|
26435
|
+
that.query.stop = true;
|
|
26436
|
+
const res = await that.afterCheck401ToRefreshToken(response, ctx, refetch);
|
|
26437
|
+
that.query.stop = false;
|
|
26438
|
+
opts?.afterCheck?.(res);
|
|
26439
|
+
if (res.code === 401) {
|
|
26440
|
+
opts?.afterAlso401?.(res);
|
|
26441
|
+
}
|
|
26442
|
+
return res;
|
|
26443
|
+
} else {
|
|
26444
|
+
return response;
|
|
26222
26445
|
}
|
|
26223
|
-
|
|
26224
|
-
|
|
26446
|
+
}
|
|
26447
|
+
async getMe(token, check401 = true) {
|
|
26448
|
+
const _token = token || this.storage.getItem("token");
|
|
26449
|
+
const that = this;
|
|
26450
|
+
return that.post({ key: "me" }, {
|
|
26451
|
+
beforeRequest: async (config) => {
|
|
26452
|
+
if (config.headers) {
|
|
26453
|
+
config.headers["Authorization"] = `Bearer ${_token}`;
|
|
26454
|
+
}
|
|
26455
|
+
if (!_token) {
|
|
26456
|
+
return false;
|
|
26457
|
+
}
|
|
26458
|
+
return config;
|
|
26459
|
+
},
|
|
26460
|
+
afterResponse: async (response, ctx) => {
|
|
26461
|
+
if (response?.code === 401 && check401 && !token) {
|
|
26462
|
+
return await that.afterCheck401ToRefreshToken(response, ctx);
|
|
26463
|
+
}
|
|
26464
|
+
return response;
|
|
26465
|
+
}
|
|
26466
|
+
});
|
|
26467
|
+
}
|
|
26468
|
+
async checkLocalUser() {
|
|
26469
|
+
const user = await this.cacheStore.getCurrentUser();
|
|
26470
|
+
if (user) {
|
|
26471
|
+
return user;
|
|
26225
26472
|
}
|
|
26473
|
+
return null;
|
|
26226
26474
|
}
|
|
26227
|
-
|
|
26228
|
-
|
|
26229
|
-
|
|
26230
|
-
return await queryLogin.run401Action(response, ctx);
|
|
26231
|
-
};
|
|
26232
|
-
var queryLogin = new QueryLoginNode({
|
|
26233
|
-
query,
|
|
26234
|
-
onLoad: async () => {}
|
|
26235
|
-
});
|
|
26236
|
-
var getUrl = (url) => {
|
|
26237
|
-
return new URL("/api/router", url).href;
|
|
26238
|
-
};
|
|
26239
|
-
|
|
26240
|
-
// node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
26241
|
-
var ANSI_BACKGROUND_OFFSET = 10;
|
|
26242
|
-
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
26243
|
-
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
26244
|
-
var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
|
|
26245
|
-
var styles = {
|
|
26246
|
-
modifier: {
|
|
26247
|
-
reset: [0, 0],
|
|
26248
|
-
bold: [1, 22],
|
|
26249
|
-
dim: [2, 22],
|
|
26250
|
-
italic: [3, 23],
|
|
26251
|
-
underline: [4, 24],
|
|
26252
|
-
overline: [53, 55],
|
|
26253
|
-
inverse: [7, 27],
|
|
26254
|
-
hidden: [8, 28],
|
|
26255
|
-
strikethrough: [9, 29]
|
|
26256
|
-
},
|
|
26257
|
-
color: {
|
|
26258
|
-
black: [30, 39],
|
|
26259
|
-
red: [31, 39],
|
|
26260
|
-
green: [32, 39],
|
|
26261
|
-
yellow: [33, 39],
|
|
26262
|
-
blue: [34, 39],
|
|
26263
|
-
magenta: [35, 39],
|
|
26264
|
-
cyan: [36, 39],
|
|
26265
|
-
white: [37, 39],
|
|
26266
|
-
blackBright: [90, 39],
|
|
26267
|
-
gray: [90, 39],
|
|
26268
|
-
grey: [90, 39],
|
|
26269
|
-
redBright: [91, 39],
|
|
26270
|
-
greenBright: [92, 39],
|
|
26271
|
-
yellowBright: [93, 39],
|
|
26272
|
-
blueBright: [94, 39],
|
|
26273
|
-
magentaBright: [95, 39],
|
|
26274
|
-
cyanBright: [96, 39],
|
|
26275
|
-
whiteBright: [97, 39]
|
|
26276
|
-
},
|
|
26277
|
-
bgColor: {
|
|
26278
|
-
bgBlack: [40, 49],
|
|
26279
|
-
bgRed: [41, 49],
|
|
26280
|
-
bgGreen: [42, 49],
|
|
26281
|
-
bgYellow: [43, 49],
|
|
26282
|
-
bgBlue: [44, 49],
|
|
26283
|
-
bgMagenta: [45, 49],
|
|
26284
|
-
bgCyan: [46, 49],
|
|
26285
|
-
bgWhite: [47, 49],
|
|
26286
|
-
bgBlackBright: [100, 49],
|
|
26287
|
-
bgGray: [100, 49],
|
|
26288
|
-
bgGrey: [100, 49],
|
|
26289
|
-
bgRedBright: [101, 49],
|
|
26290
|
-
bgGreenBright: [102, 49],
|
|
26291
|
-
bgYellowBright: [103, 49],
|
|
26292
|
-
bgBlueBright: [104, 49],
|
|
26293
|
-
bgMagentaBright: [105, 49],
|
|
26294
|
-
bgCyanBright: [106, 49],
|
|
26295
|
-
bgWhiteBright: [107, 49]
|
|
26475
|
+
async checkLocalToken() {
|
|
26476
|
+
const token = this.storage.getItem("token");
|
|
26477
|
+
return !!token;
|
|
26296
26478
|
}
|
|
26297
|
-
|
|
26298
|
-
|
|
26299
|
-
|
|
26300
|
-
var backgroundColorNames = Object.keys(styles.bgColor);
|
|
26301
|
-
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
26302
|
-
function assembleStyles() {
|
|
26303
|
-
const codes = new Map;
|
|
26304
|
-
for (const [groupName, group] of Object.entries(styles)) {
|
|
26305
|
-
for (const [styleName, style] of Object.entries(group)) {
|
|
26306
|
-
styles[styleName] = {
|
|
26307
|
-
open: `\x1B[${style[0]}m`,
|
|
26308
|
-
close: `\x1B[${style[1]}m`
|
|
26309
|
-
};
|
|
26310
|
-
group[styleName] = styles[styleName];
|
|
26311
|
-
codes.set(style[0], style[1]);
|
|
26312
|
-
}
|
|
26313
|
-
Object.defineProperty(styles, groupName, {
|
|
26314
|
-
value: group,
|
|
26315
|
-
enumerable: false
|
|
26316
|
-
});
|
|
26479
|
+
async getToken() {
|
|
26480
|
+
const token = this.storage.getItem("token");
|
|
26481
|
+
return token || "";
|
|
26317
26482
|
}
|
|
26318
|
-
|
|
26319
|
-
|
|
26320
|
-
|
|
26321
|
-
|
|
26322
|
-
styles.color.close = "\x1B[39m";
|
|
26323
|
-
styles.bgColor.close = "\x1B[49m";
|
|
26324
|
-
styles.color.ansi = wrapAnsi16();
|
|
26325
|
-
styles.color.ansi256 = wrapAnsi256();
|
|
26326
|
-
styles.color.ansi16m = wrapAnsi16m();
|
|
26327
|
-
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
26328
|
-
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
26329
|
-
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
26330
|
-
Object.defineProperties(styles, {
|
|
26331
|
-
rgbToAnsi256: {
|
|
26332
|
-
value(red, green, blue) {
|
|
26333
|
-
if (red === green && green === blue) {
|
|
26334
|
-
if (red < 8) {
|
|
26335
|
-
return 16;
|
|
26336
|
-
}
|
|
26337
|
-
if (red > 248) {
|
|
26338
|
-
return 231;
|
|
26339
|
-
}
|
|
26340
|
-
return Math.round((red - 8) / 247 * 24) + 232;
|
|
26341
|
-
}
|
|
26342
|
-
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
26343
|
-
},
|
|
26344
|
-
enumerable: false
|
|
26345
|
-
},
|
|
26346
|
-
hexToRgb: {
|
|
26347
|
-
value(hex) {
|
|
26348
|
-
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
26349
|
-
if (!matches) {
|
|
26350
|
-
return [0, 0, 0];
|
|
26351
|
-
}
|
|
26352
|
-
let [colorString] = matches;
|
|
26353
|
-
if (colorString.length === 3) {
|
|
26354
|
-
colorString = [...colorString].map((character) => character + character).join("");
|
|
26355
|
-
}
|
|
26356
|
-
const integer = Number.parseInt(colorString, 16);
|
|
26357
|
-
return [
|
|
26358
|
-
integer >> 16 & 255,
|
|
26359
|
-
integer >> 8 & 255,
|
|
26360
|
-
integer & 255
|
|
26361
|
-
];
|
|
26362
|
-
},
|
|
26363
|
-
enumerable: false
|
|
26364
|
-
},
|
|
26365
|
-
hexToAnsi256: {
|
|
26366
|
-
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
26367
|
-
enumerable: false
|
|
26368
|
-
},
|
|
26369
|
-
ansi256ToAnsi: {
|
|
26370
|
-
value(code) {
|
|
26371
|
-
if (code < 8) {
|
|
26372
|
-
return 30 + code;
|
|
26373
|
-
}
|
|
26374
|
-
if (code < 16) {
|
|
26375
|
-
return 90 + (code - 8);
|
|
26376
|
-
}
|
|
26377
|
-
let red;
|
|
26378
|
-
let green;
|
|
26379
|
-
let blue;
|
|
26380
|
-
if (code >= 232) {
|
|
26381
|
-
red = ((code - 232) * 10 + 8) / 255;
|
|
26382
|
-
green = red;
|
|
26383
|
-
blue = red;
|
|
26384
|
-
} else {
|
|
26385
|
-
code -= 16;
|
|
26386
|
-
const remainder = code % 36;
|
|
26387
|
-
red = Math.floor(code / 36) / 5;
|
|
26388
|
-
green = Math.floor(remainder / 6) / 5;
|
|
26389
|
-
blue = remainder % 6 / 5;
|
|
26390
|
-
}
|
|
26391
|
-
const value = Math.max(red, green, blue) * 2;
|
|
26392
|
-
if (value === 0) {
|
|
26393
|
-
return 30;
|
|
26394
|
-
}
|
|
26395
|
-
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
26396
|
-
if (value === 2) {
|
|
26397
|
-
result += 60;
|
|
26398
|
-
}
|
|
26399
|
-
return result;
|
|
26400
|
-
},
|
|
26401
|
-
enumerable: false
|
|
26402
|
-
},
|
|
26403
|
-
rgbToAnsi: {
|
|
26404
|
-
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
26405
|
-
enumerable: false
|
|
26406
|
-
},
|
|
26407
|
-
hexToAnsi: {
|
|
26408
|
-
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
26409
|
-
enumerable: false
|
|
26483
|
+
async beforeRequest(opts = {}) {
|
|
26484
|
+
const token = this.storage.getItem("token");
|
|
26485
|
+
if (token) {
|
|
26486
|
+
opts.headers = { ...opts.headers, Authorization: `Bearer ${token}` };
|
|
26410
26487
|
}
|
|
26411
|
-
|
|
26412
|
-
|
|
26413
|
-
|
|
26414
|
-
|
|
26415
|
-
|
|
26416
|
-
|
|
26417
|
-
|
|
26418
|
-
|
|
26419
|
-
|
|
26420
|
-
|
|
26421
|
-
|
|
26422
|
-
|
|
26423
|
-
|
|
26424
|
-
|
|
26425
|
-
|
|
26426
|
-
|
|
26427
|
-
|
|
26428
|
-
|
|
26429
|
-
|
|
26430
|
-
|
|
26431
|
-
|
|
26432
|
-
|
|
26433
|
-
|
|
26434
|
-
|
|
26435
|
-
|
|
26436
|
-
if (env.FORCE_COLOR === "true") {
|
|
26437
|
-
return 1;
|
|
26488
|
+
return opts;
|
|
26489
|
+
}
|
|
26490
|
+
async postSwitchUser(username) {
|
|
26491
|
+
return this.post({ key: "switchCheck", data: { username } });
|
|
26492
|
+
}
|
|
26493
|
+
async switchUser(username) {
|
|
26494
|
+
const localUserList = await this.cacheStore.getCurrentUserList();
|
|
26495
|
+
const user = localUserList.find((userItem) => userItem.user.username === username);
|
|
26496
|
+
if (user) {
|
|
26497
|
+
this.storage.setItem("token", user.accessToken || "");
|
|
26498
|
+
await this.beforeSetLoginUser({
|
|
26499
|
+
accessToken: user.accessToken,
|
|
26500
|
+
refreshToken: user.refreshToken,
|
|
26501
|
+
accessTokenExpiresIn: user.accessTokenExpiresIn
|
|
26502
|
+
});
|
|
26503
|
+
return {
|
|
26504
|
+
code: 200,
|
|
26505
|
+
data: {
|
|
26506
|
+
accessToken: user.accessToken,
|
|
26507
|
+
refreshToken: user.refreshToken,
|
|
26508
|
+
accessTokenExpiresIn: user.accessTokenExpiresIn
|
|
26509
|
+
},
|
|
26510
|
+
success: true,
|
|
26511
|
+
message: "切换用户成功"
|
|
26512
|
+
};
|
|
26438
26513
|
}
|
|
26439
|
-
|
|
26440
|
-
|
|
26514
|
+
const res = await this.postSwitchUser(username);
|
|
26515
|
+
if (res.code === 200) {
|
|
26516
|
+
const { accessToken, refreshToken, accessTokenExpiresIn } = res?.data || {};
|
|
26517
|
+
this.storage.setItem("token", accessToken || "");
|
|
26518
|
+
await this.beforeSetLoginUser({ accessToken, refreshToken, accessTokenExpiresIn });
|
|
26441
26519
|
}
|
|
26442
|
-
return
|
|
26520
|
+
return res;
|
|
26443
26521
|
}
|
|
26444
|
-
|
|
26445
|
-
|
|
26446
|
-
|
|
26447
|
-
|
|
26522
|
+
async logout() {
|
|
26523
|
+
this.storage.removeItem("token");
|
|
26524
|
+
const users = await this.cacheStore.getCurrentUserList();
|
|
26525
|
+
const tokens = users.map((user) => {
|
|
26526
|
+
return user?.accessToken;
|
|
26527
|
+
}).filter(Boolean);
|
|
26528
|
+
this.cacheStore.delValue();
|
|
26529
|
+
return this.post({ key: "logout", data: { tokens } });
|
|
26448
26530
|
}
|
|
26449
|
-
|
|
26450
|
-
|
|
26451
|
-
|
|
26452
|
-
|
|
26453
|
-
|
|
26454
|
-
|
|
26455
|
-
|
|
26456
|
-
|
|
26457
|
-
|
|
26458
|
-
|
|
26459
|
-
|
|
26531
|
+
async hasUser(username) {
|
|
26532
|
+
const that = this;
|
|
26533
|
+
return this.post({
|
|
26534
|
+
path: "org",
|
|
26535
|
+
key: "hasUser",
|
|
26536
|
+
data: {
|
|
26537
|
+
username
|
|
26538
|
+
}
|
|
26539
|
+
}, {
|
|
26540
|
+
afterResponse: async (response, ctx) => {
|
|
26541
|
+
if (response?.code === 401) {
|
|
26542
|
+
const res = await that.afterCheck401ToRefreshToken(response, ctx, true);
|
|
26543
|
+
return res;
|
|
26544
|
+
}
|
|
26545
|
+
return response;
|
|
26546
|
+
}
|
|
26547
|
+
});
|
|
26460
26548
|
}
|
|
26461
|
-
|
|
26462
|
-
|
|
26463
|
-
|
|
26549
|
+
async checkLoginStatus(token) {
|
|
26550
|
+
const res = await this.post({
|
|
26551
|
+
path: "user",
|
|
26552
|
+
key: "checkLoginStatus",
|
|
26553
|
+
loginToken: token
|
|
26554
|
+
});
|
|
26555
|
+
if (res.code === 200) {
|
|
26556
|
+
const { accessTokenExpiresIn, accessToken, refreshToken } = res.data;
|
|
26557
|
+
this.storage.setItem("token", accessToken || "");
|
|
26558
|
+
await this.beforeSetLoginUser({ accessToken, refreshToken, accessTokenExpiresIn });
|
|
26559
|
+
return res;
|
|
26560
|
+
}
|
|
26561
|
+
return false;
|
|
26464
26562
|
}
|
|
26465
|
-
|
|
26466
|
-
|
|
26467
|
-
|
|
26563
|
+
loginWithWeb(baseURL, { MD5, jsonwebtoken }) {
|
|
26564
|
+
const randomId = Math.random().toString(36).substring(2, 15);
|
|
26565
|
+
const timestamp = Date.now();
|
|
26566
|
+
const tokenSecret = "xiao" + randomId;
|
|
26567
|
+
let sign = "";
|
|
26568
|
+
if (MD5) {
|
|
26569
|
+
sign = MD5(`${tokenSecret}${timestamp}`).toString();
|
|
26570
|
+
}
|
|
26571
|
+
let token = "";
|
|
26572
|
+
if (jsonwebtoken) {
|
|
26573
|
+
token = jsonwebtoken.sign({ randomId, timestamp, sign }, tokenSecret, {
|
|
26574
|
+
expiresIn: 60 * 10
|
|
26575
|
+
});
|
|
26576
|
+
} else {
|
|
26577
|
+
token = tokenSecret;
|
|
26468
26578
|
}
|
|
26469
|
-
|
|
26470
|
-
|
|
26579
|
+
const url = `${baseURL}/api/router?path=user&key=webLogin&p&loginToken=${token}&sign=${sign}&randomId=${randomId}`;
|
|
26580
|
+
return { url, token, tokenSecret };
|
|
26581
|
+
}
|
|
26582
|
+
async pollLoginStatus(data) {
|
|
26583
|
+
const token = data.token;
|
|
26584
|
+
const load2 = new BaseLoad3;
|
|
26585
|
+
load2.load(async () => {
|
|
26586
|
+
const res2 = await this.checkLoginStatus(token);
|
|
26587
|
+
if (res2.code === 500) {
|
|
26588
|
+
load2.cancel("check-login-status");
|
|
26589
|
+
}
|
|
26590
|
+
return res2;
|
|
26591
|
+
}, {
|
|
26592
|
+
key: "check-login-status",
|
|
26593
|
+
isReRun: true,
|
|
26594
|
+
checkSuccess: (data2) => {
|
|
26595
|
+
return data2?.code === 200;
|
|
26596
|
+
}
|
|
26597
|
+
});
|
|
26598
|
+
const res = await load2.hasLoaded("check-login-status", {
|
|
26599
|
+
timeout: 60 * 3 * 1000
|
|
26600
|
+
});
|
|
26601
|
+
if (res.code === 200 && res.data?.code === 200) {
|
|
26602
|
+
try {
|
|
26603
|
+
console.log("网页登录成功");
|
|
26604
|
+
return true;
|
|
26605
|
+
} catch (error) {
|
|
26606
|
+
console.log("登录失败", error);
|
|
26607
|
+
return false;
|
|
26608
|
+
}
|
|
26471
26609
|
}
|
|
26610
|
+
console.log("登录失败", res);
|
|
26611
|
+
return false;
|
|
26472
26612
|
}
|
|
26473
|
-
|
|
26474
|
-
|
|
26613
|
+
}
|
|
26614
|
+
|
|
26615
|
+
// node_modules/.pnpm/@kevisual+api@0.0.52_@types+react@19.2.10_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/@kevisual/api/query/query-login/login-node-cache.ts
|
|
26616
|
+
import { homedir } from "node:os";
|
|
26617
|
+
import { join, dirname } from "node:path";
|
|
26618
|
+
import fs4 from "node:fs";
|
|
26619
|
+
import { readFileSync, writeFileSync, accessSync } from "node:fs";
|
|
26620
|
+
import { readFile, writeFile, unlink, mkdir } from "node:fs/promises";
|
|
26621
|
+
var fileExists = async (filePath, { createIfNotExists = true, isFile = true, isDir = false } = {}) => {
|
|
26622
|
+
try {
|
|
26623
|
+
accessSync(filePath, fs4.constants.F_OK);
|
|
26624
|
+
return true;
|
|
26625
|
+
} catch (error) {
|
|
26626
|
+
if (createIfNotExists && isDir) {
|
|
26627
|
+
await mkdir(filePath, { recursive: true });
|
|
26628
|
+
return true;
|
|
26629
|
+
} else if (createIfNotExists && isFile) {
|
|
26630
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
26631
|
+
return false;
|
|
26632
|
+
}
|
|
26633
|
+
return false;
|
|
26475
26634
|
}
|
|
26476
|
-
|
|
26477
|
-
|
|
26635
|
+
};
|
|
26636
|
+
var readConfigFile = (filePath) => {
|
|
26637
|
+
try {
|
|
26638
|
+
const data = readFileSync(filePath, "utf-8");
|
|
26639
|
+
const jsonData = JSON.parse(data);
|
|
26640
|
+
return jsonData;
|
|
26641
|
+
} catch (error) {
|
|
26642
|
+
return {};
|
|
26478
26643
|
}
|
|
26479
|
-
|
|
26480
|
-
|
|
26481
|
-
|
|
26644
|
+
};
|
|
26645
|
+
var writeConfigFile = (filePath, data) => {
|
|
26646
|
+
writeFileSync(filePath, JSON.stringify(data, null, 2));
|
|
26647
|
+
};
|
|
26648
|
+
var getHostName = () => {
|
|
26649
|
+
const configDir = join(homedir(), ".config", "envision");
|
|
26650
|
+
const configFile = join(configDir, "config.json");
|
|
26651
|
+
const config = readConfigFile(configFile);
|
|
26652
|
+
const baseURL = config.baseURL || "https://kevisual.cn";
|
|
26653
|
+
const hostname = new URL(baseURL).hostname;
|
|
26654
|
+
return hostname;
|
|
26655
|
+
};
|
|
26656
|
+
|
|
26657
|
+
class StorageNode {
|
|
26658
|
+
cacheData;
|
|
26659
|
+
filePath;
|
|
26660
|
+
constructor() {
|
|
26661
|
+
this.cacheData = {};
|
|
26662
|
+
const configDir = join(homedir(), ".config", "envision");
|
|
26663
|
+
const hostname = getHostName();
|
|
26664
|
+
this.filePath = join(configDir, "config", `${hostname}-storage.json`);
|
|
26665
|
+
fileExists(this.filePath, { isFile: true });
|
|
26482
26666
|
}
|
|
26483
|
-
|
|
26484
|
-
const
|
|
26485
|
-
|
|
26486
|
-
|
|
26667
|
+
async loadCache() {
|
|
26668
|
+
const filePath = this.filePath;
|
|
26669
|
+
try {
|
|
26670
|
+
const data = await readConfigFile(filePath);
|
|
26671
|
+
this.cacheData = data;
|
|
26672
|
+
} catch (error) {
|
|
26673
|
+
this.cacheData = {};
|
|
26674
|
+
await writeFile(filePath, JSON.stringify(this.cacheData, null, 2));
|
|
26487
26675
|
}
|
|
26488
|
-
return 1;
|
|
26489
26676
|
}
|
|
26490
|
-
|
|
26491
|
-
|
|
26492
|
-
return 3;
|
|
26493
|
-
}
|
|
26494
|
-
if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => (sign in env)) || env.CI_NAME === "codeship") {
|
|
26495
|
-
return 1;
|
|
26496
|
-
}
|
|
26497
|
-
return min;
|
|
26677
|
+
get length() {
|
|
26678
|
+
return Object.keys(this.cacheData).length;
|
|
26498
26679
|
}
|
|
26499
|
-
|
|
26500
|
-
return
|
|
26680
|
+
getItem(key) {
|
|
26681
|
+
return this.cacheData[key];
|
|
26501
26682
|
}
|
|
26502
|
-
|
|
26503
|
-
|
|
26683
|
+
setItem(key, value) {
|
|
26684
|
+
this.cacheData[key] = value;
|
|
26685
|
+
writeFile(this.filePath, JSON.stringify(this.cacheData, null, 2));
|
|
26504
26686
|
}
|
|
26505
|
-
|
|
26506
|
-
|
|
26687
|
+
removeItem(key) {
|
|
26688
|
+
delete this.cacheData[key];
|
|
26689
|
+
writeFile(this.filePath, JSON.stringify(this.cacheData, null, 2));
|
|
26507
26690
|
}
|
|
26508
|
-
|
|
26509
|
-
|
|
26691
|
+
clear() {
|
|
26692
|
+
this.cacheData = {};
|
|
26693
|
+
writeFile(this.filePath, JSON.stringify(this.cacheData, null, 2));
|
|
26510
26694
|
}
|
|
26511
|
-
|
|
26512
|
-
return
|
|
26695
|
+
key(index) {
|
|
26696
|
+
return Object.keys(this.cacheData)[index];
|
|
26513
26697
|
}
|
|
26514
|
-
|
|
26515
|
-
|
|
26516
|
-
|
|
26517
|
-
|
|
26518
|
-
|
|
26519
|
-
|
|
26520
|
-
|
|
26521
|
-
|
|
26522
|
-
|
|
26698
|
+
}
|
|
26699
|
+
|
|
26700
|
+
class LoginNodeCache {
|
|
26701
|
+
filepath;
|
|
26702
|
+
constructor(filepath) {
|
|
26703
|
+
this.filepath = filepath || join(homedir(), ".config", "envision", "config", `${getHostName()}-login.json`);
|
|
26704
|
+
fileExists(this.filepath, { isFile: true });
|
|
26705
|
+
}
|
|
26706
|
+
async get(_key) {
|
|
26707
|
+
try {
|
|
26708
|
+
const filePath = this.filepath;
|
|
26709
|
+
const data = readConfigFile(filePath);
|
|
26710
|
+
return data;
|
|
26711
|
+
} catch (error) {
|
|
26712
|
+
console.log("get error", error);
|
|
26713
|
+
return {};
|
|
26523
26714
|
}
|
|
26524
26715
|
}
|
|
26525
|
-
|
|
26526
|
-
|
|
26716
|
+
async set(_key, value) {
|
|
26717
|
+
try {
|
|
26718
|
+
const data = readConfigFile(this.filepath);
|
|
26719
|
+
const newData = { ...data, ...value };
|
|
26720
|
+
writeConfigFile(this.filepath, newData);
|
|
26721
|
+
} catch (error) {
|
|
26722
|
+
console.log("set error", error);
|
|
26723
|
+
}
|
|
26527
26724
|
}
|
|
26528
|
-
|
|
26529
|
-
|
|
26725
|
+
async del() {
|
|
26726
|
+
await unlink(this.filepath);
|
|
26530
26727
|
}
|
|
26531
|
-
|
|
26532
|
-
|
|
26728
|
+
async loadCache(filePath) {
|
|
26729
|
+
try {
|
|
26730
|
+
const data = await readFile(filePath, "utf-8");
|
|
26731
|
+
const jsonData = JSON.parse(data);
|
|
26732
|
+
return jsonData;
|
|
26733
|
+
} catch (error) {
|
|
26734
|
+
console.log("create new cache file:", filePath);
|
|
26735
|
+
const defaultData = { loginUsers: [] };
|
|
26736
|
+
writeConfigFile(filePath, defaultData);
|
|
26737
|
+
return defaultData;
|
|
26738
|
+
}
|
|
26739
|
+
}
|
|
26740
|
+
async init() {
|
|
26741
|
+
return await this.loadCache(this.filepath);
|
|
26533
26742
|
}
|
|
26534
|
-
return min;
|
|
26535
|
-
}
|
|
26536
|
-
function createSupportsColor(stream, options = {}) {
|
|
26537
|
-
const level = _supportsColor(stream, {
|
|
26538
|
-
streamIsTTY: stream && stream.isTTY,
|
|
26539
|
-
...options
|
|
26540
|
-
});
|
|
26541
|
-
return translateLevel(level);
|
|
26542
26743
|
}
|
|
26543
|
-
var supportsColor = {
|
|
26544
|
-
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
|
26545
|
-
stderr: createSupportsColor({ isTTY: tty.isatty(2) })
|
|
26546
|
-
};
|
|
26547
|
-
var supports_color_default = supportsColor;
|
|
26548
26744
|
|
|
26549
|
-
// node_modules/.pnpm
|
|
26550
|
-
|
|
26551
|
-
|
|
26552
|
-
|
|
26553
|
-
|
|
26745
|
+
// node_modules/.pnpm/@kevisual+api@0.0.52_@types+react@19.2.10_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/@kevisual/api/query/query-login/query-login-node.ts
|
|
26746
|
+
var storage = new StorageNode;
|
|
26747
|
+
await storage.loadCache();
|
|
26748
|
+
|
|
26749
|
+
class QueryLoginNode extends QueryLogin {
|
|
26750
|
+
constructor(opts) {
|
|
26751
|
+
super({
|
|
26752
|
+
...opts,
|
|
26753
|
+
storage,
|
|
26754
|
+
cache: new LoginNodeCache
|
|
26755
|
+
});
|
|
26554
26756
|
}
|
|
26555
|
-
const substringLength = substring.length;
|
|
26556
|
-
let endIndex = 0;
|
|
26557
|
-
let returnValue = "";
|
|
26558
|
-
do {
|
|
26559
|
-
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
26560
|
-
endIndex = index + substringLength;
|
|
26561
|
-
index = string.indexOf(substring, endIndex);
|
|
26562
|
-
} while (index !== -1);
|
|
26563
|
-
returnValue += string.slice(endIndex);
|
|
26564
|
-
return returnValue;
|
|
26565
26757
|
}
|
|
26566
|
-
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
26567
|
-
let endIndex = 0;
|
|
26568
|
-
let returnValue = "";
|
|
26569
|
-
do {
|
|
26570
|
-
const gotCR = string[index - 1] === "\r";
|
|
26571
|
-
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? `\r
|
|
26572
|
-
` : `
|
|
26573
|
-
`) + postfix;
|
|
26574
|
-
endIndex = index + 1;
|
|
26575
|
-
index = string.indexOf(`
|
|
26576
|
-
`, endIndex);
|
|
26577
|
-
} while (index !== -1);
|
|
26578
|
-
returnValue += string.slice(endIndex);
|
|
26579
|
-
return returnValue;
|
|
26580
|
-
}
|
|
26581
|
-
|
|
26582
|
-
// node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
|
|
26583
|
-
var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
|
|
26584
|
-
var GENERATOR = Symbol("GENERATOR");
|
|
26585
|
-
var STYLER = Symbol("STYLER");
|
|
26586
|
-
var IS_EMPTY = Symbol("IS_EMPTY");
|
|
26587
|
-
var levelMapping = [
|
|
26588
|
-
"ansi",
|
|
26589
|
-
"ansi",
|
|
26590
|
-
"ansi256",
|
|
26591
|
-
"ansi16m"
|
|
26592
|
-
];
|
|
26593
|
-
var styles2 = Object.create(null);
|
|
26594
|
-
var applyOptions = (object, options = {}) => {
|
|
26595
|
-
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
26596
|
-
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
26597
|
-
}
|
|
26598
|
-
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
26599
|
-
object.level = options.level === undefined ? colorLevel : options.level;
|
|
26600
|
-
};
|
|
26601
26758
|
|
|
26602
|
-
|
|
26603
|
-
|
|
26604
|
-
|
|
26605
|
-
|
|
26606
|
-
|
|
26607
|
-
var chalkFactory = (options) => {
|
|
26608
|
-
const chalk = (...strings) => strings.join(" ");
|
|
26609
|
-
applyOptions(chalk, options);
|
|
26610
|
-
Object.setPrototypeOf(chalk, createChalk.prototype);
|
|
26611
|
-
return chalk;
|
|
26759
|
+
// src/module/query.ts
|
|
26760
|
+
var config = getConfig2();
|
|
26761
|
+
var baseURL = config?.baseURL || "https://kevisual.cn";
|
|
26762
|
+
var getBaseURL = () => {
|
|
26763
|
+
return baseURL;
|
|
26612
26764
|
};
|
|
26613
|
-
|
|
26614
|
-
|
|
26615
|
-
}
|
|
26616
|
-
|
|
26617
|
-
|
|
26618
|
-
|
|
26619
|
-
get() {
|
|
26620
|
-
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
26621
|
-
Object.defineProperty(this, styleName, { value: builder });
|
|
26622
|
-
return builder;
|
|
26623
|
-
}
|
|
26765
|
+
var query = new Query({
|
|
26766
|
+
url: `${getBaseURL()}/api/router`
|
|
26767
|
+
});
|
|
26768
|
+
var getHeader = async () => {
|
|
26769
|
+
const headers = {
|
|
26770
|
+
"Content-Type": "application/json"
|
|
26624
26771
|
};
|
|
26625
|
-
|
|
26626
|
-
|
|
26627
|
-
|
|
26628
|
-
const builder = createBuilder(this, this[STYLER], true);
|
|
26629
|
-
Object.defineProperty(this, "visible", { value: builder });
|
|
26630
|
-
return builder;
|
|
26631
|
-
}
|
|
26632
|
-
};
|
|
26633
|
-
var getModelAnsi = (model, level, type, ...arguments_) => {
|
|
26634
|
-
if (model === "rgb") {
|
|
26635
|
-
if (level === "ansi16m") {
|
|
26636
|
-
return ansi_styles_default[type].ansi16m(...arguments_);
|
|
26637
|
-
}
|
|
26638
|
-
if (level === "ansi256") {
|
|
26639
|
-
return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
|
|
26640
|
-
}
|
|
26641
|
-
return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
|
|
26772
|
+
let token = getEnvToken();
|
|
26773
|
+
if (!token) {
|
|
26774
|
+
token = await storage.getItem("token");
|
|
26642
26775
|
}
|
|
26643
|
-
if (
|
|
26644
|
-
|
|
26776
|
+
if (token) {
|
|
26777
|
+
headers["Authorization"] = "Bearer " + token;
|
|
26645
26778
|
}
|
|
26646
|
-
return
|
|
26779
|
+
return headers;
|
|
26647
26780
|
};
|
|
26648
|
-
|
|
26649
|
-
|
|
26650
|
-
|
|
26651
|
-
|
|
26652
|
-
|
|
26653
|
-
return function(...arguments_) {
|
|
26654
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
|
26655
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
26656
|
-
};
|
|
26657
|
-
}
|
|
26658
|
-
};
|
|
26659
|
-
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
26660
|
-
styles2[bgModel] = {
|
|
26661
|
-
get() {
|
|
26662
|
-
const { level } = this;
|
|
26663
|
-
return function(...arguments_) {
|
|
26664
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
|
|
26665
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
26666
|
-
};
|
|
26781
|
+
query.beforeRequest = async (config2) => {
|
|
26782
|
+
if (config2.headers) {
|
|
26783
|
+
let token = getEnvToken();
|
|
26784
|
+
if (!token) {
|
|
26785
|
+
token = await storage.getItem("token");
|
|
26667
26786
|
}
|
|
26668
|
-
|
|
26669
|
-
|
|
26670
|
-
var proto = Object.defineProperties(() => {}, {
|
|
26671
|
-
...styles2,
|
|
26672
|
-
level: {
|
|
26673
|
-
enumerable: true,
|
|
26674
|
-
get() {
|
|
26675
|
-
return this[GENERATOR].level;
|
|
26676
|
-
},
|
|
26677
|
-
set(level) {
|
|
26678
|
-
this[GENERATOR].level = level;
|
|
26787
|
+
if (token) {
|
|
26788
|
+
config2.headers["Authorization"] = "Bearer " + token;
|
|
26679
26789
|
}
|
|
26680
26790
|
}
|
|
26681
|
-
|
|
26682
|
-
var createStyler = (open, close, parent) => {
|
|
26683
|
-
let openAll;
|
|
26684
|
-
let closeAll;
|
|
26685
|
-
if (parent === undefined) {
|
|
26686
|
-
openAll = open;
|
|
26687
|
-
closeAll = close;
|
|
26688
|
-
} else {
|
|
26689
|
-
openAll = parent.openAll + open;
|
|
26690
|
-
closeAll = close + parent.closeAll;
|
|
26691
|
-
}
|
|
26692
|
-
return {
|
|
26693
|
-
open,
|
|
26694
|
-
close,
|
|
26695
|
-
openAll,
|
|
26696
|
-
closeAll,
|
|
26697
|
-
parent
|
|
26698
|
-
};
|
|
26791
|
+
return config2;
|
|
26699
26792
|
};
|
|
26700
|
-
|
|
26701
|
-
|
|
26702
|
-
Object.setPrototypeOf(builder, proto);
|
|
26703
|
-
builder[GENERATOR] = self2;
|
|
26704
|
-
builder[STYLER] = _styler;
|
|
26705
|
-
builder[IS_EMPTY] = _isEmpty;
|
|
26706
|
-
return builder;
|
|
26793
|
+
query.afterResponse = async (response, ctx) => {
|
|
26794
|
+
return await queryLogin.run401Action(response, ctx);
|
|
26707
26795
|
};
|
|
26708
|
-
var
|
|
26709
|
-
|
|
26710
|
-
|
|
26711
|
-
|
|
26712
|
-
|
|
26713
|
-
|
|
26714
|
-
|
|
26796
|
+
var queryLogin = new QueryLoginNode({
|
|
26797
|
+
query,
|
|
26798
|
+
onLoad: async () => {}
|
|
26799
|
+
});
|
|
26800
|
+
var getUrl = (url) => {
|
|
26801
|
+
return new URL("/api/router", url).href;
|
|
26802
|
+
};
|
|
26803
|
+
|
|
26804
|
+
// node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
26805
|
+
var ANSI_BACKGROUND_OFFSET = 10;
|
|
26806
|
+
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
26807
|
+
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
26808
|
+
var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
|
|
26809
|
+
var styles = {
|
|
26810
|
+
modifier: {
|
|
26811
|
+
reset: [0, 0],
|
|
26812
|
+
bold: [1, 22],
|
|
26813
|
+
dim: [2, 22],
|
|
26814
|
+
italic: [3, 23],
|
|
26815
|
+
underline: [4, 24],
|
|
26816
|
+
overline: [53, 55],
|
|
26817
|
+
inverse: [7, 27],
|
|
26818
|
+
hidden: [8, 28],
|
|
26819
|
+
strikethrough: [9, 29]
|
|
26820
|
+
},
|
|
26821
|
+
color: {
|
|
26822
|
+
black: [30, 39],
|
|
26823
|
+
red: [31, 39],
|
|
26824
|
+
green: [32, 39],
|
|
26825
|
+
yellow: [33, 39],
|
|
26826
|
+
blue: [34, 39],
|
|
26827
|
+
magenta: [35, 39],
|
|
26828
|
+
cyan: [36, 39],
|
|
26829
|
+
white: [37, 39],
|
|
26830
|
+
blackBright: [90, 39],
|
|
26831
|
+
gray: [90, 39],
|
|
26832
|
+
grey: [90, 39],
|
|
26833
|
+
redBright: [91, 39],
|
|
26834
|
+
greenBright: [92, 39],
|
|
26835
|
+
yellowBright: [93, 39],
|
|
26836
|
+
blueBright: [94, 39],
|
|
26837
|
+
magentaBright: [95, 39],
|
|
26838
|
+
cyanBright: [96, 39],
|
|
26839
|
+
whiteBright: [97, 39]
|
|
26840
|
+
},
|
|
26841
|
+
bgColor: {
|
|
26842
|
+
bgBlack: [40, 49],
|
|
26843
|
+
bgRed: [41, 49],
|
|
26844
|
+
bgGreen: [42, 49],
|
|
26845
|
+
bgYellow: [43, 49],
|
|
26846
|
+
bgBlue: [44, 49],
|
|
26847
|
+
bgMagenta: [45, 49],
|
|
26848
|
+
bgCyan: [46, 49],
|
|
26849
|
+
bgWhite: [47, 49],
|
|
26850
|
+
bgBlackBright: [100, 49],
|
|
26851
|
+
bgGray: [100, 49],
|
|
26852
|
+
bgGrey: [100, 49],
|
|
26853
|
+
bgRedBright: [101, 49],
|
|
26854
|
+
bgGreenBright: [102, 49],
|
|
26855
|
+
bgYellowBright: [103, 49],
|
|
26856
|
+
bgBlueBright: [104, 49],
|
|
26857
|
+
bgMagentaBright: [105, 49],
|
|
26858
|
+
bgCyanBright: [106, 49],
|
|
26859
|
+
bgWhiteBright: [107, 49]
|
|
26715
26860
|
}
|
|
26716
|
-
|
|
26717
|
-
|
|
26718
|
-
|
|
26719
|
-
|
|
26720
|
-
|
|
26861
|
+
};
|
|
26862
|
+
var modifierNames = Object.keys(styles.modifier);
|
|
26863
|
+
var foregroundColorNames = Object.keys(styles.color);
|
|
26864
|
+
var backgroundColorNames = Object.keys(styles.bgColor);
|
|
26865
|
+
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
26866
|
+
function assembleStyles() {
|
|
26867
|
+
const codes = new Map;
|
|
26868
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
26869
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
26870
|
+
styles[styleName] = {
|
|
26871
|
+
open: `\x1B[${style[0]}m`,
|
|
26872
|
+
close: `\x1B[${style[1]}m`
|
|
26873
|
+
};
|
|
26874
|
+
group[styleName] = styles[styleName];
|
|
26875
|
+
codes.set(style[0], style[1]);
|
|
26721
26876
|
}
|
|
26877
|
+
Object.defineProperty(styles, groupName, {
|
|
26878
|
+
value: group,
|
|
26879
|
+
enumerable: false
|
|
26880
|
+
});
|
|
26722
26881
|
}
|
|
26723
|
-
|
|
26724
|
-
|
|
26725
|
-
|
|
26726
|
-
|
|
26727
|
-
|
|
26728
|
-
|
|
26729
|
-
|
|
26730
|
-
|
|
26731
|
-
|
|
26732
|
-
|
|
26733
|
-
|
|
26734
|
-
|
|
26735
|
-
|
|
26736
|
-
|
|
26737
|
-
|
|
26738
|
-
|
|
26739
|
-
|
|
26740
|
-
|
|
26741
|
-
}
|
|
26742
|
-
|
|
26743
|
-
|
|
26744
|
-
|
|
26745
|
-
|
|
26746
|
-
return eventemitter33.exports;
|
|
26747
|
-
hasRequiredEventemitter33 = 1;
|
|
26748
|
-
(function(module) {
|
|
26749
|
-
var has = Object.prototype.hasOwnProperty, prefix = "~";
|
|
26750
|
-
function Events() {}
|
|
26751
|
-
if (Object.create) {
|
|
26752
|
-
Events.prototype = Object.create(null);
|
|
26753
|
-
if (!new Events().__proto__)
|
|
26754
|
-
prefix = false;
|
|
26755
|
-
}
|
|
26756
|
-
function EE(fn, context, once) {
|
|
26757
|
-
this.fn = fn;
|
|
26758
|
-
this.context = context;
|
|
26759
|
-
this.once = once || false;
|
|
26760
|
-
}
|
|
26761
|
-
function addListener(emitter, event, fn, context, once) {
|
|
26762
|
-
if (typeof fn !== "function") {
|
|
26763
|
-
throw new TypeError("The listener must be a function");
|
|
26764
|
-
}
|
|
26765
|
-
var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
|
|
26766
|
-
if (!emitter._events[evt])
|
|
26767
|
-
emitter._events[evt] = listener, emitter._eventsCount++;
|
|
26768
|
-
else if (!emitter._events[evt].fn)
|
|
26769
|
-
emitter._events[evt].push(listener);
|
|
26770
|
-
else
|
|
26771
|
-
emitter._events[evt] = [emitter._events[evt], listener];
|
|
26772
|
-
return emitter;
|
|
26773
|
-
}
|
|
26774
|
-
function clearEvent(emitter, evt) {
|
|
26775
|
-
if (--emitter._eventsCount === 0)
|
|
26776
|
-
emitter._events = new Events;
|
|
26777
|
-
else
|
|
26778
|
-
delete emitter._events[evt];
|
|
26779
|
-
}
|
|
26780
|
-
function EventEmitter3() {
|
|
26781
|
-
this._events = new Events;
|
|
26782
|
-
this._eventsCount = 0;
|
|
26783
|
-
}
|
|
26784
|
-
EventEmitter3.prototype.eventNames = function eventNames() {
|
|
26785
|
-
var names = [], events, name;
|
|
26786
|
-
if (this._eventsCount === 0)
|
|
26787
|
-
return names;
|
|
26788
|
-
for (name in events = this._events) {
|
|
26789
|
-
if (has.call(events, name))
|
|
26790
|
-
names.push(prefix ? name.slice(1) : name);
|
|
26791
|
-
}
|
|
26792
|
-
if (Object.getOwnPropertySymbols) {
|
|
26793
|
-
return names.concat(Object.getOwnPropertySymbols(events));
|
|
26794
|
-
}
|
|
26795
|
-
return names;
|
|
26796
|
-
};
|
|
26797
|
-
EventEmitter3.prototype.listeners = function listeners(event) {
|
|
26798
|
-
var evt = prefix ? prefix + event : event, handlers = this._events[evt];
|
|
26799
|
-
if (!handlers)
|
|
26800
|
-
return [];
|
|
26801
|
-
if (handlers.fn)
|
|
26802
|
-
return [handlers.fn];
|
|
26803
|
-
for (var i = 0, l = handlers.length, ee = new Array(l);i < l; i++) {
|
|
26804
|
-
ee[i] = handlers[i].fn;
|
|
26805
|
-
}
|
|
26806
|
-
return ee;
|
|
26807
|
-
};
|
|
26808
|
-
EventEmitter3.prototype.listenerCount = function listenerCount(event) {
|
|
26809
|
-
var evt = prefix ? prefix + event : event, listeners = this._events[evt];
|
|
26810
|
-
if (!listeners)
|
|
26811
|
-
return 0;
|
|
26812
|
-
if (listeners.fn)
|
|
26813
|
-
return 1;
|
|
26814
|
-
return listeners.length;
|
|
26815
|
-
};
|
|
26816
|
-
EventEmitter3.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
26817
|
-
var evt = prefix ? prefix + event : event;
|
|
26818
|
-
if (!this._events[evt])
|
|
26819
|
-
return false;
|
|
26820
|
-
var listeners = this._events[evt], len = arguments.length, args, i;
|
|
26821
|
-
if (listeners.fn) {
|
|
26822
|
-
if (listeners.once)
|
|
26823
|
-
this.removeListener(event, listeners.fn, undefined, true);
|
|
26824
|
-
switch (len) {
|
|
26825
|
-
case 1:
|
|
26826
|
-
return listeners.fn.call(listeners.context), true;
|
|
26827
|
-
case 2:
|
|
26828
|
-
return listeners.fn.call(listeners.context, a1), true;
|
|
26829
|
-
case 3:
|
|
26830
|
-
return listeners.fn.call(listeners.context, a1, a2), true;
|
|
26831
|
-
case 4:
|
|
26832
|
-
return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
26833
|
-
case 5:
|
|
26834
|
-
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
26835
|
-
case 6:
|
|
26836
|
-
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
26882
|
+
Object.defineProperty(styles, "codes", {
|
|
26883
|
+
value: codes,
|
|
26884
|
+
enumerable: false
|
|
26885
|
+
});
|
|
26886
|
+
styles.color.close = "\x1B[39m";
|
|
26887
|
+
styles.bgColor.close = "\x1B[49m";
|
|
26888
|
+
styles.color.ansi = wrapAnsi16();
|
|
26889
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
26890
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
26891
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
26892
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
26893
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
26894
|
+
Object.defineProperties(styles, {
|
|
26895
|
+
rgbToAnsi256: {
|
|
26896
|
+
value(red, green, blue) {
|
|
26897
|
+
if (red === green && green === blue) {
|
|
26898
|
+
if (red < 8) {
|
|
26899
|
+
return 16;
|
|
26900
|
+
}
|
|
26901
|
+
if (red > 248) {
|
|
26902
|
+
return 231;
|
|
26903
|
+
}
|
|
26904
|
+
return Math.round((red - 8) / 247 * 24) + 232;
|
|
26837
26905
|
}
|
|
26838
|
-
|
|
26839
|
-
|
|
26906
|
+
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
26907
|
+
},
|
|
26908
|
+
enumerable: false
|
|
26909
|
+
},
|
|
26910
|
+
hexToRgb: {
|
|
26911
|
+
value(hex) {
|
|
26912
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
26913
|
+
if (!matches) {
|
|
26914
|
+
return [0, 0, 0];
|
|
26840
26915
|
}
|
|
26841
|
-
|
|
26842
|
-
|
|
26843
|
-
|
|
26844
|
-
for (i = 0;i < length; i++) {
|
|
26845
|
-
if (listeners[i].once)
|
|
26846
|
-
this.removeListener(event, listeners[i].fn, undefined, true);
|
|
26847
|
-
switch (len) {
|
|
26848
|
-
case 1:
|
|
26849
|
-
listeners[i].fn.call(listeners[i].context);
|
|
26850
|
-
break;
|
|
26851
|
-
case 2:
|
|
26852
|
-
listeners[i].fn.call(listeners[i].context, a1);
|
|
26853
|
-
break;
|
|
26854
|
-
case 3:
|
|
26855
|
-
listeners[i].fn.call(listeners[i].context, a1, a2);
|
|
26856
|
-
break;
|
|
26857
|
-
case 4:
|
|
26858
|
-
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
|
|
26859
|
-
break;
|
|
26860
|
-
default:
|
|
26861
|
-
if (!args)
|
|
26862
|
-
for (j = 1, args = new Array(len - 1);j < len; j++) {
|
|
26863
|
-
args[j - 1] = arguments[j];
|
|
26864
|
-
}
|
|
26865
|
-
listeners[i].fn.apply(listeners[i].context, args);
|
|
26866
|
-
}
|
|
26916
|
+
let [colorString] = matches;
|
|
26917
|
+
if (colorString.length === 3) {
|
|
26918
|
+
colorString = [...colorString].map((character) => character + character).join("");
|
|
26867
26919
|
}
|
|
26868
|
-
|
|
26869
|
-
|
|
26870
|
-
|
|
26871
|
-
|
|
26872
|
-
|
|
26873
|
-
|
|
26874
|
-
|
|
26875
|
-
|
|
26876
|
-
}
|
|
26877
|
-
|
|
26878
|
-
|
|
26879
|
-
|
|
26880
|
-
|
|
26881
|
-
|
|
26882
|
-
|
|
26883
|
-
|
|
26884
|
-
|
|
26885
|
-
var listeners = this._events[evt];
|
|
26886
|
-
if (listeners.fn) {
|
|
26887
|
-
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
|
|
26888
|
-
clearEvent(this, evt);
|
|
26920
|
+
const integer = Number.parseInt(colorString, 16);
|
|
26921
|
+
return [
|
|
26922
|
+
integer >> 16 & 255,
|
|
26923
|
+
integer >> 8 & 255,
|
|
26924
|
+
integer & 255
|
|
26925
|
+
];
|
|
26926
|
+
},
|
|
26927
|
+
enumerable: false
|
|
26928
|
+
},
|
|
26929
|
+
hexToAnsi256: {
|
|
26930
|
+
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
26931
|
+
enumerable: false
|
|
26932
|
+
},
|
|
26933
|
+
ansi256ToAnsi: {
|
|
26934
|
+
value(code) {
|
|
26935
|
+
if (code < 8) {
|
|
26936
|
+
return 30 + code;
|
|
26889
26937
|
}
|
|
26890
|
-
|
|
26891
|
-
|
|
26892
|
-
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
|
|
26893
|
-
events.push(listeners[i]);
|
|
26894
|
-
}
|
|
26938
|
+
if (code < 16) {
|
|
26939
|
+
return 90 + (code - 8);
|
|
26895
26940
|
}
|
|
26896
|
-
|
|
26897
|
-
|
|
26898
|
-
|
|
26899
|
-
|
|
26900
|
-
|
|
26901
|
-
|
|
26902
|
-
|
|
26903
|
-
|
|
26904
|
-
|
|
26905
|
-
|
|
26906
|
-
|
|
26907
|
-
|
|
26908
|
-
|
|
26909
|
-
|
|
26910
|
-
|
|
26911
|
-
|
|
26912
|
-
|
|
26913
|
-
|
|
26914
|
-
|
|
26915
|
-
|
|
26916
|
-
|
|
26917
|
-
|
|
26918
|
-
|
|
26919
|
-
|
|
26920
|
-
|
|
26921
|
-
}
|
|
26922
|
-
|
|
26923
|
-
|
|
26924
|
-
|
|
26925
|
-
|
|
26926
|
-
|
|
26927
|
-
|
|
26928
|
-
|
|
26929
|
-
const interval = promiseOpts.interval || 1000;
|
|
26930
|
-
const checkSuccess = promiseOpts?.checkSuccess || (() => true);
|
|
26931
|
-
const signal = promiseOpts.signal;
|
|
26932
|
-
return new Promise(async (resolve, reject) => {
|
|
26933
|
-
let intervalId;
|
|
26934
|
-
let timeoutId = setTimeout(() => {
|
|
26935
|
-
clearTimeout(intervalId);
|
|
26936
|
-
resolve({
|
|
26937
|
-
code: 500,
|
|
26938
|
-
message: "timeout"
|
|
26939
|
-
});
|
|
26940
|
-
}, timeout);
|
|
26941
|
-
const fn = promiseOpts.fn || (() => true);
|
|
26942
|
-
const runFn = async () => {
|
|
26943
|
-
if (signal?.aborted) {
|
|
26944
|
-
clearInterval(intervalId);
|
|
26945
|
-
clearTimeout(timeoutId);
|
|
26946
|
-
return resolve({
|
|
26947
|
-
code: 499,
|
|
26948
|
-
message: "operation cancelled"
|
|
26949
|
-
});
|
|
26950
|
-
}
|
|
26951
|
-
const res = await fn();
|
|
26952
|
-
if (!!checkSuccess(res)) {
|
|
26953
|
-
clearInterval(intervalId);
|
|
26954
|
-
clearTimeout(timeoutId);
|
|
26955
|
-
resolve({
|
|
26956
|
-
code: 200,
|
|
26957
|
-
data: res
|
|
26958
|
-
});
|
|
26959
|
-
} else {
|
|
26960
|
-
setTimeout(() => {
|
|
26961
|
-
runFn();
|
|
26962
|
-
}, interval);
|
|
26963
|
-
}
|
|
26964
|
-
};
|
|
26965
|
-
if (signal) {
|
|
26966
|
-
signal.addEventListener("abort", () => {
|
|
26967
|
-
clearInterval(intervalId);
|
|
26968
|
-
clearTimeout(timeoutId);
|
|
26969
|
-
resolve({
|
|
26970
|
-
code: 499,
|
|
26971
|
-
message: "operation cancelled"
|
|
26972
|
-
});
|
|
26973
|
-
});
|
|
26941
|
+
let red;
|
|
26942
|
+
let green;
|
|
26943
|
+
let blue;
|
|
26944
|
+
if (code >= 232) {
|
|
26945
|
+
red = ((code - 232) * 10 + 8) / 255;
|
|
26946
|
+
green = red;
|
|
26947
|
+
blue = red;
|
|
26948
|
+
} else {
|
|
26949
|
+
code -= 16;
|
|
26950
|
+
const remainder = code % 36;
|
|
26951
|
+
red = Math.floor(code / 36) / 5;
|
|
26952
|
+
green = Math.floor(remainder / 6) / 5;
|
|
26953
|
+
blue = remainder % 6 / 5;
|
|
26954
|
+
}
|
|
26955
|
+
const value = Math.max(red, green, blue) * 2;
|
|
26956
|
+
if (value === 0) {
|
|
26957
|
+
return 30;
|
|
26958
|
+
}
|
|
26959
|
+
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
26960
|
+
if (value === 2) {
|
|
26961
|
+
result += 60;
|
|
26962
|
+
}
|
|
26963
|
+
return result;
|
|
26964
|
+
},
|
|
26965
|
+
enumerable: false
|
|
26966
|
+
},
|
|
26967
|
+
rgbToAnsi: {
|
|
26968
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
26969
|
+
enumerable: false
|
|
26970
|
+
},
|
|
26971
|
+
hexToAnsi: {
|
|
26972
|
+
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
26973
|
+
enumerable: false
|
|
26974
26974
|
}
|
|
26975
|
-
runFn();
|
|
26976
26975
|
});
|
|
26977
|
-
|
|
26976
|
+
return styles;
|
|
26977
|
+
}
|
|
26978
|
+
var ansiStyles = assembleStyles();
|
|
26979
|
+
var ansi_styles_default = ansiStyles;
|
|
26978
26980
|
|
|
26979
|
-
|
|
26980
|
-
|
|
26981
|
-
|
|
26982
|
-
|
|
26983
|
-
|
|
26984
|
-
|
|
26985
|
-
|
|
26986
|
-
|
|
26987
|
-
|
|
26981
|
+
// node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js
|
|
26982
|
+
import process4 from "node:process";
|
|
26983
|
+
import os2 from "node:os";
|
|
26984
|
+
import tty from "node:tty";
|
|
26985
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process4.argv) {
|
|
26986
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
26987
|
+
const position = argv.indexOf(prefix + flag);
|
|
26988
|
+
const terminatorPosition = argv.indexOf("--");
|
|
26989
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
26990
|
+
}
|
|
26991
|
+
var { env } = process4;
|
|
26992
|
+
var flagForceColor;
|
|
26993
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
26994
|
+
flagForceColor = 0;
|
|
26995
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
26996
|
+
flagForceColor = 1;
|
|
26997
|
+
}
|
|
26998
|
+
function envForceColor() {
|
|
26999
|
+
if ("FORCE_COLOR" in env) {
|
|
27000
|
+
if (env.FORCE_COLOR === "true") {
|
|
27001
|
+
return 1;
|
|
27002
|
+
}
|
|
27003
|
+
if (env.FORCE_COLOR === "false") {
|
|
27004
|
+
return 0;
|
|
27005
|
+
}
|
|
27006
|
+
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
26988
27007
|
}
|
|
26989
|
-
|
|
26990
|
-
|
|
26991
|
-
|
|
26992
|
-
|
|
26993
|
-
this.event.removeListener(key, onEvent);
|
|
26994
|
-
resolve({
|
|
26995
|
-
code: 500,
|
|
26996
|
-
message: "timeout"
|
|
26997
|
-
});
|
|
26998
|
-
}, timeout);
|
|
26999
|
-
const onEvent = (error) => {
|
|
27000
|
-
clearTimeout(timeoutId);
|
|
27001
|
-
if (error) {
|
|
27002
|
-
return resolve({
|
|
27003
|
-
code: 500,
|
|
27004
|
-
message: error
|
|
27005
|
-
});
|
|
27006
|
-
}
|
|
27007
|
-
const data = this.modules.get(key);
|
|
27008
|
-
if (data?.loadSuccessClear) {
|
|
27009
|
-
this.remove(key);
|
|
27010
|
-
}
|
|
27011
|
-
resolve({
|
|
27012
|
-
code: 200,
|
|
27013
|
-
data: data?.modules
|
|
27014
|
-
});
|
|
27015
|
-
};
|
|
27016
|
-
this.event.once(key, onEvent);
|
|
27017
|
-
});
|
|
27008
|
+
}
|
|
27009
|
+
function translateLevel(level) {
|
|
27010
|
+
if (level === 0) {
|
|
27011
|
+
return false;
|
|
27018
27012
|
}
|
|
27019
|
-
|
|
27020
|
-
|
|
27021
|
-
|
|
27022
|
-
|
|
27023
|
-
|
|
27024
|
-
|
|
27013
|
+
return {
|
|
27014
|
+
level,
|
|
27015
|
+
hasBasic: true,
|
|
27016
|
+
has256: level >= 2,
|
|
27017
|
+
has16m: level >= 3
|
|
27018
|
+
};
|
|
27019
|
+
}
|
|
27020
|
+
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
27021
|
+
const noFlagForceColor = envForceColor();
|
|
27022
|
+
if (noFlagForceColor !== undefined) {
|
|
27023
|
+
flagForceColor = noFlagForceColor;
|
|
27024
|
+
}
|
|
27025
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
27026
|
+
if (forceColor === 0) {
|
|
27027
|
+
return 0;
|
|
27028
|
+
}
|
|
27029
|
+
if (sniffFlags) {
|
|
27030
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
27031
|
+
return 3;
|
|
27025
27032
|
}
|
|
27026
|
-
|
|
27027
|
-
|
|
27028
|
-
const isExist = hasLoadOpts?.isExist ?? true;
|
|
27029
|
-
const timeout = hasLoadOpts?.timeout ?? this.timeout;
|
|
27030
|
-
if (isExist) {
|
|
27031
|
-
return await this.listenKey(key, { timeout });
|
|
27032
|
-
}
|
|
27033
|
-
return {
|
|
27034
|
-
code: 404
|
|
27035
|
-
};
|
|
27033
|
+
if (hasFlag("color=256")) {
|
|
27034
|
+
return 2;
|
|
27036
27035
|
}
|
|
27037
|
-
|
|
27038
|
-
|
|
27039
|
-
|
|
27040
|
-
|
|
27041
|
-
|
|
27042
|
-
|
|
27036
|
+
}
|
|
27037
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
27038
|
+
return 1;
|
|
27039
|
+
}
|
|
27040
|
+
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
27041
|
+
return 0;
|
|
27042
|
+
}
|
|
27043
|
+
const min = forceColor || 0;
|
|
27044
|
+
if (env.TERM === "dumb") {
|
|
27045
|
+
return min;
|
|
27046
|
+
}
|
|
27047
|
+
if (process4.platform === "win32") {
|
|
27048
|
+
const osRelease = os2.release().split(".");
|
|
27049
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
27050
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
27043
27051
|
}
|
|
27044
|
-
|
|
27045
|
-
|
|
27052
|
+
return 1;
|
|
27053
|
+
}
|
|
27054
|
+
if ("CI" in env) {
|
|
27055
|
+
if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => (key in env))) {
|
|
27056
|
+
return 3;
|
|
27046
27057
|
}
|
|
27047
|
-
if (
|
|
27048
|
-
return
|
|
27049
|
-
code: 500,
|
|
27050
|
-
message: "load error"
|
|
27051
|
-
};
|
|
27058
|
+
if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => (sign in env)) || env.CI_NAME === "codeship") {
|
|
27059
|
+
return 1;
|
|
27052
27060
|
}
|
|
27053
|
-
|
|
27054
|
-
|
|
27055
|
-
|
|
27056
|
-
|
|
27057
|
-
|
|
27061
|
+
return min;
|
|
27062
|
+
}
|
|
27063
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
27064
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
27065
|
+
}
|
|
27066
|
+
if (env.COLORTERM === "truecolor") {
|
|
27067
|
+
return 3;
|
|
27068
|
+
}
|
|
27069
|
+
if (env.TERM === "xterm-kitty") {
|
|
27070
|
+
return 3;
|
|
27071
|
+
}
|
|
27072
|
+
if (env.TERM === "xterm-ghostty") {
|
|
27073
|
+
return 3;
|
|
27074
|
+
}
|
|
27075
|
+
if (env.TERM === "wezterm") {
|
|
27076
|
+
return 3;
|
|
27077
|
+
}
|
|
27078
|
+
if ("TERM_PROGRAM" in env) {
|
|
27079
|
+
const version2 = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
27080
|
+
switch (env.TERM_PROGRAM) {
|
|
27081
|
+
case "iTerm.app": {
|
|
27082
|
+
return version2 >= 3 ? 3 : 2;
|
|
27083
|
+
}
|
|
27084
|
+
case "Apple_Terminal": {
|
|
27085
|
+
return 2;
|
|
27086
|
+
}
|
|
27087
|
+
}
|
|
27088
|
+
}
|
|
27089
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
27090
|
+
return 2;
|
|
27091
|
+
}
|
|
27092
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
27093
|
+
return 1;
|
|
27094
|
+
}
|
|
27095
|
+
if ("COLORTERM" in env) {
|
|
27096
|
+
return 1;
|
|
27097
|
+
}
|
|
27098
|
+
return min;
|
|
27099
|
+
}
|
|
27100
|
+
function createSupportsColor(stream, options = {}) {
|
|
27101
|
+
const level = _supportsColor(stream, {
|
|
27102
|
+
streamIsTTY: stream && stream.isTTY,
|
|
27103
|
+
...options
|
|
27104
|
+
});
|
|
27105
|
+
return translateLevel(level);
|
|
27106
|
+
}
|
|
27107
|
+
var supportsColor = {
|
|
27108
|
+
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
|
27109
|
+
stderr: createSupportsColor({ isTTY: tty.isatty(2) })
|
|
27110
|
+
};
|
|
27111
|
+
var supports_color_default = supportsColor;
|
|
27112
|
+
|
|
27113
|
+
// node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js
|
|
27114
|
+
function stringReplaceAll(string, substring, replacer) {
|
|
27115
|
+
let index = string.indexOf(substring);
|
|
27116
|
+
if (index === -1) {
|
|
27117
|
+
return string;
|
|
27118
|
+
}
|
|
27119
|
+
const substringLength = substring.length;
|
|
27120
|
+
let endIndex = 0;
|
|
27121
|
+
let returnValue = "";
|
|
27122
|
+
do {
|
|
27123
|
+
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
27124
|
+
endIndex = index + substringLength;
|
|
27125
|
+
index = string.indexOf(substring, endIndex);
|
|
27126
|
+
} while (index !== -1);
|
|
27127
|
+
returnValue += string.slice(endIndex);
|
|
27128
|
+
return returnValue;
|
|
27129
|
+
}
|
|
27130
|
+
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
27131
|
+
let endIndex = 0;
|
|
27132
|
+
let returnValue = "";
|
|
27133
|
+
do {
|
|
27134
|
+
const gotCR = string[index - 1] === "\r";
|
|
27135
|
+
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? `\r
|
|
27136
|
+
` : `
|
|
27137
|
+
`) + postfix;
|
|
27138
|
+
endIndex = index + 1;
|
|
27139
|
+
index = string.indexOf(`
|
|
27140
|
+
`, endIndex);
|
|
27141
|
+
} while (index !== -1);
|
|
27142
|
+
returnValue += string.slice(endIndex);
|
|
27143
|
+
return returnValue;
|
|
27144
|
+
}
|
|
27145
|
+
|
|
27146
|
+
// node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
|
|
27147
|
+
var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
|
|
27148
|
+
var GENERATOR = Symbol("GENERATOR");
|
|
27149
|
+
var STYLER = Symbol("STYLER");
|
|
27150
|
+
var IS_EMPTY = Symbol("IS_EMPTY");
|
|
27151
|
+
var levelMapping = [
|
|
27152
|
+
"ansi",
|
|
27153
|
+
"ansi",
|
|
27154
|
+
"ansi256",
|
|
27155
|
+
"ansi16m"
|
|
27156
|
+
];
|
|
27157
|
+
var styles2 = Object.create(null);
|
|
27158
|
+
var applyOptions = (object, options = {}) => {
|
|
27159
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
27160
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
27161
|
+
}
|
|
27162
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
27163
|
+
object.level = options.level === undefined ? colorLevel : options.level;
|
|
27164
|
+
};
|
|
27165
|
+
|
|
27166
|
+
class Chalk {
|
|
27167
|
+
constructor(options) {
|
|
27168
|
+
return chalkFactory(options);
|
|
27169
|
+
}
|
|
27170
|
+
}
|
|
27171
|
+
var chalkFactory = (options) => {
|
|
27172
|
+
const chalk = (...strings) => strings.join(" ");
|
|
27173
|
+
applyOptions(chalk, options);
|
|
27174
|
+
Object.setPrototypeOf(chalk, createChalk.prototype);
|
|
27175
|
+
return chalk;
|
|
27176
|
+
};
|
|
27177
|
+
function createChalk(options) {
|
|
27178
|
+
return chalkFactory(options);
|
|
27179
|
+
}
|
|
27180
|
+
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
27181
|
+
for (const [styleName, style] of Object.entries(ansi_styles_default)) {
|
|
27182
|
+
styles2[styleName] = {
|
|
27183
|
+
get() {
|
|
27184
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
27185
|
+
Object.defineProperty(this, styleName, { value: builder });
|
|
27186
|
+
return builder;
|
|
27058
27187
|
}
|
|
27059
|
-
|
|
27060
|
-
|
|
27061
|
-
|
|
27188
|
+
};
|
|
27189
|
+
}
|
|
27190
|
+
styles2.visible = {
|
|
27191
|
+
get() {
|
|
27192
|
+
const builder = createBuilder(this, this[STYLER], true);
|
|
27193
|
+
Object.defineProperty(this, "visible", { value: builder });
|
|
27194
|
+
return builder;
|
|
27062
27195
|
}
|
|
27063
|
-
|
|
27064
|
-
|
|
27065
|
-
|
|
27066
|
-
|
|
27067
|
-
|
|
27068
|
-
message: "key is required"
|
|
27069
|
-
};
|
|
27196
|
+
};
|
|
27197
|
+
var getModelAnsi = (model, level, type, ...arguments_) => {
|
|
27198
|
+
if (model === "rgb") {
|
|
27199
|
+
if (level === "ansi16m") {
|
|
27200
|
+
return ansi_styles_default[type].ansi16m(...arguments_);
|
|
27070
27201
|
}
|
|
27071
|
-
|
|
27072
|
-
|
|
27073
|
-
status: "loading",
|
|
27074
|
-
loading: true,
|
|
27075
|
-
loadSuccessClear: opts.loadSuccessClear ?? true
|
|
27076
|
-
};
|
|
27077
|
-
let errorMessage = "";
|
|
27078
|
-
try {
|
|
27079
|
-
const isReRun = opts.isReRun ?? false;
|
|
27080
|
-
let res;
|
|
27081
|
-
if (!isReRun) {
|
|
27082
|
-
this.modules.set(key, newModule);
|
|
27083
|
-
res = await loadContent();
|
|
27084
|
-
} else {
|
|
27085
|
-
newModule.controller = new AbortController;
|
|
27086
|
-
const signal = newModule.controller.signal;
|
|
27087
|
-
this.modules.set(key, newModule);
|
|
27088
|
-
const data = await reRunFn3({
|
|
27089
|
-
timeout: opts.timeout,
|
|
27090
|
-
interval: opts.interval,
|
|
27091
|
-
checkSuccess: opts.checkSuccess,
|
|
27092
|
-
fn: loadContent,
|
|
27093
|
-
signal
|
|
27094
|
-
});
|
|
27095
|
-
newModule.controller = null;
|
|
27096
|
-
if (data.code === 499) {
|
|
27097
|
-
newModule.status = "cancel";
|
|
27098
|
-
return {
|
|
27099
|
-
code: 499,
|
|
27100
|
-
message: "operation cancelled"
|
|
27101
|
-
};
|
|
27102
|
-
}
|
|
27103
|
-
if (data.code !== 200) {
|
|
27104
|
-
throw new Error(data.message);
|
|
27105
|
-
}
|
|
27106
|
-
res = data.data;
|
|
27107
|
-
}
|
|
27108
|
-
newModule.modules = res;
|
|
27109
|
-
newModule.status = "loaded";
|
|
27110
|
-
return {
|
|
27111
|
-
code: 200,
|
|
27112
|
-
data: res
|
|
27113
|
-
};
|
|
27114
|
-
} catch (error) {
|
|
27115
|
-
errorMessage = error.message;
|
|
27116
|
-
newModule.status = "error";
|
|
27117
|
-
return {
|
|
27118
|
-
code: 500,
|
|
27119
|
-
message: error
|
|
27120
|
-
};
|
|
27121
|
-
} finally {
|
|
27122
|
-
newModule.loading = false;
|
|
27123
|
-
this.modules.set(opts.key, newModule);
|
|
27124
|
-
if (!errorMessage) {
|
|
27125
|
-
this.event.emit(opts.key);
|
|
27126
|
-
} else {
|
|
27127
|
-
this.event.emit(opts.key, errorMessage);
|
|
27128
|
-
}
|
|
27202
|
+
if (level === "ansi256") {
|
|
27203
|
+
return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
|
|
27129
27204
|
}
|
|
27205
|
+
return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
|
|
27130
27206
|
}
|
|
27131
|
-
|
|
27132
|
-
|
|
27133
|
-
|
|
27134
|
-
|
|
27135
|
-
|
|
27136
|
-
|
|
27137
|
-
|
|
27207
|
+
if (model === "hex") {
|
|
27208
|
+
return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
|
|
27209
|
+
}
|
|
27210
|
+
return ansi_styles_default[type][model](...arguments_);
|
|
27211
|
+
};
|
|
27212
|
+
var usedModels = ["rgb", "hex", "ansi256"];
|
|
27213
|
+
for (const model of usedModels) {
|
|
27214
|
+
styles2[model] = {
|
|
27215
|
+
get() {
|
|
27216
|
+
const { level } = this;
|
|
27217
|
+
return function(...arguments_) {
|
|
27218
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
|
27219
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
27138
27220
|
};
|
|
27139
27221
|
}
|
|
27140
|
-
|
|
27141
|
-
|
|
27142
|
-
|
|
27143
|
-
|
|
27144
|
-
|
|
27145
|
-
return
|
|
27146
|
-
|
|
27147
|
-
|
|
27148
|
-
|
|
27222
|
+
};
|
|
27223
|
+
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
27224
|
+
styles2[bgModel] = {
|
|
27225
|
+
get() {
|
|
27226
|
+
const { level } = this;
|
|
27227
|
+
return function(...arguments_) {
|
|
27228
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
|
|
27229
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
27230
|
+
};
|
|
27149
27231
|
}
|
|
27150
|
-
|
|
27151
|
-
|
|
27152
|
-
|
|
27153
|
-
|
|
27154
|
-
|
|
27155
|
-
|
|
27156
|
-
|
|
27232
|
+
};
|
|
27233
|
+
}
|
|
27234
|
+
var proto = Object.defineProperties(() => {}, {
|
|
27235
|
+
...styles2,
|
|
27236
|
+
level: {
|
|
27237
|
+
enumerable: true,
|
|
27238
|
+
get() {
|
|
27239
|
+
return this[GENERATOR].level;
|
|
27240
|
+
},
|
|
27241
|
+
set(level) {
|
|
27242
|
+
this[GENERATOR].level = level;
|
|
27157
27243
|
}
|
|
27158
27244
|
}
|
|
27159
|
-
|
|
27160
|
-
|
|
27161
|
-
|
|
27245
|
+
});
|
|
27246
|
+
var createStyler = (open, close, parent) => {
|
|
27247
|
+
let openAll;
|
|
27248
|
+
let closeAll;
|
|
27249
|
+
if (parent === undefined) {
|
|
27250
|
+
openAll = open;
|
|
27251
|
+
closeAll = close;
|
|
27252
|
+
} else {
|
|
27253
|
+
openAll = parent.openAll + open;
|
|
27254
|
+
closeAll = close + parent.closeAll;
|
|
27162
27255
|
}
|
|
27163
|
-
|
|
27164
|
-
|
|
27165
|
-
|
|
27166
|
-
|
|
27167
|
-
|
|
27168
|
-
|
|
27169
|
-
|
|
27170
|
-
|
|
27171
|
-
|
|
27172
|
-
|
|
27173
|
-
|
|
27256
|
+
return {
|
|
27257
|
+
open,
|
|
27258
|
+
close,
|
|
27259
|
+
openAll,
|
|
27260
|
+
closeAll,
|
|
27261
|
+
parent
|
|
27262
|
+
};
|
|
27263
|
+
};
|
|
27264
|
+
var createBuilder = (self2, _styler, _isEmpty) => {
|
|
27265
|
+
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
27266
|
+
Object.setPrototypeOf(builder, proto);
|
|
27267
|
+
builder[GENERATOR] = self2;
|
|
27268
|
+
builder[STYLER] = _styler;
|
|
27269
|
+
builder[IS_EMPTY] = _isEmpty;
|
|
27270
|
+
return builder;
|
|
27271
|
+
};
|
|
27272
|
+
var applyStyle = (self2, string) => {
|
|
27273
|
+
if (self2.level <= 0 || !string) {
|
|
27274
|
+
return self2[IS_EMPTY] ? "" : string;
|
|
27174
27275
|
}
|
|
27175
|
-
|
|
27176
|
-
|
|
27276
|
+
let styler = self2[STYLER];
|
|
27277
|
+
if (styler === undefined) {
|
|
27278
|
+
return string;
|
|
27177
27279
|
}
|
|
27178
|
-
|
|
27179
|
-
|
|
27180
|
-
|
|
27181
|
-
|
|
27182
|
-
|
|
27183
|
-
this.modules.set(key, data);
|
|
27280
|
+
const { openAll, closeAll } = styler;
|
|
27281
|
+
if (string.includes("\x1B")) {
|
|
27282
|
+
while (styler !== undefined) {
|
|
27283
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
27284
|
+
styler = styler.parent;
|
|
27184
27285
|
}
|
|
27185
27286
|
}
|
|
27186
|
-
|
|
27287
|
+
const lfIndex = string.indexOf(`
|
|
27288
|
+
`);
|
|
27289
|
+
if (lfIndex !== -1) {
|
|
27290
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
27291
|
+
}
|
|
27292
|
+
return openAll + string + closeAll;
|
|
27293
|
+
};
|
|
27294
|
+
Object.defineProperties(createChalk.prototype, styles2);
|
|
27295
|
+
var chalk = createChalk();
|
|
27296
|
+
var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
27297
|
+
var source_default = chalk;
|
|
27298
|
+
|
|
27299
|
+
// src/module/chalk.ts
|
|
27300
|
+
var chalk2 = new Chalk({ level: 3 });
|
|
27187
27301
|
|
|
27188
27302
|
// src/module/login/login-by-web.ts
|
|
27189
27303
|
var pollLoginStatus = async (token, opts) => {
|
|
@@ -31185,7 +31299,7 @@ class QueryRouterServer extends QueryRouter {
|
|
|
31185
31299
|
}
|
|
31186
31300
|
|
|
31187
31301
|
// node_modules/.pnpm/@kevisual+context@0.0.4/node_modules/@kevisual/context/dist/app.js
|
|
31188
|
-
var
|
|
31302
|
+
var isBrowser3 = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
31189
31303
|
function getDefaultExportFromCjs4(x) {
|
|
31190
31304
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
31191
31305
|
}
|
|
@@ -33601,7 +33715,7 @@ function mitt_default(n) {
|
|
|
33601
33715
|
}
|
|
33602
33716
|
|
|
33603
33717
|
// node_modules/.pnpm/@kevisual+app@0.0.2_dotenv@17.3.1/node_modules/@kevisual/app/src/app.ts
|
|
33604
|
-
var
|
|
33718
|
+
var isBrowser5 = typeof window !== "undefined";
|
|
33605
33719
|
|
|
33606
33720
|
class App {
|
|
33607
33721
|
#router;
|
|
@@ -33620,7 +33734,7 @@ class App {
|
|
|
33620
33734
|
if (opts?.storage) {
|
|
33621
33735
|
this.storage = opts.storage;
|
|
33622
33736
|
} else {
|
|
33623
|
-
if (
|
|
33737
|
+
if (isBrowser5) {
|
|
33624
33738
|
this.storage = sessionStorage;
|
|
33625
33739
|
} else {
|
|
33626
33740
|
console.warn("没有提供 storage,某些功能可能无法使用");
|
|
@@ -33664,7 +33778,7 @@ class App {
|
|
|
33664
33778
|
return this.ai;
|
|
33665
33779
|
}
|
|
33666
33780
|
get token() {
|
|
33667
|
-
if (
|
|
33781
|
+
if (isBrowser5 && !this.#token) {
|
|
33668
33782
|
this.#token = localStorage?.getItem("token") || "";
|
|
33669
33783
|
return this.#token;
|
|
33670
33784
|
}
|
|
@@ -33695,7 +33809,7 @@ class App {
|
|
|
33695
33809
|
}
|
|
33696
33810
|
const data = res.data || {};
|
|
33697
33811
|
const config2 = data.data || {};
|
|
33698
|
-
if (
|
|
33812
|
+
if (isBrowser5) {
|
|
33699
33813
|
this.storage?.setItem?.(`config_${key}`, JSON.stringify(config2));
|
|
33700
33814
|
}
|
|
33701
33815
|
return config2;
|