hifun-tools 1.3.32 → 1.4.2

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,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;
@@ -41,7 +43,7 @@ declare class InitCls {
41
43
  private _getTenantInfoStrictSync;
42
44
  /** 匹配默认租户 */
43
45
  private _matchDefaultTenant;
44
- refreshHttp(): void;
46
+ refreshHttp(): Promise<void>;
45
47
  /** 获取 lineDict.txt 内容 */
46
48
  private _fetchLineDict;
47
49
  /** 获取并处理 lineAddress.txt */
@@ -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 (host.includes("iggame") ||
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(/\/+$/, "")))) {
@@ -143,9 +149,9 @@ class InitCls {
143
149
  }
144
150
  throw new Error("无法获取有效的租户信息");
145
151
  }
146
- refreshHttp() {
152
+ async refreshHttp() {
147
153
  try {
148
- getOptimalDecodedString([this.getBaseUrl()]);
154
+ await getOptimalDecodedString([this.getBaseUrl()]);
149
155
  }
150
156
  catch (error) {
151
157
  rewardMsg({
@@ -199,8 +205,14 @@ class InitCls {
199
205
  return this.domainBaseUrl;
200
206
  }
201
207
  catch (err) {
202
- console.error("⚠️ 加载 lineAddress.txt 失败:", err);
203
- if ((this.defaultBaseUrl &&
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,6 +1,6 @@
1
1
  {
2
2
  "name": "hifun-tools",
3
- "version": "1.3.32",
3
+ "version": "1.4.2",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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
- }
@@ -1,3 +0,0 @@
1
- export * from "./tenant";
2
- export * from "./request";
3
- export * from "./init";
package/dist/src/index.js DELETED
@@ -1,3 +0,0 @@
1
- export * from "./tenant";
2
- export * from "./request";
3
- export * from "./init";
@@ -1,6 +0,0 @@
1
- import { InitConfig } from "../../types";
2
- declare class InitCls {
3
- config(opt: InitConfig): void;
4
- }
5
- declare const Init: InitCls;
6
- export { Init };
@@ -1,7 +0,0 @@
1
- class InitCls {
2
- config(opt) {
3
- console.log(opt);
4
- }
5
- }
6
- const Init = new InitCls();
7
- export { Init };
@@ -1 +0,0 @@
1
- export declare function request(url: string, options?: RequestInit): Promise<any>;
@@ -1,6 +0,0 @@
1
- export async function request(url, options = {}) {
2
- const res = await fetch(url, options);
3
- if (!res.ok)
4
- throw new Error(`HTTP ${res.status}`);
5
- return res.json();
6
- }
@@ -1,5 +0,0 @@
1
- declare class useTenant {
2
- id: number;
3
- }
4
- declare const Tenant: useTenant;
5
- export { Tenant };
@@ -1,7 +0,0 @@
1
- class useTenant {
2
- constructor() {
3
- this.id = 123;
4
- }
5
- }
6
- const Tenant = new useTenant();
7
- export { Tenant };
@@ -1,5 +0,0 @@
1
- declare class useTenant {
2
- id: number;
3
- }
4
- declare const Tenant: useTenant;
5
- export { Tenant };
@@ -1,5 +0,0 @@
1
- class useTenant {
2
- id = 123;
3
- }
4
- const Tenant = new useTenant();
5
- export { Tenant };
@@ -1,3 +0,0 @@
1
- export interface InitConfig {
2
- fileType: ("lineAddress" | "lineTenants")[];
3
- }
@@ -1 +0,0 @@
1
- export {};