karin-plugin-mys-core 1.0.0 → 1.0.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.
Files changed (168) hide show
  1. package/LICENSE +674 -0
  2. package/lib/apps/MiHoYoLogin.d.ts +3 -1
  3. package/lib/apps/MiHoYoLogin.js +181 -125
  4. package/lib/apps/MysDevice.d.ts +5 -0
  5. package/lib/apps/MysDevice.js +101 -0
  6. package/lib/apps/UIDManage.d.ts +10 -0
  7. package/lib/apps/UIDManage.js +52 -0
  8. package/lib/array-CZDr9qst.d.ts +62 -0
  9. package/lib/chunk-2DHTKQ34.js +0 -0
  10. package/lib/chunk-3BIQN6QA.js +27 -0
  11. package/lib/chunk-3CNBOOKY.js +31 -0
  12. package/lib/chunk-5NA7ZPDS.js +54 -0
  13. package/lib/chunk-6PIXUPZ6.js +82 -0
  14. package/lib/chunk-7KEG6SDX.js +0 -0
  15. package/lib/chunk-7SZX3RBZ.js +0 -0
  16. package/lib/chunk-7VAWV6ZE.js +0 -0
  17. package/lib/chunk-7WESXE4X.js +29 -0
  18. package/lib/chunk-7YZHHLS5.js +130 -0
  19. package/lib/chunk-ARLTXJFJ.js +0 -0
  20. package/lib/chunk-CFS2WFOO.js +0 -0
  21. package/lib/chunk-EMAUATE3.js +217 -0
  22. package/lib/chunk-FBWSEBAW.js +0 -0
  23. package/lib/chunk-FOAQZIZ2.js +0 -0
  24. package/lib/chunk-G547WVGV.js +73 -0
  25. package/lib/chunk-G5W5WAY5.js +64 -0
  26. package/lib/chunk-HVYNK5BN.js +45 -0
  27. package/lib/chunk-I7XZONDN.js +13 -0
  28. package/lib/chunk-IVZICDGW.js +19 -0
  29. package/lib/chunk-JBGXPVO2.js +179 -0
  30. package/lib/chunk-JRH4JC43.js +0 -0
  31. package/lib/chunk-JVJQKRJ4.js +89 -0
  32. package/lib/chunk-K5U2O3HH.js +0 -0
  33. package/lib/chunk-KN5SHBVI.js +30 -0
  34. package/lib/chunk-LG34FPBI.js +50 -0
  35. package/lib/chunk-LJSDSOY6.js +0 -0
  36. package/lib/chunk-LYTNREAI.js +0 -0
  37. package/lib/chunk-MWYDWDR4.js +0 -0
  38. package/lib/chunk-QMSYS77M.js +38 -0
  39. package/lib/chunk-SEWEEPJN.js +0 -0
  40. package/lib/{chunk-JML6VYXN.js → chunk-SHLPPEAY.js} +13 -17
  41. package/lib/chunk-SHW6FHIB.js +10 -0
  42. package/lib/chunk-W4DBT7AD.js +0 -0
  43. package/lib/chunk-X75DW4KI.js +510 -0
  44. package/lib/chunk-XQWTJIT4.js +0 -0
  45. package/lib/chunk-Y3J3J5B2.js +124 -0
  46. package/lib/chunk-Z5I6A73Y.js +0 -0
  47. package/lib/common-Dw5l6Uud.d.ts +33 -0
  48. package/lib/define-BWuQ7acM.d.ts +131 -0
  49. package/lib/dir.d.ts +11 -13
  50. package/lib/dir.js +1 -1
  51. package/lib/exports/config/array.d.ts +1 -0
  52. package/lib/exports/config/array.js +7 -0
  53. package/lib/exports/config/config.d.ts +1 -0
  54. package/lib/exports/config/config.js +8 -0
  55. package/lib/exports/config/index.d.ts +2 -0
  56. package/lib/exports/config/index.js +14 -0
  57. package/lib/exports/config/types/config.d.ts +12 -0
  58. package/lib/exports/config/types/config.js +1 -0
  59. package/lib/exports/config/types/index.d.ts +1 -0
  60. package/lib/exports/config/types/index.js +2 -0
  61. package/lib/exports/database/database.d.ts +30 -0
  62. package/lib/exports/database/database.js +18 -0
  63. package/lib/exports/database/dbs/base.d.ts +23 -0
  64. package/lib/exports/database/dbs/base.js +15 -0
  65. package/lib/exports/database/dbs/index.d.ts +4 -0
  66. package/lib/exports/database/dbs/index.js +23 -0
  67. package/lib/exports/database/dbs/sqlite3.d.ts +23 -0
  68. package/lib/exports/database/dbs/sqlite3.js +19 -0
  69. package/lib/exports/database/dbs/table.d.ts +13 -0
  70. package/lib/exports/database/dbs/table.js +19 -0
  71. package/lib/exports/database/index.d.ts +12 -0
  72. package/lib/exports/database/index.js +62 -0
  73. package/lib/exports/database/tables/index.d.ts +9 -0
  74. package/lib/exports/database/tables/index.js +39 -0
  75. package/lib/exports/database/tables/mysAccountInfo.d.ts +9 -0
  76. package/lib/exports/database/tables/mysAccountInfo.js +23 -0
  77. package/lib/exports/database/tables/mysDeviceInfo.d.ts +9 -0
  78. package/lib/exports/database/tables/mysDeviceInfo.js +26 -0
  79. package/lib/exports/database/tables/mysUserInfo.d.ts +9 -0
  80. package/lib/exports/database/tables/mysUserInfo.js +23 -0
  81. package/lib/exports/database/types/database.d.ts +6 -0
  82. package/lib/exports/database/types/database.js +1 -0
  83. package/lib/exports/database/types/dbs/base.d.ts +114 -0
  84. package/lib/exports/database/types/dbs/base.js +11 -0
  85. package/lib/exports/database/types/dbs/index.d.ts +2 -0
  86. package/lib/exports/database/types/dbs/index.js +12 -0
  87. package/lib/exports/database/types/index.d.ts +6 -0
  88. package/lib/exports/database/types/index.js +24 -0
  89. package/lib/exports/database/types/tables/index.d.ts +5 -0
  90. package/lib/exports/database/types/tables/index.js +13 -0
  91. package/lib/exports/database/types/tables/mysAccountInfo.d.ts +14 -0
  92. package/lib/exports/database/types/tables/mysAccountInfo.js +7 -0
  93. package/lib/exports/database/types/tables/mysDeviceInfo.d.ts +19 -0
  94. package/lib/exports/database/types/tables/mysDeviceInfo.js +1 -0
  95. package/lib/exports/database/types/tables/mysUserInfo.d.ts +31 -0
  96. package/lib/exports/database/types/tables/mysUserInfo.js +7 -0
  97. package/lib/exports/mys/api/apis.d.ts +82 -0
  98. package/lib/exports/mys/api/apis.js +57 -0
  99. package/lib/exports/mys/api/app.d.ts +60 -0
  100. package/lib/exports/mys/api/app.js +31 -0
  101. package/lib/exports/mys/api/define.d.ts +6 -0
  102. package/lib/exports/mys/api/define.js +43 -0
  103. package/lib/exports/mys/api/index.d.ts +11 -0
  104. package/lib/exports/mys/api/index.js +64 -0
  105. package/lib/exports/mys/index.d.ts +13 -0
  106. package/lib/exports/mys/index.js +77 -0
  107. package/lib/exports/mys/types/api/define.d.ts +6 -0
  108. package/lib/exports/mys/types/api/define.js +1 -0
  109. package/lib/exports/mys/types/api/index.d.ts +6 -0
  110. package/lib/exports/mys/types/api/index.js +2 -0
  111. package/lib/exports/mys/types/index.d.ts +10 -0
  112. package/lib/exports/mys/types/index.js +12 -0
  113. package/lib/exports/mys/types/user/game.d.ts +10 -0
  114. package/lib/exports/mys/types/user/game.js +1 -0
  115. package/lib/exports/mys/types/user/index.d.ts +10 -0
  116. package/lib/exports/mys/types/user/index.js +9 -0
  117. package/lib/exports/mys/types/user/userInfo.d.ts +10 -0
  118. package/lib/exports/mys/types/user/userInfo.js +7 -0
  119. package/lib/exports/mys/user/deviceInfo.d.ts +11 -0
  120. package/lib/exports/mys/user/deviceInfo.js +29 -0
  121. package/lib/exports/mys/user/game.d.ts +20 -0
  122. package/lib/exports/mys/user/game.js +7 -0
  123. package/lib/exports/mys/user/index.d.ts +12 -0
  124. package/lib/exports/mys/user/index.js +51 -0
  125. package/lib/exports/mys/user/userInfo.d.ts +10 -0
  126. package/lib/exports/mys/user/userInfo.js +45 -0
  127. package/lib/exports/utils/common.d.ts +1 -0
  128. package/lib/exports/utils/common.js +13 -0
  129. package/lib/exports/utils/index.d.ts +2 -0
  130. package/lib/exports/utils/index.js +12 -0
  131. package/lib/exports/utils/render.d.ts +21 -0
  132. package/lib/exports/utils/render.js +7 -0
  133. package/lib/index-DEEWbZ0V.d.ts +102 -0
  134. package/lib/index.js +1 -1
  135. package/package.json +29 -16
  136. package/resources/fonts/HYWenHei-55W.ttf +0 -0
  137. package/resources/image/launcher-icon//345/216/237/347/245/236.png +0 -0
  138. package/resources/image/launcher-icon//345/264/251/345/235/2173.png +0 -0
  139. package/resources/image/launcher-icon//345/264/251/345/235/217/345/255/246/345/233/2552.png +0 -0
  140. package/resources/image/launcher-icon//345/264/251/345/235/217/357/274/232/345/233/240/347/274/230/347/262/276/347/201/265.png +0 -0
  141. package/resources/image/launcher-icon//345/264/251/345/235/217/357/274/232/346/230/237/347/251/271/351/223/201/351/201/223.png +0 -0
  142. package/resources/image/launcher-icon//346/230/237/345/270/203/350/260/267/345/234/260.png +0 -0
  143. package/resources/image/launcher-icon//346/234/252/345/256/232/344/272/213/344/273/266/347/260/277.png +0 -0
  144. package/resources/image/launcher-icon//347/273/235/345/214/272/351/233/266.png +0 -0
  145. package/resources/image/mys-logo.png +0 -0
  146. package/resources/template/ShowBindAccount/index.css +1 -0
  147. package/resources/template/ShowBindAccount/index.html +65 -0
  148. package/resources/template/ShowBindDevice/index.html +20 -0
  149. package/resources/template/ShowBindDevice/inex.css +1 -0
  150. package/resources/template/layout/default.css +1 -0
  151. package/resources/template/layout/default.html +27 -0
  152. package/config/config.json +0 -3
  153. package/lib/app.d.ts +0 -2
  154. package/lib/base-B1BvQ4ol.d.ts +0 -99
  155. package/lib/chunk-4JTLXC2G.js +0 -519
  156. package/lib/chunk-7QISGXVH.js +0 -347
  157. package/lib/chunk-JIO4GOQA.js +0 -31
  158. package/lib/database-BDHrI6Vm.d.ts +0 -5
  159. package/lib/define-CrfHwHnK.d.ts +0 -163
  160. package/lib/exports/core.d.ts +0 -228
  161. package/lib/exports/core.js +0 -39
  162. package/lib/exports/database.d.ts +0 -47
  163. package/lib/exports/database.js +0 -17
  164. package/lib/exports/types.d.ts +0 -10
  165. package/lib/exports/types.js +0 -11
  166. package/lib/index.d.ts +0 -2
  167. package/lib/web.config.d.ts +0 -5
  168. package/lib/web.config.js +0 -30
@@ -0,0 +1,510 @@
1
+ import {
2
+ DeviceInfo
3
+ } from "./chunk-3CNBOOKY.js";
4
+ import {
5
+ MysGame
6
+ } from "./chunk-3BIQN6QA.js";
7
+ import {
8
+ MysApp,
9
+ MysHosts
10
+ } from "./chunk-G5W5WAY5.js";
11
+ import {
12
+ MysUserInfoDB
13
+ } from "./chunk-7WESXE4X.js";
14
+ import {
15
+ MysAccountInfoDB
16
+ } from "./chunk-KN5SHBVI.js";
17
+ import {
18
+ MysDeviceInfoDB
19
+ } from "./chunk-QMSYS77M.js";
20
+ import {
21
+ common_exports
22
+ } from "./chunk-LG34FPBI.js";
23
+ import {
24
+ RenderTemplate
25
+ } from "./chunk-HVYNK5BN.js";
26
+ import {
27
+ dir
28
+ } from "./chunk-SHLPPEAY.js";
29
+ import {
30
+ Config
31
+ } from "./chunk-7YZHHLS5.js";
32
+
33
+ // src/core/config/device.ts
34
+ import path from "path";
35
+ var ConfigPath = path.join(dir.ConfigDir, "device.json");
36
+ var DefaultDevice = {
37
+ version: 12,
38
+ name: "aurora",
39
+ board: "24031PN0DC",
40
+ model: "24031PN0DC",
41
+ product: "aurora",
42
+ fingerprint: "Xiaomi/aurora/aurora:12/V417IR/813:user/release-keys"
43
+ };
44
+ var DeviceCfg = new Config(`${dir.name}:device`, ConfigPath, DefaultDevice, {}).watch();
45
+
46
+ // src/core/render.ts
47
+ var Render = new RenderTemplate(dir);
48
+
49
+ // src/exports/mys/api/define.ts
50
+ import md5 from "md5";
51
+ import { logger, redis } from "node-karin";
52
+ import axios, { AxiosHeaders } from "node-karin/axios";
53
+
54
+ // src/exports/mys/user/userInfo.ts
55
+ var BaseUserInfo = class {
56
+ userId;
57
+ #ltuidMap = /* @__PURE__ */ new Map();
58
+ constructor(userId) {
59
+ this.userId = userId;
60
+ }
61
+ get ltuids() {
62
+ return this.UserInfo.ltuids;
63
+ }
64
+ get stuids() {
65
+ return this.UserInfo.stuids;
66
+ }
67
+ get deviceList() {
68
+ return this.UserInfo.deviceList;
69
+ }
70
+ get LtuidInfoList() {
71
+ return Array.from(this.#ltuidMap.values()).map((info) => Object.freeze(info)).sort((a, b) => +a.ltuid - +b.ltuid);
72
+ }
73
+ async initMysAccountInfo(UserInfo2, initAll) {
74
+ this.UserInfo = UserInfo2;
75
+ this.#ltuidMap.clear();
76
+ const idList = Array.from(/* @__PURE__ */ new Set([...UserInfo2.ltuids, ...UserInfo2.stuids]));
77
+ if (initAll) {
78
+ const MysAccountInfoList = await (await MysAccountInfoDB()).findAllByPks(idList);
79
+ MysAccountInfoList.forEach((MysAccountInfo) => {
80
+ this.#ltuidMap.set(MysAccountInfo.ltuid, MysAccountInfo);
81
+ });
82
+ } else {
83
+ const self = this;
84
+ const mainLtuid = self.bind_uids?.[self.main_uid]?.ltuid;
85
+ if (mainLtuid) {
86
+ const MysAccountInfo = await (await MysAccountInfoDB()).findByPk(mainLtuid);
87
+ MysAccountInfo && this.#ltuidMap.set(MysAccountInfo.ltuid, MysAccountInfo);
88
+ }
89
+ }
90
+ }
91
+ getLtuidInfo(ltuid) {
92
+ return Object.freeze(this.#ltuidMap.get(ltuid));
93
+ }
94
+ async getDeviceInfoList() {
95
+ return await (await MysDeviceInfoDB()).findAllByPks(this.deviceList);
96
+ }
97
+ async saveUserInfo(data) {
98
+ await this.UserInfo.save(data);
99
+ }
100
+ async saveMysAccountInfo(ltuid, data) {
101
+ let MysAccountInfo = this.#ltuidMap.get(ltuid);
102
+ if (!MysAccountInfo) {
103
+ MysAccountInfo = await (await MysAccountInfoDB()).findByPk(ltuid, true);
104
+ }
105
+ await MysAccountInfo.save(data);
106
+ this.#ltuidMap.set(ltuid, { ...MysAccountInfo, ...data });
107
+ }
108
+ };
109
+ var UserInfo = class _UserInfo extends BaseUserInfo {
110
+ static async create(userId, initAll = false) {
111
+ const userInfo = new BaseUserInfo(userId);
112
+ userInfo.refresh = async () => {
113
+ const UserInfoData = await (await MysUserInfoDB()).findByPk(userId, true);
114
+ await userInfo.initMysAccountInfo(UserInfoData, initAll);
115
+ return userInfo;
116
+ };
117
+ return await userInfo.refresh();
118
+ }
119
+ static async refreshUid(options, perm) {
120
+ let message = "";
121
+ const uids = [];
122
+ if (MysGame.num > 0) {
123
+ const res = (await getUserGameRolesByCookie.init(options).request(null)).data;
124
+ if (res?.retcode === 0) {
125
+ await MysGame.forEachGame(async (Game) => {
126
+ const uidList = Game.refresh(res.data.list);
127
+ const userInfo = await Game.UserInfo.create(options.userId);
128
+ const bindUids = userInfo.bind_uids;
129
+ uidList.forEach((uid) => {
130
+ if (!(uid in bindUids) || bindUids[uid].perm < perm) {
131
+ bindUids[uid] = {
132
+ perm,
133
+ ltuid: options.ltuid
134
+ };
135
+ }
136
+ });
137
+ uids.push({
138
+ name: Game.name,
139
+ columnKey: Game.columnKey,
140
+ data: bindUids
141
+ });
142
+ });
143
+ } else if (res?.retcode === -100) {
144
+ message = "Cookie\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0#\u626B\u7801\u767B\u5F55\u6216#\u5237\u65B0Cookie\uFF01";
145
+ } else {
146
+ message = res?.message || "\u5237\u65B0UID\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\uFF01";
147
+ }
148
+ }
149
+ return {
150
+ Serv: options.type,
151
+ uids,
152
+ message
153
+ };
154
+ }
155
+ static async refreshCookie(stokenParams, serv) {
156
+ if (Array.isArray(serv)) {
157
+ for (const s of serv) {
158
+ const res2 = await _UserInfo.refreshCookie(stokenParams, s);
159
+ if (Object.keys(res2.cookieParams).length > 0) {
160
+ return res2;
161
+ }
162
+ }
163
+ return {
164
+ Serv: "mihoyo" /* cn */,
165
+ cookieParams: {},
166
+ message: "\u83B7\u53D6Cookie\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0#\u626B\u7801\u767B\u5F55\uFF01"
167
+ };
168
+ }
169
+ const res = (await getCookieTokenBySToken.init(null).request({
170
+ stoken: new URLSearchParams({
171
+ stoken: stokenParams.stoken,
172
+ mid: stokenParams.mid,
173
+ uid: stokenParams.stuid
174
+ }).toString(),
175
+ method: serv === "mihoyo" /* cn */ ? "GET" : "POST"
176
+ })).data;
177
+ let message = "";
178
+ let cookieParams = {};
179
+ if (res?.retcode === -100) {
180
+ message = "\u767B\u5F55\u72B6\u6001\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0#\u626B\u7801\u767B\u5F55\uFF01";
181
+ } else if (res?.data?.cookie_token) {
182
+ cookieParams = {
183
+ ltuid: stokenParams.stuid,
184
+ ltoken: stokenParams.stoken,
185
+ cookie_token: res.data.cookie_token,
186
+ account_id: stokenParams.stuid
187
+ };
188
+ } else {
189
+ message = "\u83B7\u53D6Cookie\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0#\u626B\u7801\u767B\u5F55\uFF01";
190
+ }
191
+ return {
192
+ Serv: serv,
193
+ cookieParams,
194
+ message
195
+ };
196
+ }
197
+ };
198
+
199
+ // src/exports/mys/api/define.ts
200
+ var DefineApi = class {
201
+ #apiInfo;
202
+ /** @description 是否使用Fp请求 */
203
+ #useFp = false;
204
+ constructor(apiInfo) {
205
+ this.#apiInfo = apiInfo;
206
+ }
207
+ get isHoyolab() {
208
+ return this.UserInfo?.type === "hoyolab" /* os */;
209
+ }
210
+ init(userInfo) {
211
+ this.UserInfo = userInfo;
212
+ return {
213
+ request: async (data) => await this.#requestData(this.#apiInfo, data),
214
+ requestCache: async (key, seconds, data) => {
215
+ const redisKey = `${dir.name}:apiCache:${key}`;
216
+ const cache = await redis.get(redisKey);
217
+ if (cache) {
218
+ try {
219
+ const cacheData = JSON.parse(cache);
220
+ return this.#checkDataCode(cacheData);
221
+ } catch (err) {
222
+ logger.error(`[${dir.name}] redisCache(${key}) json parse error:`, err);
223
+ await redis.del(redisKey);
224
+ }
225
+ }
226
+ const result = await this.#requestData(this.#apiInfo, data);
227
+ seconds > 0 && await redis.setEx(redisKey, seconds, JSON.stringify(result));
228
+ return result;
229
+ }
230
+ };
231
+ }
232
+ #setDevice(device, deviceFp) {
233
+ const fingerprintSplit = device.fingerprint.split("/");
234
+ this.DeviceInfo = {
235
+ deviceId: device.deviceId,
236
+ deviceFp: deviceFp || "",
237
+ name: device.name,
238
+ board: device.board,
239
+ model: device.model,
240
+ oaid: device.oaid,
241
+ version: device.version,
242
+ fingerprint: device.fingerprint,
243
+ product: device.product,
244
+ brand: fingerprintSplit[0],
245
+ display: fingerprintSplit[3]
246
+ };
247
+ }
248
+ /** @description 使用CookieHeaders等需要device进行请求时使用 */
249
+ async initDevice(userInfo, deviceFp = false) {
250
+ const defaultDeviceInfo = DeviceCfg.get("");
251
+ if (userInfo?.deviceMd5) {
252
+ const deviceData = await DeviceInfo.get(userInfo.deviceMd5);
253
+ deviceData && this.#setDevice(deviceData);
254
+ }
255
+ if (!this.DeviceInfo) {
256
+ const uuid = crypto.randomUUID();
257
+ this.#setDevice({ ...defaultDeviceInfo, oaid: uuid, deviceId: uuid });
258
+ }
259
+ if (deviceFp && !this.DeviceInfo.deviceFp) {
260
+ const fpData = (await (await getDeviceFp.initDevice(null)).requestCache(`getDeviceFp:${userInfo.ltuid}`, 3600 * 8, null)).data;
261
+ this.#useFp = true;
262
+ this.DeviceInfo.deviceFp = fpData?.data?.device_fp || "38d7faa51d2b6";
263
+ }
264
+ return this.init(userInfo);
265
+ }
266
+ async #requestData(apiInfo, data) {
267
+ const { Url, Body, Method, Options = {}, HeaderFn, Result } = apiInfo(this, data);
268
+ const Headers = new AxiosHeaders(await HeaderFn());
269
+ if (this.#useFp) {
270
+ Headers.set("x-rpc-device_id", this.DeviceInfo.deviceId);
271
+ Headers.set("x-rpc-device_fp", this.DeviceInfo.deviceFp);
272
+ }
273
+ const params = {
274
+ url: Url.href,
275
+ method: Method,
276
+ data: Body,
277
+ headers: Headers
278
+ };
279
+ const start = Date.now();
280
+ let response;
281
+ try {
282
+ if (Method === "GET") {
283
+ response = await axios.get(params.url, {
284
+ headers: params.headers,
285
+ ...Options
286
+ });
287
+ } else if (Method === "POST") {
288
+ response = await axios.post(params.url, params.data, {
289
+ headers: params.headers,
290
+ ...Options
291
+ });
292
+ } else {
293
+ response = await axios.request(params);
294
+ }
295
+ } catch (err) {
296
+ logger.debug(`[${dir.name}] requst-error(${logger.green(`${Date.now() - start}ms`)}): ${JSON.stringify(params, null, 2)}`, err);
297
+ return this.#checkDataCode(null);
298
+ }
299
+ const res = Result ? await Result(response) : { data: response.data, row: response.data };
300
+ logger.debug(`[${dir.name}] requst-success(${logger.green(`${Date.now() - start}ms`)}): ${JSON.stringify(params, null, 2)} -> ${JSON.stringify(res.row, null, 2)}`);
301
+ return this.#checkDataCode(res.data);
302
+ }
303
+ getDS1(saltKey, query = "", body = "") {
304
+ const r = common_exports.randomString(6, "All");
305
+ const t = Math.floor(Date.now() / 1e3);
306
+ let DS = `salt=${MysApp.salt[saltKey]}&t=${t}&r=${r}`;
307
+ if (query || body) DS += `&b=${body}&q=${query}`;
308
+ return `${t},${r},${md5(DS)}`;
309
+ }
310
+ getDS2(saltKey, query = "", body = "") {
311
+ const r = 100001 + Math.floor(Math.random() * 1e5);
312
+ const t = Math.floor(Date.now() / 1e3);
313
+ return `${t},${r},${md5(`salt=${MysApp.salt[saltKey]}&t=${t}&r=${r}&b=${body}&q=${query}`)}`;
314
+ }
315
+ NoHeaders = (options = {}) => ({});
316
+ BaseCnHeaders = () => ({
317
+ "x-rpc-app_version": MysApp.version.cn,
318
+ "x-rpc-client_type": "5",
319
+ "x-rpc-device_id": this.DeviceInfo.deviceId,
320
+ "User-Agent": `Mozilla/5.0 (Linux; Android 12; ${this.DeviceInfo.name}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.73 Mobile Safari/537.36 miHoYoBBS/${MysApp.version.cn}`,
321
+ Referer: "https://webstatic.mihoyo.com"
322
+ });
323
+ BaseOsHeaders = () => ({
324
+ "x-rpc-app_version": MysApp.version.cn,
325
+ "x-rpc-client_type": "4",
326
+ "x-rpc-language": "zh-cn"
327
+ });
328
+ PassportHeaders = (options = {}) => ({
329
+ "x-rpc-app_version": MysApp.version.cn,
330
+ "x-rpc-game_biz": "bbs_cn",
331
+ "x-rpc-client_type": "2",
332
+ "User-Agent": "okhttp/4.8.0",
333
+ "x-rpc-app_id": "bll8iq97cem8",
334
+ DS: this.getDS1("PROD", options.query, JSON.stringify(options.body || ""))
335
+ });
336
+ CookieHeaders = (options = {}) => ({
337
+ Cookie: this.UserInfo.cookie,
338
+ ...this[this.isHoyolab ? "BaseOsHeaders" : "BaseCnHeaders"]()
339
+ });
340
+ OkHttpHeaders = (options = {}) => ({
341
+ "User-Agent": "okhttp/4.9.3",
342
+ Connection: "Keep-Alive",
343
+ "Accept-Encoding": "gzip",
344
+ "Content-Type": "application/json"
345
+ });
346
+ #checkDataCode(data, error = []) {
347
+ return {
348
+ data,
349
+ check: async () => {
350
+ const errMsg = [];
351
+ switch (data?.retcode) {
352
+ case 0:
353
+ case -1002:
354
+ break;
355
+ case -1:
356
+ case -100:
357
+ case 1001:
358
+ case 10001:
359
+ case 10103:
360
+ if (/(登录|login)/i.test(data.message)) {
361
+ logger.mark(`karin-plugin-mys-core: [cookie\u5931\u6548][uid: ${this.UserInfo?.uid}][userId:${this.UserInfo?.userId}]`);
362
+ errMsg.push(`UID:${this.UserInfo?.uid}\uFF0C\u7C73\u6E38\u793ECookie\u5DF2\u5931\u6548\uFF0C\u8BF7\u3010#\u5237\u65B0Cookie\u3011\u6216\u91CD\u65B0\u7ED1\u5B9A\u3002`);
363
+ } else {
364
+ errMsg.push(`UID:${this.UserInfo?.uid}\u7C73\u6E38\u793E\u67E5\u8BE2\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\uFF01`);
365
+ }
366
+ break;
367
+ case 10102:
368
+ if (data.message === "Data is not public for the user") {
369
+ errMsg.push(`UID:${this.UserInfo?.uid}\uFF0C\u7C73\u6E38\u793E\u6570\u636E\u672A\u516C\u5F00\uFF01`);
370
+ } else {
371
+ errMsg.push(`UID:${this.UserInfo?.uid}\uFF0C\u8BF7\u5148\u53BB\u7C73\u6E38\u793E\u7ED1\u5B9A\u89D2\u8272\uFF01`);
372
+ }
373
+ break;
374
+ case 1008:
375
+ errMsg.push(`UID:${this.UserInfo?.uid}\uFF0C\u8BF7\u5148\u53BB\u7C73\u6E38\u793E\u7ED1\u5B9A\u89D2\u8272\uFF01`);
376
+ break;
377
+ case 10101:
378
+ errMsg.push(`UID:${this.UserInfo?.uid}\uFF0C\u67E5\u8BE2\u5DF2\u8FBE\u4ECA\u65E5\u4E0A\u9650\uFF01`);
379
+ break;
380
+ case 5003:
381
+ case 10041:
382
+ logger.mark(`karin-plugin-mys-core: [UID:${this.UserInfo?.uid}][userId:${this.UserInfo?.userId}] \u8D26\u53F7\u5F02\u5E38`);
383
+ errMsg.push(`UID:${this.UserInfo?.uid}\uFF0C\u8D26\u53F7\u5F02\u5E38\uFF0C\u8BF7\u7ED1\u5B9A\u8BBE\u5907\u540E\u67E5\u8BE2\u3002`);
384
+ break;
385
+ case 1034:
386
+ case 10035:
387
+ logger.mark(`karin-plugin-mys-core: [UID:${this.UserInfo?.uid}][userId:${this.UserInfo?.userId}] \u9047\u5230\u9A8C\u8BC1\u7801`);
388
+ errMsg.push(`UID:${this.UserInfo?.uid}\uFF0C\u67E5\u8BE2\u9047\u5230\u9A8C\u8BC1\u7801\uFF0C\u8BF7\u7ED1\u5B9A\u8BBE\u5907\u540E\u67E5\u8BE2\u3002`);
389
+ break;
390
+ case 10307:
391
+ errMsg.push(`UID:${this.UserInfo?.uid}\uFF0C\u7248\u672C\u66F4\u65B0\u671F\u95F4\uFF0C\u6570\u636E\u7EF4\u62A4\u4E2D\u3002`);
392
+ break;
393
+ default:
394
+ errMsg.push(`UID:${this.UserInfo?.uid}\uFF0C\u7C73\u6E38\u793E\u63A5\u53E3\u62A5\u9519\uFF0C\u6682\u65F6\u65E0\u6CD5\u67E5\u8BE2\uFF1A${data?.message || "unknow error"}\u3002`);
395
+ break;
396
+ }
397
+ return this.#checkDataCode(data, errMsg);
398
+ },
399
+ error
400
+ };
401
+ }
402
+ };
403
+
404
+ // src/exports/mys/api/apis.ts
405
+ import lodash from "node-karin/lodash";
406
+ var fetchQRcode = new DefineApi(
407
+ (self, data) => ({
408
+ Method: "POST",
409
+ Url: new URL(`${MysHosts.hk4eSdk}hk4e_cn/combo/panda/qrcode/fetch`),
410
+ Body: {
411
+ app_id: MysApp.appId,
412
+ device: data.device
413
+ },
414
+ HeaderFn: self.NoHeaders
415
+ })
416
+ );
417
+ var queryQRcode = new DefineApi(
418
+ (self, data) => ({
419
+ Method: "POST",
420
+ Url: new URL(`${MysHosts.hk4eSdk}hk4e_cn/combo/panda/qrcode/query`),
421
+ Body: {
422
+ app_id: MysApp.appId,
423
+ device: data.device,
424
+ ticket: data.ticket
425
+ },
426
+ HeaderFn: self.NoHeaders
427
+ })
428
+ );
429
+ var getTokenByGameToken = new DefineApi(
430
+ (self, data) => ({
431
+ Method: "POST",
432
+ Url: new URL(`${MysHosts.passport}account/ma-cn-session/app/getTokenByGameToken`),
433
+ Body: {
434
+ account_id: data.account_id,
435
+ game_token: data.game_token
436
+ },
437
+ HeaderFn: self.PassportHeaders
438
+ })
439
+ );
440
+ var getCookieAccountInfoByGameToken = new DefineApi(
441
+ (self, data) => ({
442
+ Method: "GET",
443
+ Url: new URL(`${MysHosts.web["mihoyo" /* cn */]}auth/api/getCookieAccountInfoByGameToken?account_id=${data.account_id}&game_token=${data.game_token}`),
444
+ HeaderFn: self.NoHeaders
445
+ })
446
+ );
447
+ var getCookieTokenBySToken = new DefineApi(
448
+ (self, data) => ({
449
+ Method: data.method,
450
+ Url: (function() {
451
+ const url = new URL(`${MysHosts.web["mihoyo" /* cn */]}auth/api/getCookieAccountInfoBySToken?game_biz=hk4e_cn&${data.stoken}`);
452
+ if (self.isHoyolab) {
453
+ url.searchParams.set("game_biz", "hk4e_global");
454
+ url.host = MysHosts.web["hoyolab" /* os */].replace(/^https?:\/\//, "");
455
+ }
456
+ return url;
457
+ })(),
458
+ HeaderFn: self.NoHeaders
459
+ })
460
+ );
461
+ var getUserGameRolesByCookie = new DefineApi(
462
+ (self, data) => ({
463
+ Method: "GET",
464
+ Url: new URL(`${MysHosts.web[self.isHoyolab ? "hoyolab" /* os */ : "mihoyo" /* cn */]}binding/api/getUserGameRolesByCookie`),
465
+ HeaderFn: self.CookieHeaders
466
+ })
467
+ );
468
+ var getUserFullInfo = new DefineApi((self, data) => ({
469
+ Method: "GET",
470
+ Url: new URL(`${MysHosts.web.miyoushe}user/wapi/getUserFullInfo?gids=2`),
471
+ HeaderFn: self.CookieHeaders
472
+ }));
473
+ var getDeviceFp = new DefineApi((self, data) => ({
474
+ Method: "POST",
475
+ Url: new URL(`${MysHosts.publicData[self.isHoyolab ? "hoyolab" /* os */ : "mihoyo" /* cn */]}device-fp/api/getFp`),
476
+ Body: (function() {
477
+ const body = {
478
+ device_fp: "38d7faa51d2b6",
479
+ device_id: lodash.sampleSize("0123456789abcdef", 16).join(""),
480
+ ext_fields: `{"proxyStatus":0,"isRoot":0,"romCapacity":"512","deviceName":"${self.DeviceInfo.brand}","productName":"${self.DeviceInfo.model}","romRemain":"456","hostname":"BuildHost","screenSize":"1096x2434","isTablet":0,"aaid":"","model":"${self.DeviceInfo.model}","brand":"${self.DeviceInfo.brand}","hardware":"qcom","deviceType":"${self.DeviceInfo.name}","devId":"REL","serialNumber":"unknown","sdCapacity":107433,"buildTime":"1633631032000","buildUser":"BuildUser","simState":1,"ramRemain":"96757","appUpdateTimeDiff":1722171241616,"deviceInfo":"${self.DeviceInfo.fingerprint}","vaid":"${self.DeviceInfo.oaid}","buildType":"user","sdkVersion":"30","ui_mode":"UI_MODE_TYPE_NORMAL","isMockLocation":0,"cpuType":"arm64-v8a","isAirMode":0,"ringMode":2,"chargeStatus":1,"manufacturer":"${self.DeviceInfo.brand}","emulatorStatus":0,"appMemory":"512","osVersion":"${self.DeviceInfo.version}","vendor":"unknown","accelerometer":"-0.084346995x8.73799x4.6301117","sdRemain":96600,"buildTags":"release-keys","packageName":"com.mihoyo.hyperion","networkType":"WiFi","oaid":"${self.DeviceInfo.oaid}","debugStatus":1,"ramCapacity":"107433","magnetometer":"-13.9125x-17.8875x-5.4750004","display":"${self.DeviceInfo.display}","appInstallTimeDiff":1717065300325,"packageVersion":"2.20.2","gyroscope":"0.017714571x-4.5813544E-4x0.0015271181","batteryStatus":76,"hasKeyboard":0,"board":"${self.DeviceInfo.board}"}`,
481
+ platform: "2",
482
+ seed_id: crypto.randomUUID(),
483
+ seed_time: (/* @__PURE__ */ new Date()).getTime().toString()
484
+ };
485
+ if (self.isHoyolab) {
486
+ body.app_name = "bbs_oversea";
487
+ body.hoyolab_device_id = self.DeviceInfo.deviceId;
488
+ } else {
489
+ body.app_name = "bbs_cn";
490
+ body.bbs_device_id = self.DeviceInfo.deviceId;
491
+ }
492
+ return body;
493
+ })(),
494
+ HeaderFn: self.OkHttpHeaders
495
+ }));
496
+
497
+ export {
498
+ fetchQRcode,
499
+ queryQRcode,
500
+ getTokenByGameToken,
501
+ getCookieAccountInfoByGameToken,
502
+ getCookieTokenBySToken,
503
+ getUserGameRolesByCookie,
504
+ getUserFullInfo,
505
+ getDeviceFp,
506
+ Render,
507
+ BaseUserInfo,
508
+ UserInfo,
509
+ DefineApi
510
+ };
File without changes
@@ -0,0 +1,124 @@
1
+ // src/exports/database/dbs/base.ts
2
+ import { existToMkdirSync, json, logger, rmSync } from "node-karin";
3
+ import lodash from "node-karin/lodash";
4
+ import fs from "fs";
5
+ import path from "path";
6
+ var DbBase = class {
7
+ initBase(DataDir, modelName, modelSchema, type) {
8
+ this.databaseType = type;
9
+ this.databasePath = path.join(DataDir, modelName);
10
+ if (type !== "db" /* Db */) {
11
+ existToMkdirSync(this.databasePath);
12
+ }
13
+ this.modelName = modelName;
14
+ this.modelSchema = modelSchema;
15
+ }
16
+ schemaToJSON(pk) {
17
+ const result = {
18
+ [this.model.primaryKeyAttribute]: pk
19
+ };
20
+ lodash.forEach(this.modelSchema, (value, key) => {
21
+ if (key !== this.model.primaryKeyAttribute) {
22
+ result[key] = typeof value.defaultValue === "function" ? value.defaultValue() : value.defaultValue;
23
+ }
24
+ });
25
+ return result;
26
+ }
27
+ userPath(pk) {
28
+ if (this.databaseType === "dir" /* Dir */) {
29
+ return path.join(this.databasePath, pk);
30
+ }
31
+ return path.join(this.databasePath, `${pk}.json`);
32
+ }
33
+ readSync(path2, pk) {
34
+ const result = json.readSync(path2);
35
+ result.save = this.saveFile(pk);
36
+ result.destroy = () => this.destroyPath(pk);
37
+ return result;
38
+ }
39
+ readDirSync(pk) {
40
+ const path2 = this.userPath(pk);
41
+ const files = fs.readdirSync(path2);
42
+ const result = {
43
+ save: this.saveDir(pk),
44
+ destroy: () => this.destroyPath(pk),
45
+ [this.model.primaryKeyAttribute]: pk
46
+ };
47
+ const filePromises = files.map(async (file) => {
48
+ const data = await json.read(`${path2}/${file}`);
49
+ result[data.key] = data.data;
50
+ });
51
+ Promise.all(filePromises).then().catch((err) => {
52
+ logger.error(err);
53
+ });
54
+ return result;
55
+ }
56
+ writeDirSync(pk, data) {
57
+ const path2 = this.userPath(pk);
58
+ lodash.forEach(this.modelSchema, (value, key) => {
59
+ if (key !== this.model.primaryKeyAttribute) {
60
+ const result = {
61
+ key,
62
+ [this.model.primaryKeyAttribute]: pk,
63
+ data: data[key] || value.defaultValue
64
+ };
65
+ json.writeSync(`${path2}/${key}.json`, result);
66
+ }
67
+ });
68
+ return true;
69
+ }
70
+ saveFile(pk) {
71
+ return async (data) => {
72
+ delete data[this.model.primaryKeyAttribute];
73
+ const defData = this.schemaToJSON(pk);
74
+ const userPath = this.userPath(pk);
75
+ json.writeSync(userPath, lodash.merge({}, defData, data));
76
+ return this.readSync(userPath, pk);
77
+ };
78
+ }
79
+ saveDir(pk) {
80
+ return async (data) => {
81
+ delete data[this.model.primaryKeyAttribute];
82
+ this.writeDirSync(pk, data);
83
+ return this.readDirSync(pk);
84
+ };
85
+ }
86
+ destroyPath(pk) {
87
+ return new Promise((resolve) => {
88
+ const userPath = this.userPath(pk);
89
+ try {
90
+ rmSync(userPath, { recursive: true });
91
+ resolve(true);
92
+ } catch (err) {
93
+ logger.error(err);
94
+ resolve(false);
95
+ }
96
+ });
97
+ }
98
+ saveSql(model, pk) {
99
+ return async (data) => {
100
+ delete data[this.model.primaryKeyAttribute];
101
+ for (const key in data) {
102
+ if (data[key] === void 0) {
103
+ delete data[key];
104
+ }
105
+ }
106
+ const result = await model.update(data);
107
+ return {
108
+ ...result.toJSON(),
109
+ save: this.saveSql(result, pk),
110
+ destroy: () => this.destroySql(pk)
111
+ };
112
+ };
113
+ }
114
+ destroySql(pk) {
115
+ return new Promise((resolve) => {
116
+ const result = this.model.destroy({ where: { [this.model.primaryKeyAttribute]: pk } }).then((count) => count > 0).catch(() => false);
117
+ resolve(result);
118
+ });
119
+ }
120
+ };
121
+
122
+ export {
123
+ DbBase
124
+ };
File without changes
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @description 生成随机字符串
3
+ * @param length - 字符串长度
4
+ */
5
+ declare const randomString: (length: number, type: "Lower" | "Upper" | "All") => string;
6
+ /**
7
+ * @description 生成设备guid
8
+ */
9
+ declare const getDeviceGuid: () => string;
10
+ /**
11
+ * @description 将字符串解析为key-value键值对
12
+ * @param Str - 字符串
13
+ * @param sep - 分隔符
14
+ */
15
+ declare const StrToObj: <D extends {
16
+ [key: string]: string;
17
+ }>(Str: string, sep: string | RegExp) => Partial<D>;
18
+ /**
19
+ * @description 将key-value键值对解析为字符串
20
+ * @param obj - key-value键值对
21
+ * @param sep - 分隔符
22
+ */
23
+ declare const ObjToStr: (obj: Record<string, string | number>, sep: string) => string;
24
+
25
+ declare const common_ObjToStr: typeof ObjToStr;
26
+ declare const common_StrToObj: typeof StrToObj;
27
+ declare const common_getDeviceGuid: typeof getDeviceGuid;
28
+ declare const common_randomString: typeof randomString;
29
+ declare namespace common {
30
+ export { common_ObjToStr as ObjToStr, common_StrToObj as StrToObj, common_getDeviceGuid as getDeviceGuid, common_randomString as randomString };
31
+ }
32
+
33
+ export { ObjToStr as O, StrToObj as S, common as c, getDeviceGuid as g, randomString as r };