hifun-tools 1.4.1 → 1.4.3
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 +3 -0
- package/dist/init/index.js +17 -4
- package/package.json +1 -1
- package/dist/init/TenantManager.d.ts +0 -23
- package/dist/init/TenantManager.js +0 -94
- package/dist/init/viteResource.d.ts +0 -1
- package/dist/init/viteResource.js +0 -13
- package/dist/src/index.d.ts +0 -3
- package/dist/src/index.js +0 -3
- package/dist/src/init/index.d.ts +0 -6
- package/dist/src/init/index.js +0 -7
- package/dist/src/request/index.d.ts +0 -1
- package/dist/src/request/index.js +0 -6
- package/dist/src/tenant/index.d.ts +0 -5
- package/dist/src/tenant/index.js +0 -7
- package/dist/tenant/index.d.ts +0 -5
- package/dist/tenant/index.js +0 -5
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.js +0 -1
package/dist/init/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { AesDecrypt, AesEncrypt } from "./ende";
|
|
|
3
3
|
declare class InitCls {
|
|
4
4
|
AesDecrypt: typeof AesDecrypt;
|
|
5
5
|
AesEncrypt: typeof AesEncrypt;
|
|
6
|
+
private appGateway;
|
|
6
7
|
private appLine;
|
|
7
8
|
private appTenant;
|
|
8
9
|
private defaultBaseUrl;
|
|
@@ -20,6 +21,7 @@ declare class InitCls {
|
|
|
20
21
|
localPath?: string;
|
|
21
22
|
appLine?: string;
|
|
22
23
|
appTenant?: string;
|
|
24
|
+
appGateway?: string;
|
|
23
25
|
}): Promise<(string | null)[]>;
|
|
24
26
|
/** 是否 App 环境 */
|
|
25
27
|
getIsApp(): boolean;
|
|
@@ -53,5 +55,6 @@ export type TenantConfig = {
|
|
|
53
55
|
SITE_TITLE: string;
|
|
54
56
|
SITE_URL: string;
|
|
55
57
|
USER_TENANT: string;
|
|
58
|
+
DB_TITLE: string;
|
|
56
59
|
};
|
|
57
60
|
export { HF, isDomainMatch, toStandardUrl, AesEncrypt, AesDecrypt, filterSmartLines, matchBrowser, getOptimalDecodedString, };
|
package/dist/init/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { rewardMsg } from "../msg";
|
|
|
6
6
|
class InitCls {
|
|
7
7
|
AesDecrypt = AesDecrypt;
|
|
8
8
|
AesEncrypt = AesEncrypt;
|
|
9
|
+
appGateway = "";
|
|
9
10
|
appLine = "";
|
|
10
11
|
appTenant = "";
|
|
11
12
|
defaultBaseUrl = "";
|
|
@@ -18,7 +19,7 @@ class InitCls {
|
|
|
18
19
|
tenantDictList = [];
|
|
19
20
|
/** 初始化配置入口 */
|
|
20
21
|
async InitConfig(options) {
|
|
21
|
-
const { fileType, defaultBaseUrl, localPath, appLine, appTenant } = options;
|
|
22
|
+
const { fileType, defaultBaseUrl, localPath, appLine, appTenant, appGateway = "", } = options;
|
|
22
23
|
if (defaultBaseUrl)
|
|
23
24
|
this.defaultBaseUrl = defaultBaseUrl;
|
|
24
25
|
if (localPath)
|
|
@@ -26,6 +27,7 @@ class InitCls {
|
|
|
26
27
|
if (appLine && appTenant) {
|
|
27
28
|
this.appLine = appLine;
|
|
28
29
|
this.appTenant = appTenant;
|
|
30
|
+
this.appGateway = appGateway;
|
|
29
31
|
console.info("📱 appLine:", appLine, "appTenant:", appTenant);
|
|
30
32
|
}
|
|
31
33
|
console.info("📝 加载类型:", fileType);
|
|
@@ -134,7 +136,11 @@ class InitCls {
|
|
|
134
136
|
/** 匹配默认租户 */
|
|
135
137
|
_matchDefaultTenant() {
|
|
136
138
|
const host = location.host;
|
|
137
|
-
if (
|
|
139
|
+
if (this.getIsApp()) {
|
|
140
|
+
console.info("🏠 匹配到app传入租户");
|
|
141
|
+
return { tenant: this.appTenant };
|
|
142
|
+
}
|
|
143
|
+
else if (host.includes("iggame") ||
|
|
138
144
|
host.includes("localhost") ||
|
|
139
145
|
(!!this.localPath &&
|
|
140
146
|
location.origin.includes(this.localPath.replace(/\/+$/, "")))) {
|
|
@@ -199,8 +205,14 @@ class InitCls {
|
|
|
199
205
|
return this.domainBaseUrl;
|
|
200
206
|
}
|
|
201
207
|
catch (err) {
|
|
202
|
-
|
|
203
|
-
|
|
208
|
+
if (this.getIsApp()) {
|
|
209
|
+
if (this.appGateway) {
|
|
210
|
+
this.domainBaseUrl = toStandardUrl(this.appGateway);
|
|
211
|
+
console.info("🏠 使用app传入网关:", this.domainBaseUrl);
|
|
212
|
+
return this.domainBaseUrl;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else if ((this.defaultBaseUrl &&
|
|
204
216
|
(location.host.includes("iggame") ||
|
|
205
217
|
location.host.includes("localhost"))) ||
|
|
206
218
|
(!!this.localPath &&
|
|
@@ -209,6 +221,7 @@ class InitCls {
|
|
|
209
221
|
console.info("🏠 使用默认 BaseUrl:", this.domainBaseUrl);
|
|
210
222
|
return this.domainBaseUrl;
|
|
211
223
|
}
|
|
224
|
+
console.error("⚠️ 加载 lineAddress.txt 失败:", err);
|
|
212
225
|
return null;
|
|
213
226
|
}
|
|
214
227
|
}
|
package/package.json
CHANGED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
type TenantConfig = {
|
|
2
|
-
PUBLIC_TITLE: string;
|
|
3
|
-
SITE_TITLE: string;
|
|
4
|
-
SITE_URL: string;
|
|
5
|
-
USER_TENANT: string;
|
|
6
|
-
};
|
|
7
|
-
export declare class TenantManagerClass {
|
|
8
|
-
private tenantConfig;
|
|
9
|
-
private initialized;
|
|
10
|
-
private static instance;
|
|
11
|
-
tenant: string | null;
|
|
12
|
-
constructor();
|
|
13
|
-
/** 获取配置 */
|
|
14
|
-
getConfig(): TenantConfig | null;
|
|
15
|
-
/** 获取租户名 */
|
|
16
|
-
getTenant(): string;
|
|
17
|
-
getImgPath(imgName: string): string;
|
|
18
|
-
/** 严格同步获取租户信息 */
|
|
19
|
-
private getTenantInfoStrictSync;
|
|
20
|
-
/** 严格初始化(必须在应用启动时调用) */
|
|
21
|
-
initialize(): void;
|
|
22
|
-
}
|
|
23
|
-
export {};
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { getResource } from "./getResource";
|
|
2
|
-
export class TenantManagerClass {
|
|
3
|
-
tenantConfig = null;
|
|
4
|
-
initialized = false;
|
|
5
|
-
static instance;
|
|
6
|
-
tenant = null;
|
|
7
|
-
constructor() {
|
|
8
|
-
if (TenantManagerClass.instance) {
|
|
9
|
-
return TenantManagerClass.instance;
|
|
10
|
-
}
|
|
11
|
-
TenantManagerClass.instance = this;
|
|
12
|
-
}
|
|
13
|
-
/** 获取配置 */
|
|
14
|
-
getConfig() {
|
|
15
|
-
return this.tenantConfig;
|
|
16
|
-
}
|
|
17
|
-
/** 获取租户名 */
|
|
18
|
-
getTenant() {
|
|
19
|
-
if (!this.initialized || !this.tenant) {
|
|
20
|
-
throw new Error("租户尚未初始化或初始化失败");
|
|
21
|
-
}
|
|
22
|
-
return this.tenant;
|
|
23
|
-
}
|
|
24
|
-
getImgPath(imgName) {
|
|
25
|
-
if (!this.initialized || !this.tenant) {
|
|
26
|
-
throw new Error("租户尚未初始化或初始化失败");
|
|
27
|
-
}
|
|
28
|
-
return getResource(`${this.tenant}/image/${imgName}`);
|
|
29
|
-
}
|
|
30
|
-
/** 严格同步获取租户信息 */
|
|
31
|
-
getTenantInfoStrictSync() {
|
|
32
|
-
const xhr = new XMLHttpRequest();
|
|
33
|
-
xhr.open("GET", "/lineTenants.txt?t=" + Date.now(), false);
|
|
34
|
-
xhr.send(null);
|
|
35
|
-
if (xhr.status === 200) {
|
|
36
|
-
try {
|
|
37
|
-
const rawData = atob(xhr.responseText);
|
|
38
|
-
const data = JSON.parse(rawData);
|
|
39
|
-
const host = location.host;
|
|
40
|
-
const matchedEntry = Object.entries(data).find(([key]) => {
|
|
41
|
-
// key 是明文主机地址,直接比较即可
|
|
42
|
-
// 兼容 www 前缀的情况
|
|
43
|
-
// 如果当前 host 有 www 前缀,则也匹配无 www 前缀的配置
|
|
44
|
-
// 如果当前 host 无 www 前缀,则也匹配有 www 前缀的配置
|
|
45
|
-
return (key === host ||
|
|
46
|
-
(host.startsWith("www.") && key === host.substring(4)) ||
|
|
47
|
-
(!host.startsWith("www.") && key === "www." + host));
|
|
48
|
-
});
|
|
49
|
-
if (matchedEntry) {
|
|
50
|
-
const matched = matchedEntry[1];
|
|
51
|
-
if (data && matched) {
|
|
52
|
-
console.info(`🏠 匹配租户: ${matched}`);
|
|
53
|
-
return { tenant: matched };
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
console.error("解析 lineTenants.txt 失败:", error);
|
|
59
|
-
if (location.host.includes("iggame") ||
|
|
60
|
-
location.host.includes("localhost")) {
|
|
61
|
-
console.info(`🏠 iggame匹配到默认租户`);
|
|
62
|
-
return {
|
|
63
|
-
tenant: "iggame",
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
throw new Error("lineTenants.txt 格式错误");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (location.host.includes("iggame") ||
|
|
70
|
-
location.host.includes("localhost")) {
|
|
71
|
-
console.info(`🏠 iggame匹配到默认租户`);
|
|
72
|
-
return {
|
|
73
|
-
tenant: "iggame",
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
throw new Error("无法获取有效的租户信息");
|
|
77
|
-
}
|
|
78
|
-
/** 严格初始化(必须在应用启动时调用) */
|
|
79
|
-
initialize() {
|
|
80
|
-
if (this.initialized)
|
|
81
|
-
return;
|
|
82
|
-
try {
|
|
83
|
-
const tenantInfo = this.getTenantInfoStrictSync();
|
|
84
|
-
this.tenant = tenantInfo.tenant;
|
|
85
|
-
this.tenantConfig = getResource(`${tenantInfo.tenant}/config.json`);
|
|
86
|
-
this.initialized = true;
|
|
87
|
-
console.info(`🏢 严格加载租户成功: ${this.tenant}`, this.getImgPath("logo-default.png"));
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
console.error("严格租户加载失败:", error);
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function viteLoadSync(path: string): any;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// viteResource.ts
|
|
2
|
-
export function viteLoadSync(path) {
|
|
3
|
-
const modules = import.meta.glob([
|
|
4
|
-
"/config/**/*.json",
|
|
5
|
-
"/config/**/*.png",
|
|
6
|
-
"/config/**/*.jpg",
|
|
7
|
-
"/config/**/*.jpeg",
|
|
8
|
-
"/config/**/*.svg",
|
|
9
|
-
"/config/**/*.webp",
|
|
10
|
-
], { eager: true, import: "default" });
|
|
11
|
-
const match = Object.entries(modules).find(([key]) => key.endsWith(path));
|
|
12
|
-
return match ? match[1] : null;
|
|
13
|
-
}
|
package/dist/src/index.d.ts
DELETED
package/dist/src/index.js
DELETED
package/dist/src/init/index.d.ts
DELETED
package/dist/src/init/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function request(url: string, options?: RequestInit): Promise<any>;
|
package/dist/src/tenant/index.js
DELETED
package/dist/tenant/index.d.ts
DELETED
package/dist/tenant/index.js
DELETED
package/dist/types/index.d.ts
DELETED
package/dist/types/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|