hifun-tools 1.4.17 → 1.4.18
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/init/index.d.ts +6 -0
- package/dist/init/index.js +52 -29
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/init/index.d.ts
CHANGED
|
@@ -6,12 +6,15 @@ declare class InitCls {
|
|
|
6
6
|
private appGateway;
|
|
7
7
|
private appLine;
|
|
8
8
|
private appTenant;
|
|
9
|
+
private backupAddress;
|
|
10
|
+
private backupAddressList;
|
|
9
11
|
private defaultBaseUrl;
|
|
10
12
|
private domainBaseUrl;
|
|
11
13
|
private ErrorDomainUrl;
|
|
12
14
|
private initialized;
|
|
13
15
|
isRefreshNow: boolean;
|
|
14
16
|
private localPath;
|
|
17
|
+
private OriginBaseUrl;
|
|
15
18
|
private tenant;
|
|
16
19
|
private tenantConfig;
|
|
17
20
|
private tenantDict;
|
|
@@ -24,6 +27,7 @@ declare class InitCls {
|
|
|
24
27
|
appLine?: string;
|
|
25
28
|
appTenant?: string;
|
|
26
29
|
appGateway?: string;
|
|
30
|
+
backupAddress?: string[];
|
|
27
31
|
}): Promise<(string | null)[]>;
|
|
28
32
|
/** 是否 App 环境 */
|
|
29
33
|
getIsApp(): boolean;
|
|
@@ -48,6 +52,8 @@ declare class InitCls {
|
|
|
48
52
|
refreshHttp(): Promise<void>;
|
|
49
53
|
/** 获取 lineDict.txt 内容 */
|
|
50
54
|
private _fetchLineDict;
|
|
55
|
+
/** 按顺序依次请求 txt 文件,成功即返回内容,全部失败返回空字符串 */
|
|
56
|
+
private fetchTxtFile;
|
|
51
57
|
/** 获取并处理 lineAddress.txt */
|
|
52
58
|
private _loadGatewayConfig;
|
|
53
59
|
}
|
package/dist/init/index.js
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
1
|
// index.ts
|
|
2
2
|
import { getResource } from "./getResource";
|
|
3
|
-
import { isDomainMatch, filterSmartLines, getOptimalDecodedString, matchBrowser, toStandardUrl,
|
|
3
|
+
import { isDomainMatch, filterSmartLines, getOptimalDecodedString, matchBrowser, toStandardUrl, } from "./utils";
|
|
4
4
|
import { AesDecrypt, AesEncrypt } from "./ende";
|
|
5
5
|
import { closeLoadingText, loadingText, rewardMsg } from "../msg";
|
|
6
6
|
import { Cache } from "../utils";
|
|
7
|
-
import {
|
|
7
|
+
import { uniq } from "lodash-es";
|
|
8
8
|
class InitCls {
|
|
9
9
|
AesDecrypt = AesDecrypt;
|
|
10
10
|
AesEncrypt = AesEncrypt;
|
|
11
11
|
appGateway = "";
|
|
12
12
|
appLine = "";
|
|
13
13
|
appTenant = "";
|
|
14
|
+
backupAddress = [];
|
|
15
|
+
backupAddressList = [];
|
|
14
16
|
defaultBaseUrl = "";
|
|
15
17
|
domainBaseUrl = "";
|
|
16
18
|
ErrorDomainUrl = Cache("ErrorDomainUrl") || [];
|
|
17
19
|
initialized = false;
|
|
18
20
|
isRefreshNow = false;
|
|
19
21
|
localPath = "";
|
|
22
|
+
OriginBaseUrl = [];
|
|
20
23
|
tenant = "";
|
|
21
24
|
tenantConfig = null;
|
|
22
25
|
tenantDict = null;
|
|
23
26
|
tenantDictList = [];
|
|
24
27
|
/** 初始化配置入口 */
|
|
25
28
|
async InitConfig(options) {
|
|
26
|
-
const { fileType, defaultBaseUrl, localPath, appLine, appTenant, appGateway = "", } = options;
|
|
29
|
+
const { fileType, defaultBaseUrl, localPath, appLine, appTenant, appGateway = "", backupAddress, } = options;
|
|
27
30
|
if (defaultBaseUrl)
|
|
28
31
|
this.defaultBaseUrl = defaultBaseUrl;
|
|
29
32
|
if (localPath)
|
|
30
33
|
this.localPath = localPath;
|
|
34
|
+
if (backupAddress)
|
|
35
|
+
this.backupAddress = backupAddress;
|
|
31
36
|
if (appLine && appTenant) {
|
|
32
37
|
this.appLine = appLine;
|
|
33
38
|
this.appTenant = appTenant;
|
|
@@ -175,7 +180,8 @@ class InitCls {
|
|
|
175
180
|
log("停止每秒日志");
|
|
176
181
|
}
|
|
177
182
|
};
|
|
178
|
-
const retrySchedule = [5, 15, 30]; // 秒(绝对时间点)
|
|
183
|
+
// const retrySchedule = [5, 15, 30]; // 秒(绝对时间点)
|
|
184
|
+
const retrySchedule = [3]; // 秒(绝对时间点)
|
|
179
185
|
const tryRequest = async (label) => {
|
|
180
186
|
log(`${label}:开始请求`);
|
|
181
187
|
try {
|
|
@@ -214,10 +220,12 @@ class InitCls {
|
|
|
214
220
|
log("30 秒后仍失败,进入兜底逻辑 ❗");
|
|
215
221
|
closeLoadingText();
|
|
216
222
|
this.isRefreshNow = false;
|
|
217
|
-
|
|
223
|
+
const nowLineGroup = this.tenantDictList.find((a) => toStandardUrl(a.line) == toStandardUrl(this.domainBaseUrl))?.lineGroup;
|
|
224
|
+
if (!!nowLineGroup)
|
|
225
|
+
Cache("ErrorDomainUrl", uniq([...this.ErrorDomainUrl, nowLineGroup]));
|
|
218
226
|
rewardMsg({
|
|
219
227
|
title: "提示",
|
|
220
|
-
text: "网络环境异常,刷新页面以重置",
|
|
228
|
+
text: "网络环境异常,刷新页面以重置" + (nowLineGroup ? "" : "..."),
|
|
221
229
|
onSubmit() {
|
|
222
230
|
location.reload();
|
|
223
231
|
},
|
|
@@ -242,6 +250,27 @@ class InitCls {
|
|
|
242
250
|
throw new Error(`HTTP 错误: ${response.status}`);
|
|
243
251
|
return response.text();
|
|
244
252
|
}
|
|
253
|
+
/** 按顺序依次请求 txt 文件,成功即返回内容,全部失败返回空字符串 */
|
|
254
|
+
async fetchTxtFile(urls) {
|
|
255
|
+
for (const url of urls) {
|
|
256
|
+
try {
|
|
257
|
+
const response = await fetch(`${url}?t=${Date.now()}`, {
|
|
258
|
+
method: "GET",
|
|
259
|
+
cache: "no-store",
|
|
260
|
+
});
|
|
261
|
+
if (!response.ok) {
|
|
262
|
+
throw new Error(`HTTP 错误: ${response.status}`);
|
|
263
|
+
}
|
|
264
|
+
return await response.text();
|
|
265
|
+
}
|
|
266
|
+
catch (err) {
|
|
267
|
+
// 当前 url 失败,继续请求下一个
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
// 所有 url 都失败
|
|
272
|
+
return "";
|
|
273
|
+
}
|
|
245
274
|
/** 获取并处理 lineAddress.txt */
|
|
246
275
|
async _loadGatewayConfig() {
|
|
247
276
|
if (this.domainBaseUrl)
|
|
@@ -250,32 +279,26 @@ class InitCls {
|
|
|
250
279
|
const response = await fetch(`/lineAddress.txt?t=${Date.now()}`);
|
|
251
280
|
const configText = await response.text();
|
|
252
281
|
const resArray = JSON.parse(AesDecrypt(configText));
|
|
253
|
-
let OriginBaseUrl =
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
OriginBaseUrl = resArray;
|
|
259
|
-
}
|
|
260
|
-
const dictList = this.getTenantDictList();
|
|
282
|
+
let OriginBaseUrl = resArray;
|
|
283
|
+
this.OriginBaseUrl = OriginBaseUrl;
|
|
284
|
+
const dictList = this.getTenantDictList().filter((a) => !this.ErrorDomainUrl.includes(a.lineGroup));
|
|
261
285
|
const lineGroup = this.getTenantDict()?.lineGroup;
|
|
262
|
-
let baseUrl = filterSmartLines(dictList, OriginBaseUrl, lineGroup);
|
|
286
|
+
let baseUrl = filterSmartLines(dictList, OriginBaseUrl, this.ErrorDomainUrl?.length == 0 ? lineGroup : "");
|
|
263
287
|
try {
|
|
264
288
|
this.domainBaseUrl = toStandardUrl(await getOptimalDecodedString(baseUrl));
|
|
265
289
|
console.info("✅ 成功加载生产环境配置:", this.domainBaseUrl);
|
|
266
290
|
}
|
|
267
|
-
catch {
|
|
291
|
+
catch (error) {
|
|
292
|
+
const backUrl = JSON.parse(AesDecrypt(await this.fetchTxtFile(this.backupAddress)));
|
|
293
|
+
this.backupAddressList = backUrl || [];
|
|
268
294
|
// 备用策略
|
|
269
|
-
let allBaseUrl = filterSmartLines(dictList, OriginBaseUrl);
|
|
270
295
|
try {
|
|
271
|
-
this.domainBaseUrl = toStandardUrl(await getOptimalDecodedString(
|
|
272
|
-
filterIp: false,
|
|
273
|
-
}));
|
|
296
|
+
this.domainBaseUrl = toStandardUrl(await getOptimalDecodedString(backUrl));
|
|
274
297
|
console.info("✅ 备用配置成功:", this.domainBaseUrl);
|
|
275
298
|
}
|
|
276
299
|
catch (err) {
|
|
277
|
-
this.domainBaseUrl = toStandardUrl(
|
|
278
|
-
console.warn("⚠️ 备选测速失败,使用备用配置:",
|
|
300
|
+
this.domainBaseUrl = toStandardUrl(backUrl?.length > 0 ? backUrl[0] : OriginBaseUrl[0]);
|
|
301
|
+
console.warn("⚠️ 备选测速失败,使用备用配置:", this.domainBaseUrl);
|
|
279
302
|
}
|
|
280
303
|
}
|
|
281
304
|
return this.domainBaseUrl;
|
|
@@ -288,13 +311,13 @@ class InitCls {
|
|
|
288
311
|
return this.domainBaseUrl;
|
|
289
312
|
}
|
|
290
313
|
}
|
|
291
|
-
else
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
console.info("🏠 使用默认
|
|
314
|
+
else {
|
|
315
|
+
this.domainBaseUrl =
|
|
316
|
+
this.defaultBaseUrl ||
|
|
317
|
+
toStandardUrl(this.backupAddressList?.length > 0
|
|
318
|
+
? this.backupAddressList[0]
|
|
319
|
+
: this.OriginBaseUrl[0]);
|
|
320
|
+
console.info("🏠 使用默认 BaseUrl1:", this.domainBaseUrl);
|
|
298
321
|
return this.domainBaseUrl;
|
|
299
322
|
}
|
|
300
323
|
console.error("⚠️ 加载 lineAddress.txt 失败:", err);
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "1.4.
|
|
1
|
+
export declare const VERSION = "1.4.17";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "1.4.
|
|
1
|
+
export const VERSION = "1.4.17";
|