hifun-tools 1.4.49 → 1.4.51

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.
@@ -3,45 +3,50 @@
3
3
  * @param path - 相对路径,如 "tenant/config.json" 或 "tenant/logo.png"
4
4
  */
5
5
  export function getResource(path) {
6
- const isVite = typeof import.meta !== "undefined" && !!import.meta.env;
7
- const isWebpack = typeof __webpack_require__ === "function" ||
8
- (typeof require !== "undefined" &&
9
- typeof require.context === "function");
10
- if (process.env.__rspack__) {
11
- return;
12
- }
13
- else if (isVite && import.meta?.glob) {
14
- // ---------------- VITE ----------------
15
- const modules = import.meta?.glob([
16
- "/config/**/*.json",
17
- "/config/**/*.png",
18
- "/config/**/*.jpg",
19
- "/config/**/*.jpeg",
20
- "/config/**/*.svg",
21
- "/config/**/*.webp",
22
- ], {
23
- eager: true,
24
- import: "default",
25
- });
26
- const match = Object.entries(modules).find(([key]) => key.endsWith(path));
27
- if (!match) {
28
- console.warn(`[getResource] 未找到文件: ${path}`);
29
- return null;
6
+ try {
7
+ const isVite = typeof import.meta !== "undefined" && !!import.meta.env;
8
+ const isWebpack = typeof __webpack_require__ === "function" ||
9
+ (typeof require !== "undefined" &&
10
+ typeof require.context === "function");
11
+ if (process.env.__rspack__) {
12
+ return;
30
13
  }
31
- const [, mod] = match;
32
- return mod;
33
- }
34
- else if (isWebpack) {
35
- // ---------------- WEBPACK ----------------
36
- const ctx = require.context("/config", true, /\.(json|png|jpg|jpeg|svg|webp)$/);
37
- const files = ctx.keys();
38
- const match = files.find((key) => key.endsWith(path));
39
- if (!match) {
40
- console.warn(`[getResource] 未找到文件: ${path}`);
41
- return null;
14
+ else if (isVite && import.meta?.glob) {
15
+ // ---------------- VITE ----------------
16
+ const modules = import.meta?.glob([
17
+ "/config/**/*.json",
18
+ "/config/**/*.png",
19
+ "/config/**/*.jpg",
20
+ "/config/**/*.jpeg",
21
+ "/config/**/*.svg",
22
+ "/config/**/*.webp",
23
+ ], {
24
+ eager: true,
25
+ import: "default",
26
+ });
27
+ const match = Object.entries(modules).find(([key]) => key.endsWith(path));
28
+ if (!match) {
29
+ console.warn(`[getResource] 未找到文件: ${path}`);
30
+ return null;
31
+ }
32
+ const [, mod] = match;
33
+ return mod;
42
34
  }
43
- return ctx(match);
35
+ else if (isWebpack) {
36
+ // ---------------- WEBPACK ----------------
37
+ const ctx = require.context("/config", true, /\.(json|png|jpg|jpeg|svg|webp)$/);
38
+ const files = ctx.keys();
39
+ const match = files.find((key) => key.endsWith(path));
40
+ if (!match) {
41
+ console.warn(`[getResource] 未找到文件: ${path}`);
42
+ return null;
43
+ }
44
+ return ctx(match);
45
+ }
46
+ console.error("[getResource] 不支持的构建环境(需要 Vite 或 Webpack)");
47
+ return null;
48
+ }
49
+ catch (error) {
50
+ return null;
44
51
  }
45
- console.error("[getResource] 不支持的构建环境(需要 Vite 或 Webpack)");
46
- return null;
47
52
  }
@@ -59,6 +59,10 @@ class InitCls {
59
59
  // ✨ 将 lineAddressData 传递给加载方法
60
60
  results.push(await this._loadGatewayConfig(retry, lineAddressData));
61
61
  }
62
+ else if (defaultBaseUrl) {
63
+ this.domainBaseUrl = defaultBaseUrl;
64
+ results.push(this.domainBaseUrl);
65
+ }
62
66
  console.info("✅ 所有初始化完成:", results);
63
67
  return results;
64
68
  }
@@ -372,64 +376,79 @@ class InitCls {
372
376
  const tenantDictList = this.getTenantDictList().filter((a) => !this.ErrorDomainUrl.includes(a.lineGroup));
373
377
  this.domainBaseUrl = this.defaultBaseUrl;
374
378
  console.info(`✅ defaultBaseUrl 可用,响应时间: ${this.speedDelay}ms`);
375
- // 尝试获取 OriginBaseUrl 数据,不用于测速,仅用于设置 OriginBaseUrl
376
- let originBaseUrlRetrieved = false;
377
- // 1. 尝试使用传入的 lineAddressData
378
- if (lineAddressData && !originBaseUrlRetrieved) {
379
- try {
380
- const originBaseUrl = JSON.parse(AesDecrypt(lineAddressData));
381
- this.OriginBaseUrl = filterSmartLines(tenantDictList, originBaseUrl);
382
- if (this.OriginBaseUrl.length > 0)
383
- originBaseUrlRetrieved = true;
384
- console.info("✅ 使用传入的 lineAddressData 设置 OriginBaseUrl");
385
- }
386
- catch (err) {
387
- console.info("⚠️ 传入的 lineAddressData 解析失败,尝试其他方式");
388
- }
389
- }
390
- // 2. 尝试获取远程 lineAddress.txt
391
- if (!originBaseUrlRetrieved) {
392
- try {
393
- console.info("🌐 尝试获取远程 lineAddress.txt 设置 OriginBaseUrl...");
394
- const response = await fetch(`/lineAddress.txt?t=${Date.now()}`);
395
- if (response.ok) {
396
- const configText = await response.text();
397
- const originBaseUrl = JSON.parse(AesDecrypt(configText));
379
+ // 立即返回结果,同时在后台执行后续逻辑
380
+ (async () => {
381
+ // 尝试获取 OriginBaseUrl 数据,不用于测速,仅用于设置 OriginBaseUrl
382
+ let originBaseUrlRetrieved = false;
383
+ // 1. 尝试使用传入的 lineAddressData
384
+ if (lineAddressData && !originBaseUrlRetrieved) {
385
+ try {
386
+ const originBaseUrl = JSON.parse(AesDecrypt(lineAddressData));
398
387
  this.OriginBaseUrl = filterSmartLines(tenantDictList, originBaseUrl);
399
388
  if (this.OriginBaseUrl.length > 0)
400
389
  originBaseUrlRetrieved = true;
401
- console.info("✅ 使用远程 lineAddress.txt 设置 OriginBaseUrl");
390
+ console.info("✅ 使用传入的 lineAddressData 设置 OriginBaseUrl");
391
+ }
392
+ catch (err) {
393
+ console.info("⚠️ 传入的 lineAddressData 解析失败,尝试其他方式");
402
394
  }
403
395
  }
404
- catch (err) {
405
- console.info("⚠️ 获取远程 lineAddress.txt 失败,尝试备用地址");
396
+ // 2. 尝试获取远程 lineAddress.txt
397
+ if (!originBaseUrlRetrieved) {
398
+ try {
399
+ console.info("🌐 尝试获取远程 lineAddress.txt 设置 OriginBaseUrl...");
400
+ const response = await fetch(`/lineAddress.txt?t=${Date.now()}`);
401
+ if (response.ok) {
402
+ const configText = await response.text();
403
+ const originBaseUrl = JSON.parse(AesDecrypt(configText));
404
+ if (tenantDictList.length > 1) {
405
+ this.OriginBaseUrl = filterSmartLines(tenantDictList, originBaseUrl);
406
+ if (this.OriginBaseUrl.length > 0)
407
+ originBaseUrlRetrieved = true;
408
+ }
409
+ else {
410
+ this.OriginBaseUrl = originBaseUrl;
411
+ originBaseUrlRetrieved = true;
412
+ }
413
+ console.info("✅ 使用远程 lineAddress.txt 设置 OriginBaseUrl");
414
+ }
415
+ }
416
+ catch (err) {
417
+ console.info("⚠️ 获取远程 lineAddress.txt 失败,尝试备用地址");
418
+ }
406
419
  }
407
- }
408
- // 3. 尝试备用地址
409
- if (!originBaseUrlRetrieved) {
410
- try {
411
- console.info(" ambulance 尝试备用地址设置 OriginBaseUrl...");
412
- if (this.tenant === "t1sport")
413
- this.backupAddress = t1BackGateWay;
414
- const backupRaw = await this.fetchTxtFile(this.backupAddress);
415
- if (backupRaw) {
416
- const backupList = JSON.parse(AesDecrypt(backupRaw));
417
- this.backupAddressList = backupList || [];
418
- this.OriginBaseUrl = filterSmartLines(tenantDictList, this.backupAddressList);
419
- if (this.OriginBaseUrl.length > 0)
420
- originBaseUrlRetrieved = true;
421
- console.info("✅ 使用备用地址设置 OriginBaseUrl");
420
+ // 3. 尝试备用地址
421
+ if (!originBaseUrlRetrieved) {
422
+ try {
423
+ console.info("🚑 尝试备用地址设置 OriginBaseUrl...");
424
+ if (this.tenant === "t1sport")
425
+ this.backupAddress = t1BackGateWay;
426
+ const backupRaw = await this.fetchTxtFile(this.backupAddress);
427
+ if (backupRaw) {
428
+ const backupList = JSON.parse(AesDecrypt(backupRaw));
429
+ this.backupAddressList = backupList || [];
430
+ if (tenantDictList.length > 1) {
431
+ this.OriginBaseUrl = filterSmartLines(tenantDictList, this.backupAddressList);
432
+ if (this.OriginBaseUrl.length > 0)
433
+ originBaseUrlRetrieved = true;
434
+ }
435
+ else {
436
+ this.OriginBaseUrl = this.backupAddressList;
437
+ originBaseUrlRetrieved = true;
438
+ }
439
+ console.info("✅ 使用备用地址设置 OriginBaseUrl");
440
+ }
441
+ }
442
+ catch (err) {
443
+ console.info("⚠️ 备用地址获取失败");
422
444
  }
423
445
  }
424
- catch (err) {
425
- console.info("⚠️ 备用地址获取失败");
446
+ // 如果所有方式都失败了,至少保留 defaultBaseUrl
447
+ if (!originBaseUrlRetrieved) {
448
+ this.OriginBaseUrl = [this.defaultBaseUrl];
449
+ console.info("📋 使用 defaultBaseUrl 设置 OriginBaseUrl(兜底方案)");
426
450
  }
427
- }
428
- // 如果所有方式都失败了,至少保留 defaultBaseUrl
429
- if (!originBaseUrlRetrieved) {
430
- this.OriginBaseUrl = [this.defaultBaseUrl];
431
- console.info("📋 使用 defaultBaseUrl 设置 OriginBaseUrl(兜底方案)");
432
- }
451
+ })(); // 立即执行,但不等待
433
452
  return this.domainBaseUrl;
434
453
  }
435
454
  else {
@@ -160,7 +160,13 @@ export async function HttpServer(endpoint, params = {}, method = "GET", options
160
160
  // 生成 UDID / 签名 / baseUrl
161
161
  const udid = await generateUdid();
162
162
  const baseUrl = HF.getBaseUrl();
163
- const fullUrl = new URL(endpoint, baseUrl).toString();
163
+ let fullUrl;
164
+ try {
165
+ fullUrl = new URL(endpoint, baseUrl).toString();
166
+ }
167
+ catch (error) {
168
+ fullUrl = baseUrl + endpoint;
169
+ }
164
170
  const timestamp = Date.now();
165
171
  const lang = getParams("lang") || "YN";
166
172
  // 组装公共字段(注意:不强制覆盖用户 bodyParams)
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.4.48";
1
+ export declare const VERSION = "1.4.50";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.4.48";
1
+ export const VERSION = "1.4.50";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hifun-tools",
3
- "version": "1.4.49",
3
+ "version": "1.4.51",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",