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,179 @@
1
+ import {
2
+ Render,
3
+ UserInfo
4
+ } from "./chunk-RWBRS7SA.js";
5
+ import {
6
+ MysGame
7
+ } from "./chunk-3BIQN6QA.js";
8
+
9
+ // src/apps/UIDManage.ts
10
+ import karin, { handler, segment } from "node-karin";
11
+ var BindUID = karin.command(
12
+ /^#?(.*?)绑定uid(?:\s*(.+))?$/i,
13
+ async (e, next) => {
14
+ const msgMatch = e.msg.match(/^#?(?<prefix>.*?)绑定uid(?:\s*(?<uid>.+))?$/i)?.groups;
15
+ const Game = MysGame.match(msgMatch.prefix?.trim() || "");
16
+ if (!Game) return next();
17
+ const uid = msgMatch.uid?.trim();
18
+ if (!uid) {
19
+ e.reply("\u8BF7\u63D0\u4F9B\u8981\u7ED1\u5B9A\u7684\u6E38\u620FUID\uFF01", { at: true });
20
+ return true;
21
+ }
22
+ const userInfo = await Game.UserInfo.create(e.userId);
23
+ const bindUids = userInfo.bind_uids;
24
+ if (!(uid in bindUids)) {
25
+ bindUids[uid] = { perm: 0 /* BIND */, ltuid: "" };
26
+ }
27
+ await userInfo.saveUserInfo({
28
+ [Game.game + "-main"]: uid,
29
+ [Game.game + "-uids"]: bindUids
30
+ });
31
+ await handler.call(`MYS.${Game.game}.ShowUID`, { e });
32
+ return true;
33
+ }
34
+ );
35
+ var getMainUid = (uid, mainUid, bindUids) => {
36
+ if (mainUid !== uid) return mainUid;
37
+ const filterUids = Object.entries(bindUids).filter((value) => value[1].perm !== 4 /* DEL */);
38
+ if (filterUids.length > 0) return filterUids[0][0];
39
+ return "";
40
+ };
41
+ var UnbindUID = karin.command(
42
+ /^#?(.*?)(删除|解绑)uid(?:\s*(.+))?$/i,
43
+ async (e, next) => {
44
+ const msgMatch = e.msg.match(/^#?(?<prefix>.*?)(删除|解绑)uid(?:\s*(?<idx>.+))?$/i)?.groups;
45
+ const Game = MysGame.match(msgMatch.prefix?.trim() || "");
46
+ if (!Game) return next();
47
+ const uid = msgMatch.idx?.trim();
48
+ const idx = +uid.split(".")[0];
49
+ if (isNaN(idx)) {
50
+ e.reply("\u8BF7\u6B63\u786E\u63D0\u4F9B\u8981\u89E3\u7ED1\u7684\u6E38\u620FUID\u6216\u5E8F\u53F7\uFF01", { at: true });
51
+ return true;
52
+ }
53
+ const userInfo = await Game.UserInfo.create(e.userId);
54
+ const bindUids = userInfo.bind_uids;
55
+ let delUid = uid;
56
+ if (idx <= 1e4) {
57
+ const filterUids = Object.entries(bindUids).filter((value) => value[1].perm !== 4 /* DEL */);
58
+ if (idx > filterUids.length || idx <= 0) {
59
+ e.reply("UID\u5E8F\u53F7\u4E0D\u5B58\u5728\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u65B0\u8F93\u5165\uFF01", { at: true });
60
+ return "break";
61
+ }
62
+ delUid = filterUids[idx - 1][0];
63
+ }
64
+ if (delUid in bindUids) {
65
+ if (bindUids[delUid].perm === 0 /* BIND */) {
66
+ delete bindUids[delUid];
67
+ } else {
68
+ bindUids[delUid].perm = 4 /* DEL */;
69
+ }
70
+ } else {
71
+ e.reply("UID\u672A\u7ED1\u5B9A\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u65B0\u8F93\u5165\uFF01", { at: true });
72
+ return "break";
73
+ }
74
+ const mainUid = getMainUid(delUid, userInfo.main_uid, bindUids);
75
+ await userInfo.saveUserInfo({
76
+ [Game.game + "-main"]: mainUid,
77
+ [Game.game + "-uids"]: bindUids
78
+ });
79
+ await handler.call(`MYS.${Game.game}.ShowUID`, { e });
80
+ return true;
81
+ }
82
+ );
83
+ var ShowBindAccountCmdFunc = async (e) => {
84
+ const userInfo = await UserInfo.create(e.userId, true);
85
+ const renderData = {
86
+ User: {
87
+ userId: e.userId,
88
+ avatar: e.contact.name,
89
+ nickname: await e.bot.getAvatarUrl(e.userId, 100)
90
+ },
91
+ AccountList: []
92
+ };
93
+ const ltuidInfoList = userInfo.LtuidInfoList;
94
+ if (ltuidInfoList.length > 0) {
95
+ for (const ltuidInfo of ltuidInfoList) {
96
+ const data = {
97
+ ltuid: ltuidInfo.ltuid,
98
+ permission: 0 /* BIND */,
99
+ bindUids: []
100
+ };
101
+ if (ltuidInfo.cookie) {
102
+ data.permission += 1 /* CK */;
103
+ }
104
+ if (ltuidInfo.stoken) {
105
+ data.permission += 2 /* ST */;
106
+ }
107
+ await MysGame.forEachGame(async (Game) => {
108
+ const gameUserInfo = await Game.UserInfo.create(e.userId);
109
+ data.bindUids.push({
110
+ gameName: Game.name,
111
+ uids: Object.entries(gameUserInfo.bind_uids).filter(([, info]) => info.ltuid === ltuidInfo.ltuid).map(([uid, info]) => ({
112
+ uid,
113
+ perm: info.perm
114
+ }))
115
+ });
116
+ });
117
+ renderData.AccountList.push(data);
118
+ }
119
+ }
120
+ const image = await Render.template("ShowBindAccount", renderData);
121
+ image && e.reply(segment.image(image), { at: true });
122
+ return true;
123
+ };
124
+ var ShowBindAccount = karin.command(
125
+ /^#?(米游社|mys)账号(列表)?$/i,
126
+ ShowBindAccountCmdFunc
127
+ );
128
+ var UnbindAccount = karin.command(
129
+ /^#?(删除|解绑)(米游社|mys)账号(?:\s*(.+))?$/i,
130
+ async (e) => {
131
+ const msgMatch = e.msg.match(/^#?(删除|解绑)(米游社|mys)账号(?:\s*(?<idx>.+))?$/i)?.groups;
132
+ const uid = msgMatch.idx?.trim();
133
+ const idx = +uid.split(".")[0];
134
+ if (isNaN(idx)) {
135
+ e.reply("\u8BF7\u6B63\u786E\u63D0\u4F9B\u8981\u89E3\u7ED1\u7684\u7C73\u6E38\u793EUID\u6216\u5E8F\u53F7\uFF01", { at: true });
136
+ return true;
137
+ }
138
+ const userInfo = await UserInfo.create(e.userId, true);
139
+ let ltuidInfo;
140
+ const ltuidInfoList = userInfo.LtuidInfoList;
141
+ if (idx < 1e4) {
142
+ if (idx > ltuidInfoList.length || idx <= 0) {
143
+ e.reply("\u7C73\u6E38\u793EUID\u5E8F\u53F7\u4E0D\u5B58\u5728\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u65B0\u8F93\u5165\uFF01", { at: true });
144
+ return true;
145
+ }
146
+ ltuidInfo = ltuidInfoList[idx - 1];
147
+ } else {
148
+ ltuidInfo = ltuidInfoList.find((info) => info.ltuid === uid);
149
+ if (!ltuidInfo) {
150
+ e.reply("\u7C73\u6E38\u793EUID\u672A\u7ED1\u5B9A\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u65B0\u8F93\u5165\uFF01", { at: true });
151
+ return true;
152
+ }
153
+ }
154
+ const ltuid = ltuidInfo.ltuid;
155
+ await ltuidInfo.destroy();
156
+ await userInfo.saveUserInfo({
157
+ ltuids: userInfo.ltuids.remove(ltuid),
158
+ stuids: userInfo.stuids.remove(ltuid)
159
+ });
160
+ await MysGame.forEachGame(async (Game) => {
161
+ const gameUserInfo = await Game.UserInfo.create(e.userId);
162
+ const bindUids = gameUserInfo.bind_uids;
163
+ for (const uid2 in bindUids) {
164
+ if (bindUids[uid2].ltuid === ltuid) {
165
+ bindUids[uid2].perm = 0 /* BIND */;
166
+ }
167
+ }
168
+ });
169
+ return await ShowBindAccountCmdFunc(e);
170
+ }
171
+ );
172
+
173
+ export {
174
+ BindUID,
175
+ UnbindUID,
176
+ ShowBindAccountCmdFunc,
177
+ ShowBindAccount,
178
+ UnbindAccount
179
+ };
@@ -0,0 +1,45 @@
1
+ // src/exports/utils/render.ts
2
+ import karin, { config } from "node-karin";
3
+ import path from "path";
4
+ var RenderTemplate = class {
5
+ #renderCfg;
6
+ constructor(cfg) {
7
+ this.#renderCfg = cfg;
8
+ }
9
+ /** @description 渲染Html路径为:resources/template/${template}/index.html */
10
+ async template(template, rendeDdata, options = {}) {
11
+ const img = await karin.render({
12
+ name: `${this.#renderCfg.name}/${template}`,
13
+ data: {
14
+ ...rendeDdata,
15
+ plugin: {
16
+ ...options.plugin || {},
17
+ template,
18
+ name: this.#renderCfg.name,
19
+ version: this.#renderCfg.version,
20
+ resources: {
21
+ default: path.join(this.#renderCfg.pluginDir, "resources").replace(/\\/g, "/"),
22
+ download: this.#renderCfg.ResourcesDir.replace(/\\/g, "/")
23
+ },
24
+ defaultLayout: path.join(this.#renderCfg.pluginDir, "resources/template/layout/default.html")
25
+ },
26
+ karin: {
27
+ version: config.pkg().version
28
+ }
29
+ },
30
+ type: options.type || "jpeg",
31
+ omitBackground: options.type === "png",
32
+ selector: "container",
33
+ file: path.join(this.#renderCfg.pluginDir, `resources/template/${template}/index.html`),
34
+ setViewport: {
35
+ deviceScaleFactor: 2
36
+ }
37
+ });
38
+ if (!img) return null;
39
+ return "base64://" + img;
40
+ }
41
+ };
42
+
43
+ export {
44
+ RenderTemplate
45
+ };
@@ -0,0 +1,13 @@
1
+ // src/exports/database/types/tables/mysUserInfo.ts
2
+ var UidPermission = /* @__PURE__ */ ((UidPermission2) => {
3
+ UidPermission2[UidPermission2["BIND"] = 0] = "BIND";
4
+ UidPermission2[UidPermission2["CK"] = 1] = "CK";
5
+ UidPermission2[UidPermission2["ST"] = 2] = "ST";
6
+ UidPermission2[UidPermission2["CS"] = 3] = "CS";
7
+ UidPermission2[UidPermission2["DEL"] = 4] = "DEL";
8
+ return UidPermission2;
9
+ })(UidPermission || {});
10
+
11
+ export {
12
+ UidPermission
13
+ };
@@ -0,0 +1,19 @@
1
+ // src/exports/mys/types/user/userInfo.ts
2
+ var RegisterGameBase = class {
3
+ game;
4
+ columnKey;
5
+ /** @description 游戏名称 */
6
+ name;
7
+ /** @description 指令前缀匹配 */
8
+ prefix;
9
+ constructor(game, name, prefix) {
10
+ this.game = game;
11
+ this.columnKey = `${game}-uids`;
12
+ this.name = name;
13
+ this.prefix = prefix;
14
+ }
15
+ };
16
+
17
+ export {
18
+ RegisterGameBase
19
+ };
@@ -0,0 +1,130 @@
1
+ import {
2
+ EnhancedArray
3
+ } from "./chunk-6PIXUPZ6.js";
4
+
5
+ // src/exports/config/config.ts
6
+ import { existsSync, logger, requireFileSync, watch, writeJsonSync } from "node-karin";
7
+ import lodash from "node-karin/lodash";
8
+ var Config = class {
9
+ #cfgName;
10
+ /**
11
+ * @description 配置缓存
12
+ */
13
+ #ConfigCache = null;
14
+ /**
15
+ * @description 默认配置
16
+ */
17
+ #DefaultConfig;
18
+ #DefineConfig;
19
+ /**
20
+ * @description 配置保存路径
21
+ */
22
+ #ConfigPath;
23
+ /**
24
+ * @param name 插件名称:配置名称
25
+ */
26
+ constructor(name, ConfigPath, DefaultConfig, DefineConfig) {
27
+ this.#cfgName = name;
28
+ this.#ConfigPath = ConfigPath;
29
+ this.#DefaultConfig = DefaultConfig;
30
+ this.#DefineConfig = DefineConfig;
31
+ !existsSync(ConfigPath) && writeJsonSync(ConfigPath, DefaultConfig);
32
+ this.loadConfig();
33
+ }
34
+ loadConfig() {
35
+ const config = requireFileSync(this.#ConfigPath);
36
+ const mergedConfig = this.mergeWithDefaults(config, this.#DefaultConfig, this.#DefineConfig);
37
+ this.#ConfigCache = mergedConfig;
38
+ return mergedConfig;
39
+ }
40
+ mergeWithDefaults(userConfig, defaultConfig, IgnoreConfig) {
41
+ const filterUserConfig = (user, defaults, Ignore) => {
42
+ if (Array.isArray(user) && Array.isArray(defaults)) {
43
+ if (Ignore?.defaultConfigItem) {
44
+ const filtered = [];
45
+ const required = Ignore.defaultConfigItem.required;
46
+ user.forEach((value, key) => {
47
+ if (required && lodash.isPlainObject(value)) {
48
+ const hasAllRequired = required.every((requiredKey) => requiredKey in value && value[requiredKey] !== void 0 && value[requiredKey] !== null && value[requiredKey] !== "");
49
+ if (!hasAllRequired) return;
50
+ }
51
+ filtered[key] = filterUserConfig(value, Ignore.defaultConfigItem.defaultConfig, Ignore.defaultConfigItem.defaultConfig);
52
+ });
53
+ return filtered;
54
+ }
55
+ return user;
56
+ } else if (lodash.isPlainObject(user) && lodash.isPlainObject(defaults)) {
57
+ const filtered = {};
58
+ const mergedValue = lodash.merge({}, defaults, user);
59
+ if (Ignore?.defaultConfig) {
60
+ lodash.forEach(user, (value, key) => {
61
+ const mergedValue2 = lodash.merge(Array.isArray(value) ? [] : {}, Ignore.defaultConfig, value);
62
+ filtered[key] = filterUserConfig(mergedValue2, Ignore.defaultConfig, Array.isArray(value) ? Ignore : Ignore[key]);
63
+ });
64
+ }
65
+ lodash.forEach(defaults, (value, key) => {
66
+ filtered[key] = filterUserConfig(mergedValue[key], value, Ignore?.[key]);
67
+ });
68
+ return filtered;
69
+ }
70
+ return user;
71
+ };
72
+ const filteredUserConfig = filterUserConfig(userConfig, defaultConfig, IgnoreConfig);
73
+ const result = lodash.merge({}, defaultConfig, filteredUserConfig);
74
+ if (!lodash.isEqual(result, userConfig)) {
75
+ try {
76
+ writeJsonSync(this.#ConfigPath, result);
77
+ } catch (err) {
78
+ logger.error(err);
79
+ }
80
+ }
81
+ return result;
82
+ }
83
+ /**
84
+ * @description 获取配置路径对应的默认配置
85
+ */
86
+ getDef(path) {
87
+ const defConfig = JSON.parse(JSON.stringify(this.#DefaultConfig));
88
+ return lodash.get(defConfig, path);
89
+ }
90
+ get(path, isArray = false, def) {
91
+ const conf = JSON.parse(JSON.stringify(this.#ConfigCache));
92
+ const result = path ? lodash.get(conf, path, def) : conf;
93
+ if (isArray) {
94
+ if (!Array.isArray(result)) {
95
+ logger.error(`\u914D\u7F6E\u8DEF\u5F84 ${path} \u4E0D\u662F\u6570\u7EC4\u7C7B\u578B`);
96
+ return new EnhancedArray(this, [], path);
97
+ }
98
+ return new EnhancedArray(this, result, path);
99
+ }
100
+ return result;
101
+ }
102
+ /**
103
+ * @param save 是否立即保存
104
+ */
105
+ set(path, value, save) {
106
+ lodash.set(this.#ConfigCache, path, value);
107
+ save && this.save();
108
+ }
109
+ /**
110
+ * @description 立即保存配置
111
+ */
112
+ save() {
113
+ try {
114
+ logger.debug(`[${this.#cfgName}] \u4FDD\u5B58\u914D\u7F6E`, this.#ConfigCache);
115
+ writeJsonSync(this.#ConfigPath, this.#ConfigCache);
116
+ } catch (err) {
117
+ logger.error(err);
118
+ }
119
+ }
120
+ watch() {
121
+ watch(this.#ConfigPath, () => {
122
+ this.loadConfig();
123
+ });
124
+ return this;
125
+ }
126
+ };
127
+
128
+ export {
129
+ Config
130
+ };
File without changes
@@ -0,0 +1,89 @@
1
+ // src/exports/database/types/dbs/base.ts
2
+ import { logger } from "node-karin";
3
+ import lodash from "node-karin/lodash";
4
+ var Dialect = /* @__PURE__ */ ((Dialect2) => {
5
+ Dialect2["Sqlite"] = "sqlite";
6
+ Dialect2["MySQL"] = "mysql";
7
+ Dialect2["MariaDB"] = "mariadb";
8
+ Dialect2["PostgreSQL"] = "postgres";
9
+ Dialect2["MSSQL"] = "mssql";
10
+ Dialect2["Oracle"] = "oracle";
11
+ Dialect2["DB2"] = "db2";
12
+ Dialect2["Snowflake"] = "snowflake";
13
+ return Dialect2;
14
+ })(Dialect || {});
15
+ var DatabaseType = /* @__PURE__ */ ((DatabaseType2) => {
16
+ DatabaseType2["File"] = "file";
17
+ DatabaseType2["Dir"] = "dir";
18
+ DatabaseType2["Db"] = "db";
19
+ return DatabaseType2;
20
+ })(DatabaseType || {});
21
+ var DatabaseArray = class _DatabaseArray extends Array {
22
+ constructor(items) {
23
+ super();
24
+ Object.setPrototypeOf(this, _DatabaseArray.prototype);
25
+ if (Array.isArray(items)) {
26
+ this.push(...items);
27
+ }
28
+ }
29
+ /**
30
+ * @param element - string | number
31
+ * @returns
32
+ */
33
+ has(element) {
34
+ return new Set(this).has(element);
35
+ }
36
+ /**
37
+ * @param isEqual 是否不添加重复元素
38
+ */
39
+ add(element, isEqual) {
40
+ if (isEqual) {
41
+ const existingSet = new Set(this.map((item) => JSON.stringify(item)));
42
+ if (existingSet.has(JSON.stringify(element))) return this;
43
+ }
44
+ this.push(element);
45
+ return this;
46
+ }
47
+ /**
48
+ * @param isEqual 是否不添加重复元素
49
+ */
50
+ addSome(elements, isEqual) {
51
+ if (isEqual) {
52
+ const existingSet = new Set(this.map((item) => JSON.stringify(item)));
53
+ elements = elements.filter((element) => !existingSet.has(JSON.stringify(element)));
54
+ if (elements.length === 0) return this;
55
+ }
56
+ this.push(...elements);
57
+ return this;
58
+ }
59
+ /**
60
+ * @param isIndex predicate是否为索引
61
+ */
62
+ remove(predicate, isIndex = false) {
63
+ let newArr = [];
64
+ if (isIndex && lodash.isNumber(predicate)) {
65
+ if (predicate < 0 || predicate >= this.length) {
66
+ logger.error(`DatabaseArray\u7D22\u5F15 ${predicate} \u8D85\u51FA\u8303\u56F4`);
67
+ return this;
68
+ }
69
+ newArr = [...this.slice(0, predicate), ...this.slice(predicate + 1)];
70
+ } else if (lodash.isFunction(predicate)) {
71
+ newArr = this.filter((item) => !predicate(item));
72
+ } else {
73
+ newArr = lodash.without(this, predicate);
74
+ }
75
+ this.length = 0;
76
+ this.push(...newArr);
77
+ return this;
78
+ }
79
+ clear() {
80
+ this.length = 0;
81
+ return this;
82
+ }
83
+ };
84
+
85
+ export {
86
+ Dialect,
87
+ DatabaseType,
88
+ DatabaseArray
89
+ };
File without changes
@@ -0,0 +1,30 @@
1
+ import {
2
+ Table
3
+ } from "./chunk-5NA7ZPDS.js";
4
+ import {
5
+ Database
6
+ } from "./chunk-G547WVGV.js";
7
+ import {
8
+ dir
9
+ } from "./chunk-SHLPPEAY.js";
10
+
11
+ // src/exports/database/tables/mysAccountInfo.ts
12
+ var MysAccountInfoTable = new Table(
13
+ dir.DataDir,
14
+ "mys_account_info_data",
15
+ "db" /* Db */
16
+ );
17
+ var MysAccountInfoDB = await MysAccountInfoTable.init(
18
+ {
19
+ ltuid: Database.PkColumn("STRING"),
20
+ type: Database.Column("STRING", "mihoyo" /* cn */),
21
+ cookie: Database.Column("TEXT", ""),
22
+ stoken: Database.Column("STRING", ""),
23
+ deviceMd5: Database.Column("STRING", "")
24
+ }
25
+ );
26
+
27
+ export {
28
+ MysAccountInfoTable,
29
+ MysAccountInfoDB
30
+ };
@@ -0,0 +1,50 @@
1
+ import {
2
+ __export
3
+ } from "./chunk-MLKGABMK.js";
4
+
5
+ // src/exports/utils/common.ts
6
+ var common_exports = {};
7
+ __export(common_exports, {
8
+ ObjToStr: () => ObjToStr,
9
+ StrToObj: () => StrToObj,
10
+ getDeviceGuid: () => getDeviceGuid,
11
+ randomString: () => randomString
12
+ });
13
+ import lodash from "node-karin/lodash";
14
+ var randomString = (length, type) => {
15
+ let str = "0123456789";
16
+ if (type === "Lower" || type === "All") {
17
+ str += "abcdefghijklmnopqrstuvwxyz";
18
+ }
19
+ if (type === "Upper" || type === "All") {
20
+ str += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
21
+ }
22
+ return lodash.sampleSize(str, length).join("");
23
+ };
24
+ var getDeviceGuid = () => {
25
+ function S4() {
26
+ return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
27
+ }
28
+ return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4();
29
+ };
30
+ var StrToObj = (Str, sep) => {
31
+ const strObj = {};
32
+ Str.split(sep).forEach((item) => {
33
+ const [key, value] = item.split("=");
34
+ if (key) {
35
+ strObj[key] = value || "";
36
+ }
37
+ });
38
+ return strObj;
39
+ };
40
+ var ObjToStr = (obj, sep) => {
41
+ return Object.entries(obj).filter(([k, v]) => v).map(([k, v]) => `${k}=${v}`).join(sep) + sep;
42
+ };
43
+
44
+ export {
45
+ randomString,
46
+ getDeviceGuid,
47
+ StrToObj,
48
+ ObjToStr,
49
+ common_exports
50
+ };
File without changes
File without changes
File without changes