karin-plugin-mys-core 1.0.1 → 1.0.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.
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 +177 -109
  4. package/lib/apps/MysDevice.d.ts +2 -2
  5. package/lib/apps/MysDevice.js +65 -23
  6. package/lib/apps/UIDManage.d.ts +10 -0
  7. package/lib/apps/UIDManage.js +52 -0
  8. package/lib/array-DuqoS2wx.d.ts +62 -0
  9. package/lib/chunk-2DHTKQ34.js +0 -0
  10. package/lib/chunk-3BIQN6QA.js +27 -0
  11. package/lib/chunk-5NA7ZPDS.js +54 -0
  12. package/lib/chunk-6PIXUPZ6.js +82 -0
  13. package/lib/chunk-7KEG6SDX.js +0 -0
  14. package/lib/chunk-7SZX3RBZ.js +0 -0
  15. package/lib/chunk-7VAWV6ZE.js +0 -0
  16. package/lib/chunk-7WESXE4X.js +29 -0
  17. package/lib/chunk-ARLTXJFJ.js +0 -0
  18. package/lib/chunk-CFS2WFOO.js +0 -0
  19. package/lib/chunk-COKAJ7V6.js +31 -0
  20. package/lib/chunk-EMAUATE3.js +217 -0
  21. package/lib/chunk-FBWSEBAW.js +0 -0
  22. package/lib/chunk-FOAQZIZ2.js +0 -0
  23. package/lib/chunk-G547WVGV.js +73 -0
  24. package/lib/chunk-G5W5WAY5.js +64 -0
  25. package/lib/chunk-HNODD2IL.js +179 -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-JKZ5NRPX.js +130 -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-RWBRS7SA.js +510 -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-UVMX6WUC.js +38 -0
  43. package/lib/chunk-W4DBT7AD.js +0 -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 -15
  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/lib/app.d.ts +0 -2
  153. package/lib/base-BJv9XnQP.d.ts +0 -120
  154. package/lib/chunk-CQNW7LJI.js +0 -38
  155. package/lib/chunk-MV2UE7C7.js +0 -410
  156. package/lib/chunk-NHUNEZXM.js +0 -371
  157. package/lib/chunk-WYRIRWT5.js +0 -213
  158. package/lib/database-byVXw91u.d.ts +0 -5
  159. package/lib/define-pa_pWNWT.d.ts +0 -182
  160. package/lib/exports/core.d.ts +0 -249
  161. package/lib/exports/core.js +0 -45
  162. package/lib/exports/database.d.ts +0 -48
  163. package/lib/exports/database.js +0 -20
  164. package/lib/exports/types.d.ts +0 -5
  165. package/lib/exports/types.js +0 -13
  166. package/lib/index.d.ts +0 -2
  167. package/lib/web.config.d.ts +0 -5
  168. package/lib/web.config.js +0 -55
@@ -0,0 +1,510 @@
1
+ import {
2
+ DeviceInfo
3
+ } from "./chunk-COKAJ7V6.js";
4
+ import {
5
+ MysGame
6
+ } from "./chunk-3BIQN6QA.js";
7
+ import {
8
+ MysApp,
9
+ MysHosts
10
+ } from "./chunk-G5W5WAY5.js";
11
+ import {
12
+ Config
13
+ } from "./chunk-JKZ5NRPX.js";
14
+ import {
15
+ MysAccountInfoDB
16
+ } from "./chunk-KN5SHBVI.js";
17
+ import {
18
+ MysDeviceInfoDB
19
+ } from "./chunk-UVMX6WUC.js";
20
+ import {
21
+ MysUserInfoDB
22
+ } from "./chunk-7WESXE4X.js";
23
+ import {
24
+ common_exports
25
+ } from "./chunk-LG34FPBI.js";
26
+ import {
27
+ RenderTemplate
28
+ } from "./chunk-HVYNK5BN.js";
29
+ import {
30
+ dir
31
+ } from "./chunk-SHLPPEAY.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
@@ -6,38 +6,34 @@ var pluginDir = fileURLToPath(new URL("../", import.meta.url));
6
6
  var pluginName = path.basename(pluginDir);
7
7
  var pkg = requireFileSync(path.join(pluginDir, "package.json"));
8
8
  var dir = {
9
- /** 根目录绝对路径 */
9
+ /** @description 根目录绝对路径 */
10
10
  pluginDir,
11
- /** 插件目录名称 */
11
+ /** @description 插件目录名称 */
12
12
  pluginName,
13
- /** package.json */
13
+ /** @description package.json */
14
14
  pkg,
15
- /** 插件版本 package.json 的 version */
15
+ /** @description 插件版本 package.json 的 version */
16
16
  get version() {
17
17
  return pkg.version;
18
18
  },
19
- /** 插件名称 package.json 的 name */
19
+ /** @description 插件名称 package.json 的 name */
20
20
  get name() {
21
21
  return pkg.name;
22
22
  },
23
- /** 插件默认配置目录 */
24
- get defConfigDir() {
25
- return path.join(pluginDir, "config");
26
- },
27
- /** 在`@karinjs`中的绝对路径 */
23
+ /** @description 在`@karinjs`中的绝对路径 */
28
24
  get karinPath() {
29
25
  return path.join(karinPathBase, pluginName);
30
26
  },
31
- /** 插件配置目录 `@karinjs/karin-plugin-xxx/config` */
32
- get ConfigDir() {
33
- return path.join(this.karinPath, "config");
34
- },
35
- /** 插件数据目录 `@karinjs/karin-plugin-xxx/data` */
27
+ /** @description 插件数据目录 `@karinjs/karin-plugin-xxx/data` */
36
28
  get DataDir() {
37
29
  return path.join(this.karinPath, "data");
38
30
  },
39
- /** 插件资源目录 `@karinjs/karin-plugin-xxx/resources` */
40
- get defResourcesDir() {
31
+ /** @description 插件配置目录 `@karinjs/karin-plugin-xxx/config` */
32
+ get ConfigDir() {
33
+ return path.join(this.karinPath, "config");
34
+ },
35
+ /** @description 插件资源目录 `@karinjs/karin-plugin-xxx/resources` */
36
+ get ResourcesDir() {
41
37
  return path.join(this.karinPath, "resources");
42
38
  }
43
39
  };
@@ -0,0 +1,10 @@
1
+ // src/exports/database/types/tables/mysAccountInfo.ts
2
+ var MysAccountType = /* @__PURE__ */ ((MysAccountType2) => {
3
+ MysAccountType2["cn"] = "mihoyo";
4
+ MysAccountType2["os"] = "hoyolab";
5
+ return MysAccountType2;
6
+ })(MysAccountType || {});
7
+
8
+ export {
9
+ MysAccountType
10
+ };
@@ -0,0 +1,38 @@
1
+ import {
2
+ Table
3
+ } from "./chunk-5NA7ZPDS.js";
4
+ import {
5
+ common_exports
6
+ } from "./chunk-LG34FPBI.js";
7
+ import {
8
+ Database
9
+ } from "./chunk-G547WVGV.js";
10
+ import {
11
+ dir
12
+ } from "./chunk-SHLPPEAY.js";
13
+
14
+ // src/exports/database/tables/mysDeviceInfo.ts
15
+ var MysDeviceInfoTable = new Table(
16
+ dir.DataDir,
17
+ "mys_device_info_data",
18
+ "db" /* Db */
19
+ );
20
+ var MysDeviceInfoDB = await MysDeviceInfoTable.init(
21
+ {
22
+ md5: Database.PkColumn("STRING"),
23
+ deviceId: Database.Column("STRING", common_exports.getDeviceGuid),
24
+ deviceFp: Database.Column("STRING", ""),
25
+ name: Database.Column("STRING", ""),
26
+ board: Database.Column("STRING", ""),
27
+ model: Database.Column("STRING", ""),
28
+ oaid: Database.Column("STRING", ""),
29
+ version: Database.Column("INTEGER", 12),
30
+ fingerprint: Database.Column("STRING", ""),
31
+ product: Database.Column("STRING", "")
32
+ }
33
+ );
34
+
35
+ export {
36
+ MysDeviceInfoTable,
37
+ MysDeviceInfoDB
38
+ };
File without changes
File without changes