karin-plugin-mys-core 1.0.1 → 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 +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-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 -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
@@ -1,371 +0,0 @@
1
- import {
2
- common_exports
3
- } from "./chunk-WYRIRWT5.js";
4
- import {
5
- dir
6
- } from "./chunk-JML6VYXN.js";
7
-
8
- // src/database/dbs/base.ts
9
- import { json, logger } from "node-karin";
10
- import lodash from "node-karin/lodash";
11
- import fs from "fs";
12
- import path from "path";
13
- var DbBase = class {
14
- schemaToJSON(pk) {
15
- const result = {
16
- [this.model.primaryKeyAttribute]: pk
17
- };
18
- lodash.forEach(this.modelSchema, (value, key) => {
19
- if (key !== this.model.primaryKeyAttribute) {
20
- result[key] = typeof value.defaultValue === "function" ? value.defaultValue() : value.defaultValue;
21
- }
22
- });
23
- return result;
24
- }
25
- userPath(pk) {
26
- if (this.databaseType === "dir" /* Dir */) {
27
- return path.join(this.databasePath, pk);
28
- }
29
- return path.join(this.databasePath, `${pk}.json`);
30
- }
31
- readSync(path3, pk) {
32
- const result = json.readSync(path3);
33
- result.save = this.saveFile(pk);
34
- return result;
35
- }
36
- readDirSync(pk) {
37
- const path3 = this.userPath(pk);
38
- const files = fs.readdirSync(path3);
39
- const result = {
40
- save: this.saveDir(pk),
41
- [this.model.primaryKeyAttribute]: pk
42
- };
43
- const filePromises = files.map(async (file) => {
44
- const data = await json.read(`${path3}/${file}`);
45
- result[data.key] = data.data;
46
- });
47
- Promise.all(filePromises).then().catch((err) => {
48
- logger.error(err);
49
- });
50
- return result;
51
- }
52
- writeDirSync(pk, data) {
53
- const path3 = this.userPath(pk);
54
- lodash.forEach(this.modelSchema, (value, key) => {
55
- if (key !== this.model.primaryKeyAttribute) {
56
- const result = {
57
- key,
58
- [this.model.primaryKeyAttribute]: pk,
59
- data: data[key] || value.defaultValue
60
- };
61
- json.writeSync(`${path3}/${key}.json`, result);
62
- }
63
- });
64
- return true;
65
- }
66
- saveFile(pk) {
67
- return async (data) => {
68
- delete data[this.model.primaryKeyAttribute];
69
- const defData = this.schemaToJSON(pk);
70
- const userPath = this.userPath(pk);
71
- json.writeSync(userPath, lodash.merge({}, defData, data));
72
- return this.readSync(userPath, pk);
73
- };
74
- }
75
- saveDir(pk) {
76
- return async (data) => {
77
- delete data[this.model.primaryKeyAttribute];
78
- this.writeDirSync(pk, data);
79
- return this.readDirSync(pk);
80
- };
81
- }
82
- saveSql(model, pk) {
83
- return async (data) => {
84
- delete data[this.model.primaryKeyAttribute];
85
- const result = await model.update(data);
86
- return {
87
- ...result.toJSON(),
88
- save: this.saveSql(result, pk)
89
- };
90
- };
91
- }
92
- };
93
-
94
- // src/database/database.ts
95
- import { logger as logger3 } from "node-karin";
96
- import { DataTypes as DataTypes2 } from "sequelize";
97
-
98
- // src/database/dbs/sqlite3.ts
99
- import { json as json2, logger as logger2 } from "node-karin";
100
- import fs2 from "fs";
101
- import path2 from "path";
102
- import { DataTypes, Sequelize } from "sequelize";
103
- var dialect = "sqlite" /* Sqlite */;
104
- var sequelize = new Sequelize({
105
- storage: path2.join(dir.DataDir, "database", "sqlite3.db"),
106
- dialect,
107
- logging: false
108
- });
109
- var Sqlite3 = class extends DbBase {
110
- dialect = dialect;
111
- async check() {
112
- try {
113
- await sequelize.authenticate();
114
- return true;
115
- } catch (error) {
116
- logger2.error(error);
117
- return false;
118
- }
119
- }
120
- async init(DataDir, modelName, modelSchema, type) {
121
- this.databaseType = type;
122
- this.databasePath = path2.join(DataDir, modelName);
123
- if (type !== "db" /* Db */) {
124
- fs2.mkdirSync(this.databasePath);
125
- }
126
- this.modelName = modelName;
127
- this.modelSchema = modelSchema;
128
- if (this.databaseType === "db" /* Db */) {
129
- this.model = sequelize.define(this.modelName, this.modelSchema, {
130
- timestamps: false
131
- });
132
- await this.model.sync();
133
- const queryInterface = sequelize.getQueryInterface();
134
- const tableDescription = await queryInterface.describeTable(this.modelName);
135
- for (const key in this.modelSchema) {
136
- if (!tableDescription[key]) {
137
- await queryInterface.addColumn(this.modelName, key, this.modelSchema[key]);
138
- if (typeof this.modelSchema[key] === "string") continue;
139
- const defaultValue = this.modelSchema[key].defaultValue;
140
- if (defaultValue !== void 0) {
141
- await this.model.update({ [key]: defaultValue }, { where: {} });
142
- }
143
- }
144
- }
145
- }
146
- return this;
147
- }
148
- async findByPk(pk, create = false) {
149
- if (this.databaseType !== "db" /* Db */) {
150
- const path3 = this.userPath(pk);
151
- if (!fs2.existsSync(path3)) {
152
- if (create) {
153
- const data = this.schemaToJSON(pk);
154
- if (this.databaseType === "dir" /* Dir */) {
155
- fs2.mkdirSync(path3);
156
- this.writeDirSync(pk, data);
157
- return {
158
- ...data,
159
- save: this.saveDir(pk)
160
- };
161
- } else {
162
- json2.writeSync(path3, data);
163
- return {
164
- ...data,
165
- save: this.saveFile(pk)
166
- };
167
- }
168
- }
169
- return void 0;
170
- }
171
- if (this.databaseType === "dir" /* Dir */) {
172
- return this.readDirSync(pk);
173
- } else {
174
- return this.readSync(path3, pk);
175
- }
176
- } else {
177
- let result = await this.model.findByPk(pk);
178
- if (!result && create) {
179
- result = await this.model.create(this.schemaToJSON(pk));
180
- }
181
- if (!result) return void 0;
182
- return {
183
- ...result.toJSON(),
184
- save: this.saveSql(result, pk)
185
- };
186
- }
187
- }
188
- async findAllByPks(pks) {
189
- if (this.databaseType !== "db" /* Db */) {
190
- const result = [];
191
- pks.forEach((pk) => {
192
- const path3 = this.userPath(pk);
193
- if (fs2.existsSync(path3)) {
194
- if (this.databaseType === "dir" /* Dir */) {
195
- result.push(this.readDirSync(pk));
196
- } else {
197
- result.push(this.readSync(path3, pk));
198
- }
199
- }
200
- });
201
- return result;
202
- } else {
203
- const result = await this.model.findAll({
204
- where: {
205
- [this.model.primaryKeyAttribute]: pks
206
- }
207
- });
208
- return result.map((item) => ({
209
- ...item.toJSON(),
210
- save: this.saveSql(item, item[this.model.primaryKeyAttribute])
211
- }));
212
- }
213
- }
214
- async destroy(pk) {
215
- if (this.databaseType !== "db" /* Db */) {
216
- const path3 = this.userPath(pk);
217
- if (this.databaseType === "dir" /* Dir */) {
218
- fs2.rmdirSync(path3, { recursive: true });
219
- } else {
220
- fs2.unlinkSync(path3);
221
- }
222
- return true;
223
- } else {
224
- const destroyed = await this.model.destroy({
225
- where: { [this.model.primaryKeyAttribute]: pk }
226
- });
227
- return destroyed > 0;
228
- }
229
- }
230
- };
231
- var Sqlite3Static = new class Sqlite3Static2 {
232
- Column(type, def, option) {
233
- return {
234
- type: DataTypes[type],
235
- defaultValue: def,
236
- ...option
237
- };
238
- }
239
- ArrayColumn(key, fn) {
240
- return {
241
- type: DataTypes.STRING,
242
- defaultValue: [].join(","),
243
- get() {
244
- return this.getDataValue(key).split(",").filter(Boolean);
245
- },
246
- set(data) {
247
- const setData = (fn ? fn(data) : data) || [];
248
- this.setDataValue(key, setData.join(","));
249
- }
250
- };
251
- }
252
- JsonColumn(key, def = {}) {
253
- return {
254
- type: DataTypes.STRING,
255
- defaultValue: JSON.stringify(def),
256
- get() {
257
- let data = this.getDataValue(key);
258
- try {
259
- data = JSON.parse(data) || def;
260
- } catch (e) {
261
- data = def;
262
- }
263
- return data;
264
- },
265
- set(data) {
266
- this.setDataValue(key, JSON.stringify(data));
267
- }
268
- };
269
- }
270
- }();
271
-
272
- // src/database/database.ts
273
- var DatabaseClass = class {
274
- #defaultDatabase;
275
- #defaultDatabaseStatic;
276
- constructor() {
277
- this.#defaultDatabase = () => new Sqlite3();
278
- this.#defaultDatabaseStatic = Sqlite3Static;
279
- }
280
- /** 设置默认数据库 */
281
- async default(Database2, Static) {
282
- const db = Database2();
283
- if (await db.check()) {
284
- this.#defaultDatabase = Database2;
285
- this.#defaultDatabaseStatic = Static;
286
- } else {
287
- logger3.error();
288
- }
289
- }
290
- /** 获取当前使用的数据库 */
291
- get() {
292
- return this.#defaultDatabase();
293
- }
294
- get PkColumn() {
295
- return (type, option) => ({
296
- type: DataTypes2[type],
297
- primaryKey: true,
298
- allowNull: false,
299
- ...option
300
- });
301
- }
302
- get Column() {
303
- return this.#defaultDatabaseStatic.Column;
304
- }
305
- get ArrayColumn() {
306
- return this.#defaultDatabaseStatic.ArrayColumn;
307
- }
308
- get JsonColumn() {
309
- return this.#defaultDatabaseStatic.JsonColumn;
310
- }
311
- };
312
- var Database = new DatabaseClass();
313
-
314
- // src/database/tables/mysAccountInfo.ts
315
- var DB = Database.get();
316
- var MysAccountInfoDB = await DB.init(
317
- dir.DataDir,
318
- "mysAccountInfoData",
319
- {
320
- ltuid: Database.PkColumn("STRING"),
321
- type: Database.Column("STRING", "mihoyo" /* cn */),
322
- cookie: Database.Column("TEXT", ""),
323
- stoken: Database.Column("STRING", ""),
324
- deviceMd5: Database.Column("STRING", "")
325
- },
326
- "db" /* Db */
327
- );
328
-
329
- // src/database/tables/mysDeviceInfo.ts
330
- var DB2 = Database.get();
331
- var MysDeviceInfoDB = await DB2.init(
332
- dir.DataDir,
333
- "mysDeviceInfoData",
334
- {
335
- md5: Database.PkColumn("STRING"),
336
- deviceId: Database.Column("STRING", common_exports.getDeviceGuid),
337
- deviceFp: Database.Column("STRING", ""),
338
- name: Database.Column("STRING", ""),
339
- board: Database.Column("STRING", ""),
340
- model: Database.Column("STRING", ""),
341
- oaid: Database.Column("STRING", ""),
342
- androidVersion: Database.Column("STRING", ""),
343
- fingerprint: Database.Column("STRING", ""),
344
- product: Database.Column("STRING", "")
345
- },
346
- "db" /* Db */
347
- );
348
-
349
- // src/database/tables/mysUserInfo.ts
350
- var DB3 = Database.get();
351
- var BaseMysUserInfoSchema = {
352
- userId: Database.PkColumn("STRING"),
353
- ltuids: Database.ArrayColumn("ltuids"),
354
- stuids: Database.ArrayColumn("stuids"),
355
- deviceList: Database.ArrayColumn("deviceList")
356
- };
357
- var MysUserInfoDB = await DB3.init(
358
- dir.DataDir,
359
- "mysUserInfoData",
360
- BaseMysUserInfoSchema,
361
- "db" /* Db */
362
- );
363
-
364
- export {
365
- DbBase,
366
- Database,
367
- MysAccountInfoDB,
368
- MysDeviceInfoDB,
369
- BaseMysUserInfoSchema,
370
- MysUserInfoDB
371
- };
@@ -1,213 +0,0 @@
1
- import {
2
- dir
3
- } from "./chunk-JML6VYXN.js";
4
- import {
5
- __export
6
- } from "./chunk-MLKGABMK.js";
7
-
8
- // src/utils/common.ts
9
- var common_exports = {};
10
- __export(common_exports, {
11
- ObjToStr: () => ObjToStr,
12
- StrToObj: () => StrToObj,
13
- getDeviceGuid: () => getDeviceGuid,
14
- getEndOfDay: () => getEndOfDay,
15
- random: () => random,
16
- randomString: () => randomString,
17
- sleep: () => sleep,
18
- timef: () => timef
19
- });
20
- import lodash from "node-karin/lodash";
21
- import moment from "node-karin/moment";
22
- var random = (min, max) => lodash.random(min, max);
23
- var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
24
- var timef = (format = "YYYY-MM-DD HH:mm:ss") => moment().format(format);
25
- var getDeviceGuid = () => {
26
- function S4() {
27
- return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
28
- }
29
- return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4();
30
- };
31
- var randomString = (length, type) => {
32
- let str = "0123456789";
33
- if (type === "Lower" || type === "All") {
34
- str += "abcdefghijklmnopqrstuvwxyz";
35
- }
36
- if (type === "Upper" || type === "All") {
37
- str += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
38
- }
39
- return lodash.sampleSize(str, length).join("");
40
- };
41
- var StrToObj = (Str, sep) => {
42
- const strObj = {};
43
- Str.split(sep).forEach((item) => {
44
- const [key, value] = item.split("=");
45
- if (key) {
46
- strObj[key] = value || "";
47
- }
48
- });
49
- return strObj;
50
- };
51
- var ObjToStr = (obj, sep) => {
52
- return Object.entries(obj).filter(([k, v]) => v).map(([k, v]) => `${k}=${v}`).join(sep) + sep;
53
- };
54
- var getEndOfDay = () => Number(moment().endOf("day").format("X")) - Number(moment().format("X"));
55
-
56
- // src/utils/config.ts
57
- import {
58
- existsSync,
59
- logger,
60
- requireFileSync,
61
- watch,
62
- writeJsonSync
63
- } from "node-karin";
64
- import lodash2 from "node-karin/lodash";
65
- import path from "path";
66
- var DefaultConfig = {
67
- device: {
68
- deviceName: "",
69
- deviceBoard: "",
70
- deviceModel: "",
71
- androidVersion: "",
72
- deviceFingerprint: "",
73
- deviceProduct: ""
74
- },
75
- commands: {
76
- ["BingMysDevice" /* BingMysDevice */]: {
77
- cmds: [],
78
- end: true,
79
- flags: ""
80
- }
81
- }
82
- };
83
- var ConfigPath = path.join(dir.ConfigDir, "config.json");
84
- var Config = class {
85
- /**
86
- * @description 配置文件路径
87
- */
88
- #ConfigPath;
89
- /**
90
- * @description 默认配置(只读)
91
- */
92
- #DefaultConfig;
93
- /**
94
- * @description 配置缓存
95
- */
96
- #configCache = null;
97
- constructor(ConfigPath2, DefaultConfig2) {
98
- this.#ConfigPath = ConfigPath2;
99
- this.#DefaultConfig = Object.freeze(DefaultConfig2);
100
- !existsSync(this.#ConfigPath) && writeJsonSync(this.#ConfigPath, this.#DefaultConfig);
101
- this.loadConfig();
102
- watch(this.#ConfigPath, () => {
103
- logger.info("\u914D\u7F6E\u6587\u4EF6\u5DF2\u4FEE\u6539\uFF0C\u91CD\u65B0\u52A0\u8F7D\u914D\u7F6E");
104
- this.loadConfig();
105
- });
106
- }
107
- loadConfig() {
108
- const config = requireFileSync(this.#ConfigPath);
109
- const mergedConfig = this.mergeWithDefaults(config, this.#DefaultConfig);
110
- this.#configCache = mergedConfig;
111
- return mergedConfig;
112
- }
113
- mergeWithDefaults(userConfig, defaultConfig) {
114
- const filterUserConfig = (user, defaults) => {
115
- if (lodash2.isPlainObject(user) && lodash2.isPlainObject(defaults)) {
116
- const filtered = {};
117
- for (const key in defaults) {
118
- if (Object.prototype.hasOwnProperty.call(user, key)) {
119
- filtered[key] = filterUserConfig(user[key], defaults[key]);
120
- }
121
- }
122
- return filtered;
123
- }
124
- return user;
125
- };
126
- const filteredUserConfig = filterUserConfig(userConfig, defaultConfig);
127
- const result = lodash2.merge({}, defaultConfig, filteredUserConfig);
128
- if (!lodash2.isEqual(result, userConfig)) {
129
- try {
130
- writeJsonSync(this.#ConfigPath, result);
131
- } catch (err) {
132
- logger.error(err);
133
- }
134
- }
135
- return result;
136
- }
137
- /**
138
- * @description 获取配置路径对应的默认配置
139
- */
140
- getDef(path2) {
141
- const defConfig = JSON.parse(JSON.stringify(this.#DefaultConfig));
142
- return lodash2.get(defConfig, path2);
143
- }
144
- get(path2, isArray = false) {
145
- const conf = JSON.parse(JSON.stringify(this.#configCache));
146
- const result = lodash2.get(conf, path2);
147
- if (isArray) {
148
- if (!Array.isArray(result)) {
149
- logger.error(`\u914D\u7F6E\u8DEF\u5F84 ${path2} \u4E0D\u662F\u6570\u7EC4\u7C7B\u578B`);
150
- return new EnhancedArray([], path2);
151
- }
152
- return new EnhancedArray(result, path2);
153
- }
154
- return result;
155
- }
156
- set(path2, value) {
157
- const conf = JSON.parse(JSON.stringify(this.#configCache));
158
- lodash2.set(conf, path2, value);
159
- this.#configCache = conf;
160
- try {
161
- writeJsonSync(`${dir.ConfigDir}/config.json`, conf);
162
- } catch (err) {
163
- logger.error(err);
164
- }
165
- }
166
- /**
167
- * @description 获取触发指令正则表达式
168
- */
169
- getCommand(cmd) {
170
- const command = this.get(`commands.${cmd}`);
171
- return new RegExp(`^(${command.cmds.join("|")})${command.end ? "$" : ""}`, command.flags);
172
- }
173
- };
174
- var Cfg = new Config(ConfigPath, DefaultConfig);
175
- var EnhancedArray = class extends Array {
176
- #keyPath;
177
- constructor(items, path2) {
178
- super(...items);
179
- this.#keyPath = path2;
180
- }
181
- add(element) {
182
- if (this.some((item) => lodash2.isEqual(item, element))) {
183
- return this;
184
- }
185
- this.push(element);
186
- Cfg.set(this.#keyPath, this.slice());
187
- return this;
188
- }
189
- remove(predicate, isIndex = false) {
190
- let newArr = [];
191
- if (isIndex && lodash2.isNumber(predicate)) {
192
- if (predicate < 0 || predicate >= this.length) {
193
- logger.error(`\u7D22\u5F15 ${predicate} \u8D85\u51FA\u8303\u56F4`);
194
- return this;
195
- }
196
- newArr = [...this.slice(0, predicate), ...this.slice(predicate + 1)];
197
- } else if (lodash2.isFunction(predicate)) {
198
- newArr = this.filter((item) => !predicate(item));
199
- } else {
200
- newArr = lodash2.without(this, predicate);
201
- }
202
- this.length = 0;
203
- this.push(...newArr);
204
- Cfg.set(this.#keyPath, this.slice());
205
- return this;
206
- }
207
- };
208
-
209
- export {
210
- common_exports,
211
- Config,
212
- Cfg
213
- };
@@ -1,5 +0,0 @@
1
- import { a as DatabaseType, c as DatabaseClassInstance } from './base-BJv9XnQP.js';
2
-
3
- type DatabaseFn = <T extends Record<string, any>, D extends DatabaseType>() => DatabaseClassInstance<T, D>;
4
-
5
- export type { DatabaseFn as D };