node-karin 1.1.1 → 1.1.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.
- package/CHANGELOG.md +32 -0
- package/dist/cli/index.cjs +8 -6
- package/dist/cli/index.js +8 -6
- package/dist/index.d.ts +13 -4
- package/dist/index.js +219 -155
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## [1.1.3](https://github.com/KarinJS/Karin/compare/core-v1.1.2...core-v1.1.3) (2025-01-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### 🐛 Bug Fixes
|
|
7
|
+
|
|
8
|
+
* 热更新`.env` ([90c4eb8](https://github.com/KarinJS/Karin/commit/90c4eb86dbefd236b7a672a8c5a0c0a848964fff))
|
|
9
|
+
|
|
10
|
+
## [1.1.2](https://github.com/KarinJS/Karin/compare/core-v1.1.1...core-v1.1.2) (2025-01-16)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### 🐛 Bug Fixes
|
|
14
|
+
|
|
15
|
+
* create-karin ([758e20f](https://github.com/KarinJS/Karin/commit/758e20f2d824d23a998fe85c02883e1db53148f9))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### 🎫 Chores
|
|
19
|
+
|
|
20
|
+
* release main ([#238](https://github.com/KarinJS/Karin/issues/238)) ([0d68b7b](https://github.com/KarinJS/Karin/commit/0d68b7b9fdcb1857ece912b0c246273a4433567b))
|
|
21
|
+
|
|
22
|
+
## [1.1.1](https://github.com/KarinJS/Karin/compare/core-v1.1.0...core-v1.1.1) (2025-01-16)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### 🐛 Bug Fixes
|
|
26
|
+
|
|
27
|
+
* create-karin ([758e20f](https://github.com/KarinJS/Karin/commit/758e20f2d824d23a998fe85c02883e1db53148f9))
|
|
28
|
+
* getPlugins ([5484dfa](https://github.com/KarinJS/Karin/commit/5484dfac88e404116c8e61b755d8ced02aecc576))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### 🎫 Chores
|
|
32
|
+
|
|
33
|
+
* release main ([#237](https://github.com/KarinJS/Karin/issues/237)) ([f97e931](https://github.com/KarinJS/Karin/commit/f97e931e88c1fed0bb973ef06b7a33797a961c0a))
|
|
34
|
+
|
|
3
35
|
## [1.1.1](https://github.com/KarinJS/Karin/compare/core-v1.1.0...core-v1.1.1) (2025-01-16)
|
|
4
36
|
|
|
5
37
|
|
package/dist/cli/index.cjs
CHANGED
|
@@ -125,7 +125,7 @@ var createDir = () => {
|
|
|
125
125
|
path2__default.default.join(dir, "@karinjs", "temp", "console"),
|
|
126
126
|
path2__default.default.join(dir, "@karinjs", "temp", "html")
|
|
127
127
|
];
|
|
128
|
-
isDev && list.push(path2__default.default.join(dir, "plugins", "karin-plugin-example"));
|
|
128
|
+
!isDev && list.push(path2__default.default.join(dir, "plugins", "karin-plugin-example"));
|
|
129
129
|
list.forEach((item) => {
|
|
130
130
|
if (!fs2__default.default.existsSync(item)) fs2__default.default.mkdirSync(item, { recursive: true });
|
|
131
131
|
});
|
|
@@ -248,8 +248,8 @@ var createWorkspace = (dir2) => {
|
|
|
248
248
|
fs2__default.default.writeFileSync(workspace, content);
|
|
249
249
|
};
|
|
250
250
|
var createOtherFile = async () => {
|
|
251
|
-
isDev && createPnpmFile(dir);
|
|
252
|
-
isDev && createWorkspace(dir);
|
|
251
|
+
!isDev && createPnpmFile(dir);
|
|
252
|
+
!isDev && createWorkspace(dir);
|
|
253
253
|
if (!shouldSkipNpmrc()) {
|
|
254
254
|
createOrUpdateNpmrc(dir);
|
|
255
255
|
}
|
|
@@ -280,9 +280,11 @@ var modifyPackageJson = () => {
|
|
|
280
280
|
if (!data.scripts) data.scripts = {};
|
|
281
281
|
data.scripts.karin = "karin";
|
|
282
282
|
const list = ["app", "start", "pm2", "stop", "rs", "log"];
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
283
|
+
if (!isDev) {
|
|
284
|
+
list.forEach((v) => {
|
|
285
|
+
data.scripts[v] = `karin ${v}`;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
286
288
|
fs2__default.default.writeFileSync(path2__default.default.join(dir, "package.json"), JSON.stringify(data, null, 2));
|
|
287
289
|
return data;
|
|
288
290
|
};
|
package/dist/cli/index.js
CHANGED
|
@@ -116,7 +116,7 @@ var createDir = () => {
|
|
|
116
116
|
path2.join(dir, "@karinjs", "temp", "console"),
|
|
117
117
|
path2.join(dir, "@karinjs", "temp", "html")
|
|
118
118
|
];
|
|
119
|
-
isDev && list.push(path2.join(dir, "plugins", "karin-plugin-example"));
|
|
119
|
+
!isDev && list.push(path2.join(dir, "plugins", "karin-plugin-example"));
|
|
120
120
|
list.forEach((item) => {
|
|
121
121
|
if (!fs2.existsSync(item)) fs2.mkdirSync(item, { recursive: true });
|
|
122
122
|
});
|
|
@@ -239,8 +239,8 @@ var createWorkspace = (dir2) => {
|
|
|
239
239
|
fs2.writeFileSync(workspace, content);
|
|
240
240
|
};
|
|
241
241
|
var createOtherFile = async () => {
|
|
242
|
-
isDev && createPnpmFile(dir);
|
|
243
|
-
isDev && createWorkspace(dir);
|
|
242
|
+
!isDev && createPnpmFile(dir);
|
|
243
|
+
!isDev && createWorkspace(dir);
|
|
244
244
|
if (!shouldSkipNpmrc()) {
|
|
245
245
|
createOrUpdateNpmrc(dir);
|
|
246
246
|
}
|
|
@@ -271,9 +271,11 @@ var modifyPackageJson = () => {
|
|
|
271
271
|
if (!data.scripts) data.scripts = {};
|
|
272
272
|
data.scripts.karin = "karin";
|
|
273
273
|
const list = ["app", "start", "pm2", "stop", "rs", "log"];
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
274
|
+
if (!isDev) {
|
|
275
|
+
list.forEach((v) => {
|
|
276
|
+
data.scripts[v] = `karin ${v}`;
|
|
277
|
+
});
|
|
278
|
+
}
|
|
277
279
|
fs2.writeFileSync(path2.join(dir, "package.json"), JSON.stringify(data, null, 2));
|
|
278
280
|
return data;
|
|
279
281
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -8957,6 +8957,8 @@ interface Config {
|
|
|
8957
8957
|
admin: string[];
|
|
8958
8958
|
/** 用户管理 */
|
|
8959
8959
|
user: {
|
|
8960
|
+
/** 是否启用用户事件 */
|
|
8961
|
+
enable: boolean;
|
|
8960
8962
|
/** 用户白名单 */
|
|
8961
8963
|
enable_list: string[];
|
|
8962
8964
|
/** 用户黑名单 */
|
|
@@ -9198,7 +9200,7 @@ type Groups = Record<string, {
|
|
|
9198
9200
|
}>;
|
|
9199
9201
|
|
|
9200
9202
|
/**
|
|
9201
|
-
* `
|
|
9203
|
+
* `privates.json` 类型
|
|
9202
9204
|
*/
|
|
9203
9205
|
type Privates = Record<string, {
|
|
9204
9206
|
/** 好友消息冷却时间,单位秒,0则无限制 */
|
|
@@ -9279,8 +9281,9 @@ declare const clearTemp: () => void;
|
|
|
9279
9281
|
/**
|
|
9280
9282
|
* 更新日志等级
|
|
9281
9283
|
* @param level 日志等级
|
|
9284
|
+
* @returns 返回更新后的日志等级
|
|
9282
9285
|
*/
|
|
9283
|
-
declare const updateLevel: (level?: string) =>
|
|
9286
|
+
declare const updateLevel: (level?: string) => string;
|
|
9284
9287
|
|
|
9285
9288
|
/**
|
|
9286
9289
|
* 获取群聊、频道配置
|
|
@@ -9530,6 +9533,11 @@ declare const getDirectCfg: (userId: string, selfId: string) => {
|
|
|
9530
9533
|
readonly key: string;
|
|
9531
9534
|
};
|
|
9532
9535
|
|
|
9536
|
+
/**
|
|
9537
|
+
* 监听.env文件变化并自动重新加载
|
|
9538
|
+
*/
|
|
9539
|
+
declare const watchEnv: () => void;
|
|
9540
|
+
|
|
9533
9541
|
declare const index_admin: typeof admin;
|
|
9534
9542
|
declare const index_authKey: typeof authKey;
|
|
9535
9543
|
declare const index_clearTemp: typeof clearTemp;
|
|
@@ -9557,9 +9565,10 @@ declare const index_setStr: typeof setStr;
|
|
|
9557
9565
|
declare const index_setYaml: typeof setYaml;
|
|
9558
9566
|
declare const index_timeout: typeof timeout;
|
|
9559
9567
|
declare const index_updateLevel: typeof updateLevel;
|
|
9568
|
+
declare const index_watchEnv: typeof watchEnv;
|
|
9560
9569
|
declare const index_webSocketServerToken: typeof webSocketServerToken;
|
|
9561
9570
|
declare namespace index {
|
|
9562
|
-
export { adapter$1 as adapter, index_admin as admin, index_authKey as authKey, index_clearTemp as clearTemp, index_config as config, index_defaultConfig as defaultConfig, index_ffmpegPath as ffmpegPath, index_ffplayPath as ffplayPath, index_ffprobePath as ffprobePath, index_getDirectCfg as getDirectCfg, index_getFriendCfg as getFriendCfg, index_getGroupCfg as getGroupCfg, index_getGuildCfg as getGuildCfg, index_getYaml as getYaml, index_groups as groups, index_host as host, index_lint as lint, index_master as master, index_mergeData as mergeData, index_pkg as pkg, index_pm2 as pm2, index_port as port, index_privates as privates, index_redis as redis, render$1 as render, index_setStr as setStr, index_setYaml as setYaml, index_timeout as timeout, index_updateLevel as updateLevel, index_webSocketServerToken as webSocketServerToken };
|
|
9571
|
+
export { adapter$1 as adapter, index_admin as admin, index_authKey as authKey, index_clearTemp as clearTemp, index_config as config, index_defaultConfig as defaultConfig, index_ffmpegPath as ffmpegPath, index_ffplayPath as ffplayPath, index_ffprobePath as ffprobePath, index_getDirectCfg as getDirectCfg, index_getFriendCfg as getFriendCfg, index_getGroupCfg as getGroupCfg, index_getGuildCfg as getGuildCfg, index_getYaml as getYaml, index_groups as groups, index_host as host, index_lint as lint, index_master as master, index_mergeData as mergeData, index_pkg as pkg, index_pm2 as pm2, index_port as port, index_privates as privates, index_redis as redis, render$1 as render, index_setStr as setStr, index_setYaml as setYaml, index_timeout as timeout, index_updateLevel as updateLevel, index_watchEnv as watchEnv, index_webSocketServerToken as webSocketServerToken };
|
|
9563
9572
|
}
|
|
9564
9573
|
|
|
9565
9574
|
/** ws 服务 */
|
|
@@ -9684,7 +9693,7 @@ declare const contact: {
|
|
|
9684
9693
|
declare class AdapterConsole extends AdapterBase implements AdapterType {
|
|
9685
9694
|
constructor();
|
|
9686
9695
|
get selfId(): string;
|
|
9687
|
-
createEvent(data: Buffer): void
|
|
9696
|
+
createEvent(data: Buffer): Promise<void>;
|
|
9688
9697
|
sendMsg(contact: Contact, elements: Array<Elements>, retryCount?: number): Promise<SendMsgResults>;
|
|
9689
9698
|
getUrl(data: string | Buffer, ext: string): Promise<string>;
|
|
9690
9699
|
}
|
package/dist/index.js
CHANGED
|
@@ -492,9 +492,9 @@ var init_data = __esm({
|
|
|
492
492
|
stream2.on("end", () => resolve(Buffer.concat(chunks)));
|
|
493
493
|
stream2.on("error", (error) => reject(error));
|
|
494
494
|
});
|
|
495
|
-
readFile = async (
|
|
495
|
+
readFile = async (path17) => {
|
|
496
496
|
try {
|
|
497
|
-
const data = await fs5.promises.readFile(
|
|
497
|
+
const data = await fs5.promises.readFile(path17);
|
|
498
498
|
return data;
|
|
499
499
|
} catch (error) {
|
|
500
500
|
logger.error(error);
|
|
@@ -801,9 +801,11 @@ var init_config = __esm({
|
|
|
801
801
|
updateLevel = (level2) => {
|
|
802
802
|
if (level2) {
|
|
803
803
|
logger.level = level2;
|
|
804
|
-
return;
|
|
804
|
+
return level2;
|
|
805
805
|
}
|
|
806
|
-
|
|
806
|
+
const newLevel = process.env.LOG_LEVEL || "info";
|
|
807
|
+
logger.level = newLevel;
|
|
808
|
+
return newLevel;
|
|
807
809
|
};
|
|
808
810
|
watch(FILE, async (_, data) => {
|
|
809
811
|
cache3 = await lint(defaultConfig.config, data);
|
|
@@ -1147,10 +1149,10 @@ var init_yaml = __esm({
|
|
|
1147
1149
|
* 获取指定路径的值
|
|
1148
1150
|
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
1149
1151
|
*/
|
|
1150
|
-
get(
|
|
1152
|
+
get(path17) {
|
|
1151
1153
|
try {
|
|
1152
|
-
if (!
|
|
1153
|
-
return lodash.get(this.document.toJSON(),
|
|
1154
|
+
if (!path17) return this.document.toJSON();
|
|
1155
|
+
return lodash.get(this.document.toJSON(), path17);
|
|
1154
1156
|
} catch (error) {
|
|
1155
1157
|
logger.error(`[YamlEditor] \u83B7\u53D6\u6570\u636E\u65F6\u51FA\u9519\uFF1A${error}`);
|
|
1156
1158
|
return null;
|
|
@@ -1162,9 +1164,9 @@ var init_yaml = __esm({
|
|
|
1162
1164
|
* @param value - 要设置的值 允许的类型:`string`, `boolean`, `number`, `object`, `array`
|
|
1163
1165
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1164
1166
|
*/
|
|
1165
|
-
set(
|
|
1167
|
+
set(path17, value, isSplit = true) {
|
|
1166
1168
|
try {
|
|
1167
|
-
const _path = typeof
|
|
1169
|
+
const _path = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1168
1170
|
this.document.setIn(_path, value);
|
|
1169
1171
|
return true;
|
|
1170
1172
|
} catch (error) {
|
|
@@ -1178,11 +1180,11 @@ var init_yaml = __esm({
|
|
|
1178
1180
|
* @param value - 要添加的值
|
|
1179
1181
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1180
1182
|
*/
|
|
1181
|
-
add(
|
|
1183
|
+
add(path17, value, isSplit = true) {
|
|
1182
1184
|
try {
|
|
1183
|
-
const _path = typeof
|
|
1185
|
+
const _path = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1184
1186
|
this.document.addIn(_path, value);
|
|
1185
|
-
logger.debug(`[YamlEditor] \u5DF2\u5728 ${
|
|
1187
|
+
logger.debug(`[YamlEditor] \u5DF2\u5728 ${path17} \u6DFB\u52A0\u65B0\u7684\u503C`);
|
|
1186
1188
|
return true;
|
|
1187
1189
|
} catch (error) {
|
|
1188
1190
|
logger.error(`[YamlEditor] \u6DFB\u52A0\u6570\u636E\u65F6\u51FA\u9519\uFF1A${error}`);
|
|
@@ -1195,9 +1197,9 @@ var init_yaml = __esm({
|
|
|
1195
1197
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1196
1198
|
* @returns 是否删除成功
|
|
1197
1199
|
*/
|
|
1198
|
-
del(
|
|
1200
|
+
del(path17, isSplit = true) {
|
|
1199
1201
|
try {
|
|
1200
|
-
const _path = typeof
|
|
1202
|
+
const _path = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1201
1203
|
this.document.deleteIn(_path);
|
|
1202
1204
|
return true;
|
|
1203
1205
|
} catch (error) {
|
|
@@ -1212,9 +1214,9 @@ var init_yaml = __esm({
|
|
|
1212
1214
|
* @param prepend - 如果为 true,则添加到数组的开头,否则添加到末尾
|
|
1213
1215
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1214
1216
|
*/
|
|
1215
|
-
append(
|
|
1217
|
+
append(path17, value, prepend = false, isSplit = true) {
|
|
1216
1218
|
try {
|
|
1217
|
-
const _path = typeof
|
|
1219
|
+
const _path = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1218
1220
|
let current = this.document.getIn(_path);
|
|
1219
1221
|
if (!current) {
|
|
1220
1222
|
current = new YAML.YAMLSeq();
|
|
@@ -1225,7 +1227,7 @@ var init_yaml = __esm({
|
|
|
1225
1227
|
} else {
|
|
1226
1228
|
prepend ? current.items.unshift(value) : current.add(value);
|
|
1227
1229
|
}
|
|
1228
|
-
logger.debug(`[YamlEditor] \u5DF2\u5411 ${
|
|
1230
|
+
logger.debug(`[YamlEditor] \u5DF2\u5411 ${path17} \u6570\u7EC4${prepend ? "\u5F00\u5934" : "\u672B\u5C3E"}\u6DFB\u52A0\u65B0\u5143\u7D20\uFF1A${value}`);
|
|
1229
1231
|
return true;
|
|
1230
1232
|
} catch (error) {
|
|
1231
1233
|
logger.error(`[YamlEditor] \u5411\u6570\u7EC4\u6DFB\u52A0\u5143\u7D20\u65F6\u51FA\u9519\uFF1A${error}`);
|
|
@@ -1238,9 +1240,9 @@ var init_yaml = __esm({
|
|
|
1238
1240
|
* @param value - 要删除的值
|
|
1239
1241
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1240
1242
|
*/
|
|
1241
|
-
remove(
|
|
1243
|
+
remove(path17, value, isSplit = true) {
|
|
1242
1244
|
try {
|
|
1243
|
-
const _path = typeof
|
|
1245
|
+
const _path = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1244
1246
|
const current = this.document.getIn(_path);
|
|
1245
1247
|
if (!current) {
|
|
1246
1248
|
logger.error("[YamlEditor] \u6307\u5B9A\u7684\u8DEF\u5F84\u4E0D\u5B58\u5728");
|
|
@@ -1256,7 +1258,7 @@ var init_yaml = __esm({
|
|
|
1256
1258
|
return false;
|
|
1257
1259
|
}
|
|
1258
1260
|
current.items.splice(index4, 1);
|
|
1259
|
-
logger.debug(`[YamlEditor] \u5DF2\u4ECE ${
|
|
1261
|
+
logger.debug(`[YamlEditor] \u5DF2\u4ECE ${path17} \u6570\u7EC4\u5220\u9664\u5143\u7D20\uFF1A${value}`);
|
|
1260
1262
|
return true;
|
|
1261
1263
|
} catch (error) {
|
|
1262
1264
|
logger.error(`[YamlEditor] \u4ECE\u6570\u7EC4\u5220\u9664\u5143\u7D20\u65F6\u51FA\u9519\uFF1A${error}`);
|
|
@@ -1268,9 +1270,9 @@ var init_yaml = __esm({
|
|
|
1268
1270
|
* @param path - 路径,用点号分隔
|
|
1269
1271
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1270
1272
|
*/
|
|
1271
|
-
has(
|
|
1273
|
+
has(path17, isSplit = true) {
|
|
1272
1274
|
try {
|
|
1273
|
-
const _path = typeof
|
|
1275
|
+
const _path = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1274
1276
|
return this.document.hasIn(_path);
|
|
1275
1277
|
} catch (error) {
|
|
1276
1278
|
logger.error(`[YamlEditor] \u68C0\u67E5\u8DEF\u5F84\u662F\u5426\u5B58\u5728\u65F6\u51FA\u9519\uFF1A${error}`);
|
|
@@ -1283,9 +1285,9 @@ var init_yaml = __esm({
|
|
|
1283
1285
|
* @param value - 要查询的值
|
|
1284
1286
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1285
1287
|
*/
|
|
1286
|
-
hasval(
|
|
1288
|
+
hasval(path17, value, isSplit = true) {
|
|
1287
1289
|
try {
|
|
1288
|
-
const _path = typeof
|
|
1290
|
+
const _path = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1289
1291
|
const current = this.document.getIn(_path);
|
|
1290
1292
|
if (!current) return false;
|
|
1291
1293
|
if (current instanceof YAML.YAMLSeq) {
|
|
@@ -1296,7 +1298,7 @@ var init_yaml = __esm({
|
|
|
1296
1298
|
return lodash.isEqual(current, value);
|
|
1297
1299
|
}
|
|
1298
1300
|
} catch (error) {
|
|
1299
|
-
logger.error(`[YamlEditor] \u68C0\u67E5\u8DEF\u5F84 ${
|
|
1301
|
+
logger.error(`[YamlEditor] \u68C0\u67E5\u8DEF\u5F84 ${path17} \u662F\u5426\u5305\u542B\u503C\u65F6\u51FA\u9519\uFF1A${error}`);
|
|
1300
1302
|
return false;
|
|
1301
1303
|
}
|
|
1302
1304
|
}
|
|
@@ -1306,8 +1308,8 @@ var init_yaml = __esm({
|
|
|
1306
1308
|
* @param value - 要查询的值
|
|
1307
1309
|
* @deprecated 请使用 `hasval` 代替
|
|
1308
1310
|
*/
|
|
1309
|
-
hasVal(
|
|
1310
|
-
return this.hasval(
|
|
1311
|
+
hasVal(path17, value) {
|
|
1312
|
+
return this.hasval(path17, value);
|
|
1311
1313
|
}
|
|
1312
1314
|
/**
|
|
1313
1315
|
* 向根节点新增元素,如果根节点不是数组,则将其转换为数组再新增元素
|
|
@@ -1352,9 +1354,9 @@ var init_yaml = __esm({
|
|
|
1352
1354
|
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
1353
1355
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1354
1356
|
*/
|
|
1355
|
-
getpair(
|
|
1356
|
-
if (!
|
|
1357
|
-
const keys = typeof
|
|
1357
|
+
getpair(path17, isSplit = true) {
|
|
1358
|
+
if (!path17) throw new Error("path is required");
|
|
1359
|
+
const keys = typeof path17 === "string" ? isSplit ? path17.split(".") : [path17] : path17;
|
|
1358
1360
|
let pair = this.document.contents;
|
|
1359
1361
|
keys.forEach((key) => {
|
|
1360
1362
|
if (isMap(pair)) {
|
|
@@ -1374,10 +1376,10 @@ var init_yaml = __esm({
|
|
|
1374
1376
|
* @param prepend - 如果为 true,则添加注释到开头,否则添加到同一行的末尾
|
|
1375
1377
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1376
1378
|
*/
|
|
1377
|
-
comment(
|
|
1378
|
-
if (!
|
|
1379
|
-
const pair = this.getpair(
|
|
1380
|
-
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${
|
|
1379
|
+
comment(path17, comment2, prepend = true, isSplit = true) {
|
|
1380
|
+
if (!path17) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
|
|
1381
|
+
const pair = this.getpair(path17, isSplit);
|
|
1382
|
+
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path17}`);
|
|
1381
1383
|
comment2 = ` ${comment2}`;
|
|
1382
1384
|
if (prepend) {
|
|
1383
1385
|
pair.key.commentBefore = comment2;
|
|
@@ -1391,10 +1393,10 @@ var init_yaml = __esm({
|
|
|
1391
1393
|
* @param type - 要删除的注释类型,`before` 为注释前,`after` 为注释后,`all` 为全部
|
|
1392
1394
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1393
1395
|
*/
|
|
1394
|
-
uncomment(
|
|
1395
|
-
if (!
|
|
1396
|
-
const pair = this.getpair(
|
|
1397
|
-
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${
|
|
1396
|
+
uncomment(path17, type = "all", isSplit = true) {
|
|
1397
|
+
if (!path17) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
|
|
1398
|
+
const pair = this.getpair(path17, isSplit);
|
|
1399
|
+
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path17}`);
|
|
1398
1400
|
if (type === "all") {
|
|
1399
1401
|
delete pair.key.comment;
|
|
1400
1402
|
delete pair.key.commentBefore;
|
|
@@ -1410,10 +1412,10 @@ var init_yaml = __esm({
|
|
|
1410
1412
|
* @param type - 要检查的注释类型,`before` 为注释前,`after` 为注释后
|
|
1411
1413
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1412
1414
|
*/
|
|
1413
|
-
hascomment(
|
|
1414
|
-
if (!
|
|
1415
|
-
const pair = this.getpair(
|
|
1416
|
-
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${
|
|
1415
|
+
hascomment(path17, type, isSplit = true) {
|
|
1416
|
+
if (!path17) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
|
|
1417
|
+
const pair = this.getpair(path17, isSplit);
|
|
1418
|
+
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path17}`);
|
|
1417
1419
|
if (type === "before") {
|
|
1418
1420
|
return !!pair.key.commentBefore;
|
|
1419
1421
|
} else if (type === "after") {
|
|
@@ -1426,10 +1428,10 @@ var init_yaml = __esm({
|
|
|
1426
1428
|
* @param path - 路径,多个路径使用`.`连接,例如:`a.b.c`
|
|
1427
1429
|
* @param isSplit - 是否使用分割路径路径,默认为 `true`
|
|
1428
1430
|
*/
|
|
1429
|
-
getcomment(
|
|
1430
|
-
if (!
|
|
1431
|
-
const pair = this.getpair(
|
|
1432
|
-
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${
|
|
1431
|
+
getcomment(path17, isSplit = true) {
|
|
1432
|
+
if (!path17) throw new Error("[YamlEditor] path \u4E0D\u80FD\u4E3A\u7A7A");
|
|
1433
|
+
const pair = this.getpair(path17, isSplit);
|
|
1434
|
+
if (!pair) throw new Error(`[YamlEditor] \u672A\u627E\u5230\u8282\u70B9 ${path17}`);
|
|
1433
1435
|
return pair.key.commentBefore || pair.key.comment;
|
|
1434
1436
|
}
|
|
1435
1437
|
/**
|
|
@@ -1441,11 +1443,11 @@ var init_yaml = __esm({
|
|
|
1441
1443
|
logger.debug("[YamlEditor] \u6587\u4EF6\u5DF2\u4FDD\u5B58");
|
|
1442
1444
|
}
|
|
1443
1445
|
};
|
|
1444
|
-
read = (
|
|
1445
|
-
const data = YAML.parse(fs8.readFileSync(
|
|
1446
|
+
read = (path17) => {
|
|
1447
|
+
const data = YAML.parse(fs8.readFileSync(path17, "utf-8"));
|
|
1446
1448
|
read.save = (options) => {
|
|
1447
1449
|
try {
|
|
1448
|
-
save(
|
|
1450
|
+
save(path17, data, typeof options === "string" ? JSON.parse(options) : options);
|
|
1449
1451
|
return true;
|
|
1450
1452
|
} catch (error) {
|
|
1451
1453
|
logger.error("[YamlEditor] \u4FDD\u5B58\u6587\u4EF6\u65F6\u51FA\u9519");
|
|
@@ -1455,23 +1457,23 @@ var init_yaml = __esm({
|
|
|
1455
1457
|
};
|
|
1456
1458
|
return data;
|
|
1457
1459
|
};
|
|
1458
|
-
write = (
|
|
1460
|
+
write = (path17, value) => {
|
|
1459
1461
|
try {
|
|
1460
|
-
fs8.writeFileSync(
|
|
1462
|
+
fs8.writeFileSync(path17, YAML.stringify(value));
|
|
1461
1463
|
return true;
|
|
1462
1464
|
} catch {
|
|
1463
1465
|
return false;
|
|
1464
1466
|
}
|
|
1465
1467
|
};
|
|
1466
|
-
save = (
|
|
1468
|
+
save = (path17, value, options) => {
|
|
1467
1469
|
if (!options) {
|
|
1468
|
-
fs8.writeFileSync(
|
|
1470
|
+
fs8.writeFileSync(path17, YAML.stringify(value));
|
|
1469
1471
|
return;
|
|
1470
1472
|
}
|
|
1471
1473
|
const editor = new YamlEditor(YAML.stringify(value));
|
|
1472
1474
|
const comment2 = typeof options === "string" ? JSON.parse(fs8.readFileSync(options, "utf8")) : options;
|
|
1473
1475
|
applyComments(editor, comment2);
|
|
1474
|
-
fs8.writeFileSync(
|
|
1476
|
+
fs8.writeFileSync(path17, editor.document.toString());
|
|
1475
1477
|
};
|
|
1476
1478
|
comment = (filePath, commentConfig) => {
|
|
1477
1479
|
const editor = new YamlEditor(filePath);
|
|
@@ -1770,6 +1772,29 @@ var init_privates = __esm({
|
|
|
1770
1772
|
}
|
|
1771
1773
|
});
|
|
1772
1774
|
|
|
1775
|
+
// src/utils/config/env.ts
|
|
1776
|
+
import path6 from "node:path";
|
|
1777
|
+
import dotenv from "dotenv";
|
|
1778
|
+
import chokidar2 from "chokidar";
|
|
1779
|
+
var watchEnv;
|
|
1780
|
+
var init_env2 = __esm({
|
|
1781
|
+
"src/utils/config/env.ts"() {
|
|
1782
|
+
"use strict";
|
|
1783
|
+
init_esm_shims();
|
|
1784
|
+
watchEnv = () => {
|
|
1785
|
+
const targetPath = path6.join(process.cwd(), ".env");
|
|
1786
|
+
const watcher = chokidar2.watch(targetPath, { persistent: true, ignoreInitial: true });
|
|
1787
|
+
const runtime = process.env.RUNTIME;
|
|
1788
|
+
watcher.on("change", () => {
|
|
1789
|
+
logger.info("[\u914D\u7F6E\u6587\u4EF6\u53D8\u52A8] .env");
|
|
1790
|
+
dotenv.config({ path: targetPath, override: true });
|
|
1791
|
+
process.env.RUNTIME = runtime;
|
|
1792
|
+
});
|
|
1793
|
+
};
|
|
1794
|
+
watchEnv();
|
|
1795
|
+
}
|
|
1796
|
+
});
|
|
1797
|
+
|
|
1773
1798
|
// src/utils/config/index.ts
|
|
1774
1799
|
var config_exports2 = {};
|
|
1775
1800
|
__export(config_exports2, {
|
|
@@ -1802,6 +1827,7 @@ __export(config_exports2, {
|
|
|
1802
1827
|
setYaml: () => setYaml,
|
|
1803
1828
|
timeout: () => timeout,
|
|
1804
1829
|
updateLevel: () => updateLevel,
|
|
1830
|
+
watchEnv: () => watchEnv,
|
|
1805
1831
|
webSocketServerToken: () => webSocketServerToken
|
|
1806
1832
|
});
|
|
1807
1833
|
var init_config2 = __esm({
|
|
@@ -1816,6 +1842,7 @@ var init_config2 = __esm({
|
|
|
1816
1842
|
init_adapter();
|
|
1817
1843
|
init_default();
|
|
1818
1844
|
init_privates();
|
|
1845
|
+
init_env2();
|
|
1819
1846
|
}
|
|
1820
1847
|
});
|
|
1821
1848
|
|
|
@@ -1897,7 +1924,7 @@ var init_time = __esm({
|
|
|
1897
1924
|
// src/utils/fs/path.ts
|
|
1898
1925
|
import fs9 from "node:fs";
|
|
1899
1926
|
import lodash2 from "lodash";
|
|
1900
|
-
import
|
|
1927
|
+
import path7 from "node:path";
|
|
1901
1928
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
1902
1929
|
var filesByExt, splitPath, getRelPath, urlToPath, isSubPath;
|
|
1903
1930
|
var init_path = __esm({
|
|
@@ -1912,45 +1939,45 @@ var init_path = __esm({
|
|
|
1912
1939
|
if (!Array.isArray(ext)) ext = [ext];
|
|
1913
1940
|
files.forEach((v) => {
|
|
1914
1941
|
if (v.isDirectory()) return;
|
|
1915
|
-
if (ext.includes(
|
|
1942
|
+
if (ext.includes(path7.extname(v.name))) {
|
|
1916
1943
|
if (returnType === "name") {
|
|
1917
1944
|
list4.push(v.name);
|
|
1918
1945
|
} else if (returnType === "rel") {
|
|
1919
|
-
const file =
|
|
1920
|
-
list4.push(
|
|
1946
|
+
const file = path7.resolve(filePath, v.name);
|
|
1947
|
+
list4.push(path7.relative(process.cwd(), file));
|
|
1921
1948
|
} else if (returnType === "abs") {
|
|
1922
|
-
list4.push(
|
|
1949
|
+
list4.push(path7.resolve(filePath, v.name));
|
|
1923
1950
|
}
|
|
1924
1951
|
}
|
|
1925
1952
|
});
|
|
1926
1953
|
return list4;
|
|
1927
1954
|
};
|
|
1928
1955
|
splitPath = (filePath) => {
|
|
1929
|
-
const dirname =
|
|
1930
|
-
const basename =
|
|
1956
|
+
const dirname = path7.dirname(filePath).replace(sep, "");
|
|
1957
|
+
const basename = path7.basename(filePath);
|
|
1931
1958
|
return { dirname, basename };
|
|
1932
1959
|
};
|
|
1933
1960
|
getRelPath = (filePath) => filePath.replace(/\\+/g, "/").replace(/\.+\/+|\/+$/g, "");
|
|
1934
1961
|
urlToPath = (url) => {
|
|
1935
1962
|
const filePath = fileURLToPath2(url);
|
|
1936
|
-
const rel =
|
|
1937
|
-
const upLevelsCount = rel.split(
|
|
1963
|
+
const rel = path7.relative(path7.dirname(filePath), process.cwd());
|
|
1964
|
+
const upLevelsCount = rel.split(path7.sep).length;
|
|
1938
1965
|
return lodash2.repeat("../", upLevelsCount);
|
|
1939
1966
|
};
|
|
1940
1967
|
isSubPath = (root, target, isAbs = true) => {
|
|
1941
1968
|
if (isAbs) {
|
|
1942
|
-
root =
|
|
1943
|
-
target =
|
|
1969
|
+
root = path7.resolve(root);
|
|
1970
|
+
target = path7.resolve(target);
|
|
1944
1971
|
}
|
|
1945
|
-
const relative =
|
|
1946
|
-
return relative && !relative.startsWith("..") && !
|
|
1972
|
+
const relative = path7.relative(root, target);
|
|
1973
|
+
return relative && !relative.startsWith("..") && !path7.isAbsolute(relative);
|
|
1947
1974
|
};
|
|
1948
1975
|
}
|
|
1949
1976
|
});
|
|
1950
1977
|
|
|
1951
1978
|
// src/plugin/list.ts
|
|
1952
1979
|
import fs10 from "node:fs";
|
|
1953
|
-
import
|
|
1980
|
+
import path8 from "node:path";
|
|
1954
1981
|
var cache8, getPlugins, getPluginsInfo, createPkg, getAppInfo, getGitInfo, getNpmInfo, isNpmPlugin, filterApp, filterGit, filterPkg;
|
|
1955
1982
|
var init_list = __esm({
|
|
1956
1983
|
"src/plugin/list.ts"() {
|
|
@@ -2005,17 +2032,17 @@ var init_list = __esm({
|
|
|
2005
2032
|
await Promise.allSettled(list4.map(async (v) => {
|
|
2006
2033
|
const [type, name] = v.split(":");
|
|
2007
2034
|
if (type === "app") {
|
|
2008
|
-
const file =
|
|
2035
|
+
const file = path8.join(pluginDir, name);
|
|
2009
2036
|
await getAppInfo(info, file, name, ext);
|
|
2010
2037
|
return;
|
|
2011
2038
|
}
|
|
2012
2039
|
if (type === "git" || type === "root") {
|
|
2013
|
-
const file = type === "root" ? process.cwd() :
|
|
2040
|
+
const file = type === "root" ? process.cwd() : path8.join(pluginDir, name);
|
|
2014
2041
|
await getGitInfo(info, file, name, ext);
|
|
2015
2042
|
return;
|
|
2016
2043
|
}
|
|
2017
2044
|
if (type === "npm") {
|
|
2018
|
-
const file =
|
|
2045
|
+
const file = path8.join(process.cwd(), "node_modules", name);
|
|
2019
2046
|
await getNpmInfo(info, file, name);
|
|
2020
2047
|
}
|
|
2021
2048
|
}));
|
|
@@ -2030,7 +2057,7 @@ var init_list = __esm({
|
|
|
2030
2057
|
dir,
|
|
2031
2058
|
id: -1,
|
|
2032
2059
|
get pkgPath() {
|
|
2033
|
-
const file =
|
|
2060
|
+
const file = path8.join(this.dir, "package.json");
|
|
2034
2061
|
if (!fs10.existsSync(file)) return "";
|
|
2035
2062
|
return file;
|
|
2036
2063
|
},
|
|
@@ -2045,7 +2072,7 @@ var init_list = __esm({
|
|
|
2045
2072
|
info.push(createPkg("app", name, dir, apps, [dir]));
|
|
2046
2073
|
};
|
|
2047
2074
|
getGitInfo = async (info, dir, name, ext) => {
|
|
2048
|
-
const pkg3 = await requireFile(
|
|
2075
|
+
const pkg3 = await requireFile(path8.join(dir, "package.json"));
|
|
2049
2076
|
if (!pkg3 || !pkg3.karin) {
|
|
2050
2077
|
info.push(createPkg("git", name, dir, [], []));
|
|
2051
2078
|
return;
|
|
@@ -2066,7 +2093,7 @@ var init_list = __esm({
|
|
|
2066
2093
|
pushApps(pkg3.karin.apps);
|
|
2067
2094
|
}
|
|
2068
2095
|
await Promise.allSettled(files.map(async (app2) => {
|
|
2069
|
-
const appPath =
|
|
2096
|
+
const appPath = path8.join(dir, app2);
|
|
2070
2097
|
if (!fs10.existsSync(appPath)) return;
|
|
2071
2098
|
apps.push(...filesByExt(appPath, ext, "abs"));
|
|
2072
2099
|
allApps.push(appPath);
|
|
@@ -2078,7 +2105,7 @@ var init_list = __esm({
|
|
|
2078
2105
|
const ext = ".js";
|
|
2079
2106
|
const apps = [];
|
|
2080
2107
|
const allApps = [];
|
|
2081
|
-
const pkg3 = await requireFile(
|
|
2108
|
+
const pkg3 = await requireFile(path8.join(dir, "package.json"));
|
|
2082
2109
|
if (!((_b = (_a = pkg3.karin) == null ? void 0 : _a.apps) == null ? void 0 : _b.length)) {
|
|
2083
2110
|
info.push(createPkg("npm", name, dir, [], []));
|
|
2084
2111
|
return;
|
|
@@ -2090,7 +2117,7 @@ var init_list = __esm({
|
|
|
2090
2117
|
files.push(...pkg3.karin.apps);
|
|
2091
2118
|
}
|
|
2092
2119
|
await Promise.allSettled(files.map(async (app2) => {
|
|
2093
|
-
const appPath =
|
|
2120
|
+
const appPath = path8.join(dir, app2);
|
|
2094
2121
|
if (!fs10.existsSync(appPath)) return;
|
|
2095
2122
|
apps.push(...filesByExt(appPath, ext, "abs"));
|
|
2096
2123
|
allApps.push(appPath);
|
|
@@ -2099,7 +2126,7 @@ var init_list = __esm({
|
|
|
2099
2126
|
};
|
|
2100
2127
|
isNpmPlugin = async (name) => {
|
|
2101
2128
|
try {
|
|
2102
|
-
const file =
|
|
2129
|
+
const file = path8.join(process.cwd(), "node_modules", name, "package.json");
|
|
2103
2130
|
const pkg3 = await requireFile(file);
|
|
2104
2131
|
return !!pkg3.karin;
|
|
2105
2132
|
} catch {
|
|
@@ -2120,12 +2147,12 @@ var init_list = __esm({
|
|
|
2120
2147
|
await Promise.all(files.map(async (v) => {
|
|
2121
2148
|
if (!v.isDirectory()) return;
|
|
2122
2149
|
if (!v.name.startsWith("karin-plugin-")) return;
|
|
2123
|
-
if (!fs10.existsSync(
|
|
2150
|
+
if (!fs10.existsSync(path8.join(pluginDir, v.name, "package.json"))) return;
|
|
2124
2151
|
list4.push(`git:${v.name}`);
|
|
2125
2152
|
}));
|
|
2126
2153
|
};
|
|
2127
2154
|
filterPkg = async (list4) => {
|
|
2128
|
-
const karinPkg = await requireFile(
|
|
2155
|
+
const karinPkg = await requireFile(path8.join(karinDir, "package.json"));
|
|
2129
2156
|
const exclude = [...Object.keys(karinPkg.dependencies || {}), ...Object.keys(karinPkg.devDependencies || {})];
|
|
2130
2157
|
const pkg3 = await requireFile("./package.json");
|
|
2131
2158
|
const dependencies = Object.keys(pkg3.dependencies || {}).filter((name) => !exclude.includes(name) && !name.startsWith("@types"));
|
|
@@ -2194,36 +2221,36 @@ var init_json = __esm({
|
|
|
2194
2221
|
"src/utils/fs/json.ts"() {
|
|
2195
2222
|
"use strict";
|
|
2196
2223
|
init_esm_shims();
|
|
2197
|
-
readJsonSync = (
|
|
2224
|
+
readJsonSync = (path17, isThrow = false) => {
|
|
2198
2225
|
try {
|
|
2199
|
-
const data = fs12.readFileSync(
|
|
2226
|
+
const data = fs12.readFileSync(path17, "utf8");
|
|
2200
2227
|
return JSON.parse(data);
|
|
2201
2228
|
} catch (error) {
|
|
2202
2229
|
if (isThrow) throw error;
|
|
2203
2230
|
return null;
|
|
2204
2231
|
}
|
|
2205
2232
|
};
|
|
2206
|
-
writeJsonSync = (
|
|
2233
|
+
writeJsonSync = (path17, data, isThrow = false) => {
|
|
2207
2234
|
try {
|
|
2208
|
-
fs12.writeFileSync(
|
|
2235
|
+
fs12.writeFileSync(path17, JSON.stringify(data, null, 2));
|
|
2209
2236
|
return true;
|
|
2210
2237
|
} catch (error) {
|
|
2211
2238
|
if (isThrow) throw error;
|
|
2212
2239
|
return false;
|
|
2213
2240
|
}
|
|
2214
2241
|
};
|
|
2215
|
-
readJson = async (
|
|
2242
|
+
readJson = async (path17, isThrow = false) => {
|
|
2216
2243
|
try {
|
|
2217
|
-
const data = await fs12.promises.readFile(
|
|
2244
|
+
const data = await fs12.promises.readFile(path17, "utf8");
|
|
2218
2245
|
return JSON.parse(data);
|
|
2219
2246
|
} catch (error) {
|
|
2220
2247
|
if (isThrow) throw error;
|
|
2221
2248
|
return null;
|
|
2222
2249
|
}
|
|
2223
2250
|
};
|
|
2224
|
-
writeJson = async (
|
|
2251
|
+
writeJson = async (path17, data, isThrow = false) => {
|
|
2225
2252
|
try {
|
|
2226
|
-
await fs12.promises.writeFile(
|
|
2253
|
+
await fs12.promises.writeFile(path17, JSON.stringify(data, null, 2));
|
|
2227
2254
|
return true;
|
|
2228
2255
|
} catch (error) {
|
|
2229
2256
|
if (isThrow) throw error;
|
|
@@ -2274,7 +2301,7 @@ var init_cache = __esm({
|
|
|
2274
2301
|
});
|
|
2275
2302
|
|
|
2276
2303
|
// src/utils/fs/pkg.ts
|
|
2277
|
-
import
|
|
2304
|
+
import path9 from "node:path";
|
|
2278
2305
|
import { existsSync as existsSync3 } from "node:fs";
|
|
2279
2306
|
import { createRequire } from "module";
|
|
2280
2307
|
var pkgRoot, getPluginInfo, isPlugin;
|
|
@@ -2294,15 +2321,15 @@ var init_pkg = __esm({
|
|
|
2294
2321
|
dir = __require.resolve(name);
|
|
2295
2322
|
}
|
|
2296
2323
|
try {
|
|
2297
|
-
if (existsSync3(
|
|
2298
|
-
return
|
|
2324
|
+
if (existsSync3(path9.join(dir, "package.json"))) {
|
|
2325
|
+
return path9.resolve(dir);
|
|
2299
2326
|
}
|
|
2300
2327
|
while (true) {
|
|
2301
|
-
dir =
|
|
2302
|
-
if (existsSync3(
|
|
2303
|
-
return
|
|
2328
|
+
dir = path9.dirname(dir);
|
|
2329
|
+
if (existsSync3(path9.join(dir, "package.json"))) {
|
|
2330
|
+
return path9.resolve(dir);
|
|
2304
2331
|
}
|
|
2305
|
-
if (dir ===
|
|
2332
|
+
if (dir === path9.dirname(dir)) {
|
|
2306
2333
|
throw new Error(`[common] \u672A\u627E\u5230\u5305${name}\u7684\u6839\u76EE\u5F55`);
|
|
2307
2334
|
}
|
|
2308
2335
|
}
|
|
@@ -2718,7 +2745,7 @@ __export(common_exports, {
|
|
|
2718
2745
|
writeYaml: () => write
|
|
2719
2746
|
});
|
|
2720
2747
|
import fs13 from "node:fs";
|
|
2721
|
-
import
|
|
2748
|
+
import path10 from "node:path";
|
|
2722
2749
|
import Axios, { AxiosError as AxiosError2 } from "axios";
|
|
2723
2750
|
var sleep, axios3, uptime2, formatTime2, updateYaml, getNpmPlugins, getPlugins2, getGitPlugins, mergeImage, getAbsPath, getImageSize, generateLayout, buildFilterComplex;
|
|
2724
2751
|
var init_common = __esm({
|
|
@@ -2790,13 +2817,13 @@ var init_common = __esm({
|
|
|
2790
2817
|
getGitPlugins = async (isPack = false) => getPlugins("git", isPack);
|
|
2791
2818
|
mergeImage = async (images, perRow = 3) => {
|
|
2792
2819
|
if (images.length < 2) throw Error("\u56FE\u7247\u6570\u91CF\u5FC5\u987B\u5927\u4E8E1");
|
|
2793
|
-
const root =
|
|
2794
|
-
const rootTemp =
|
|
2820
|
+
const root = path10.join(tempPath, "mergeImage");
|
|
2821
|
+
const rootTemp = path10.join(root, Date.now().toString());
|
|
2795
2822
|
fs13.mkdirSync(rootTemp, { recursive: true });
|
|
2796
2823
|
const files = getAbsPath(images, rootTemp);
|
|
2797
2824
|
const filterComplex = await buildFilterComplex(files, perRow);
|
|
2798
2825
|
const inputImages = files.map((file) => `-i "${file}"`).join(" ");
|
|
2799
|
-
const output =
|
|
2826
|
+
const output = path10.join(rootTemp, "output.png");
|
|
2800
2827
|
const ffmpegCmd = `${inputImages} -filter_complex "${filterComplex}" -map "[out]" ${output}`;
|
|
2801
2828
|
const result = await ffmpeg(ffmpegCmd);
|
|
2802
2829
|
if (!result.status) {
|
|
@@ -2815,13 +2842,13 @@ var init_common = __esm({
|
|
|
2815
2842
|
if (image2.startsWith("base64://")) {
|
|
2816
2843
|
const base642 = image2.replace(/^base64:\/\//, "");
|
|
2817
2844
|
const buffer2 = Buffer.from(base642, "base64");
|
|
2818
|
-
const file2 =
|
|
2845
|
+
const file2 = path10.join(root, `${index4}.png`);
|
|
2819
2846
|
fs13.writeFileSync(file2, buffer2);
|
|
2820
2847
|
files.push(file2);
|
|
2821
2848
|
return;
|
|
2822
2849
|
}
|
|
2823
2850
|
if (!fs13.existsSync(image2)) throw Error(`\u56FE\u7247\u8DEF\u5F84\u4E0D\u5B58\u5728: ${image2}`);
|
|
2824
|
-
const file =
|
|
2851
|
+
const file = path10.join(root, path10.basename(image2));
|
|
2825
2852
|
fs13.copyFileSync(image2, file);
|
|
2826
2853
|
files.push(file);
|
|
2827
2854
|
});
|
|
@@ -2871,8 +2898,8 @@ var init_level = __esm({
|
|
|
2871
2898
|
LevelDB = class extends Level {
|
|
2872
2899
|
id;
|
|
2873
2900
|
get;
|
|
2874
|
-
constructor(
|
|
2875
|
-
super(
|
|
2901
|
+
constructor(path17) {
|
|
2902
|
+
super(path17, { valueEncoding: "json" });
|
|
2876
2903
|
this.id = "Level";
|
|
2877
2904
|
this.get = super.get.bind(this);
|
|
2878
2905
|
}
|
|
@@ -3961,8 +3988,8 @@ var init_tools2 = __esm({
|
|
|
3961
3988
|
});
|
|
3962
3989
|
|
|
3963
3990
|
// src/plugin/watcher.ts
|
|
3964
|
-
import
|
|
3965
|
-
import
|
|
3991
|
+
import chokidar3 from "chokidar";
|
|
3992
|
+
import path11 from "node:path";
|
|
3966
3993
|
var WatcherPlugin;
|
|
3967
3994
|
var init_watcher = __esm({
|
|
3968
3995
|
"src/plugin/watcher.ts"() {
|
|
@@ -4001,12 +4028,12 @@ var init_watcher = __esm({
|
|
|
4001
4028
|
* 开始监听
|
|
4002
4029
|
*/
|
|
4003
4030
|
startWatch() {
|
|
4004
|
-
this.watcher =
|
|
4031
|
+
this.watcher = chokidar3.watch(Array.from(this.watchDirs), {
|
|
4005
4032
|
ignoreInitial: true,
|
|
4006
4033
|
ignored: /(^|[/\\])\../
|
|
4007
4034
|
});
|
|
4008
4035
|
this.watcher.on("add", (file) => this.handleFileChange(file, "add")).on("change", (file) => this.handleFileChange(file, "change")).on("unlink", (file) => this.handleFileChange(file, "unlink"));
|
|
4009
|
-
const relativePaths = Array.from(this.watchDirs).map((dir) =>
|
|
4036
|
+
const relativePaths = Array.from(this.watchDirs).map((dir) => path11.relative(process.cwd(), dir).replace(/\\/g, "/"));
|
|
4010
4037
|
logger.debug("\n[hmr] \u5F00\u59CB\u76D1\u542C\u6587\u4EF6\u5939:\n", relativePaths.join("\n"));
|
|
4011
4038
|
}
|
|
4012
4039
|
/**
|
|
@@ -4025,17 +4052,17 @@ var init_watcher = __esm({
|
|
|
4025
4052
|
* @param action 操作类型
|
|
4026
4053
|
*/
|
|
4027
4054
|
async handleFileChange(file, action) {
|
|
4028
|
-
const ext =
|
|
4055
|
+
const ext = path11.extname(file);
|
|
4029
4056
|
const exts = isTsx() ? [".ts", ".js"] : [".js"];
|
|
4030
4057
|
if (!exts.includes(ext)) return;
|
|
4031
|
-
const absPath2 =
|
|
4058
|
+
const absPath2 = path11.resolve(file);
|
|
4032
4059
|
const pkg3 = this.findPkgByFile(absPath2);
|
|
4033
4060
|
if (!pkg3) return;
|
|
4034
|
-
const relativePath =
|
|
4061
|
+
const relativePath = path11.relative(process.cwd(), file).replace(/\\/g, "/");
|
|
4035
4062
|
logger.debug(`[hmr][${pkg3.name}] \u6587\u4EF6${action}: ${relativePath}`);
|
|
4036
4063
|
if (action === "unlink") {
|
|
4037
4064
|
this.unloadPlugin(absPath2);
|
|
4038
|
-
logger.info(`[hmr][${pkg3.name}] \u5DF2\u5378\u8F7D: ${
|
|
4065
|
+
logger.info(`[hmr][${pkg3.name}] \u5DF2\u5378\u8F7D: ${path11.basename(file)}`);
|
|
4039
4066
|
return;
|
|
4040
4067
|
}
|
|
4041
4068
|
if (action === "change") {
|
|
@@ -4046,7 +4073,7 @@ var init_watcher = __esm({
|
|
|
4046
4073
|
this.loader.cachePlugin(result, pkg3, absPath2);
|
|
4047
4074
|
this.loader.sort();
|
|
4048
4075
|
const actionText = action === "add" ? "\u65B0\u589E\u63D2\u4EF6" : "\u91CD\u8F7D\u5B8C\u6210";
|
|
4049
|
-
logger.info(`[hmr][${pkg3.name}] ${actionText}: ${
|
|
4076
|
+
logger.info(`[hmr][${pkg3.name}] ${actionText}: ${path11.basename(file)}`);
|
|
4050
4077
|
} catch (error) {
|
|
4051
4078
|
logger.error(`[hmr][${pkg3.name}] \u52A0\u8F7D\u5931\u8D25:`, error);
|
|
4052
4079
|
}
|
|
@@ -4087,7 +4114,7 @@ __export(loader_exports, {
|
|
|
4087
4114
|
});
|
|
4088
4115
|
import fs14 from "node:fs";
|
|
4089
4116
|
import lodash5 from "lodash";
|
|
4090
|
-
import
|
|
4117
|
+
import path12 from "node:path";
|
|
4091
4118
|
import util2 from "node:util";
|
|
4092
4119
|
import schedule from "node-schedule";
|
|
4093
4120
|
var seq, LoaderPlugin;
|
|
@@ -4139,13 +4166,13 @@ var init_loader = __esm({
|
|
|
4139
4166
|
});
|
|
4140
4167
|
if (pkg3.type !== "app") {
|
|
4141
4168
|
if (isTsx() && ((_c = (_b = pkg3 == null ? void 0 : pkg3.pkgData) == null ? void 0 : _b.karin) == null ? void 0 : _c.main)) {
|
|
4142
|
-
const file =
|
|
4169
|
+
const file = path12.join(pkg3.dir, pkg3.pkgData.karin.main);
|
|
4143
4170
|
if (fs14.existsSync(file)) {
|
|
4144
4171
|
entryPromises.push(this.loaderMain(pkg3.name, file));
|
|
4145
4172
|
}
|
|
4146
4173
|
}
|
|
4147
4174
|
if ((_d = pkg3 == null ? void 0 : pkg3.pkgData) == null ? void 0 : _d.main) {
|
|
4148
|
-
const file =
|
|
4175
|
+
const file = path12.join(pkg3.dir, pkg3.pkgData.main);
|
|
4149
4176
|
if (fs14.existsSync(file)) {
|
|
4150
4177
|
entryPromises.push(this.loaderMain(pkg3.name, file));
|
|
4151
4178
|
}
|
|
@@ -4153,7 +4180,7 @@ var init_loader = __esm({
|
|
|
4153
4180
|
}
|
|
4154
4181
|
if (pkg3.type !== "app" && ((_f = (_e = pkg3 == null ? void 0 : pkg3.pkgData) == null ? void 0 : _e.karin) == null ? void 0 : _f.static)) {
|
|
4155
4182
|
const list5 = Array.isArray(pkg3.pkgData.karin.static) ? pkg3.pkgData.karin.static : [pkg3.pkgData.karin.static];
|
|
4156
|
-
cache9.static.push(...list5.map((file) =>
|
|
4183
|
+
cache9.static.push(...list5.map((file) => path12.resolve(pkg3.dir, file)));
|
|
4157
4184
|
}
|
|
4158
4185
|
}));
|
|
4159
4186
|
await Promise.all([...allPromises, ...entryPromises]);
|
|
@@ -4193,10 +4220,10 @@ var init_loader = __esm({
|
|
|
4193
4220
|
return {
|
|
4194
4221
|
absPath: app2,
|
|
4195
4222
|
get dirname() {
|
|
4196
|
-
return
|
|
4223
|
+
return path12.dirname(this.absPath);
|
|
4197
4224
|
},
|
|
4198
4225
|
get basename() {
|
|
4199
|
-
return
|
|
4226
|
+
return path12.basename(this.absPath);
|
|
4200
4227
|
},
|
|
4201
4228
|
type,
|
|
4202
4229
|
method,
|
|
@@ -4511,7 +4538,7 @@ var init_middleware = __esm({
|
|
|
4511
4538
|
});
|
|
4512
4539
|
|
|
4513
4540
|
// src/server/app.ts
|
|
4514
|
-
import
|
|
4541
|
+
import path13 from "node:path";
|
|
4515
4542
|
import express from "express";
|
|
4516
4543
|
import { createServer } from "node:http";
|
|
4517
4544
|
var app, server, listen;
|
|
@@ -4525,8 +4552,8 @@ var init_app = __esm({
|
|
|
4525
4552
|
app = express();
|
|
4526
4553
|
server = createServer(app);
|
|
4527
4554
|
app.use(authMiddleware);
|
|
4528
|
-
app.use("/web", express.static(
|
|
4529
|
-
app.use("/web/*", express.static(
|
|
4555
|
+
app.use("/web", express.static(path13.join(process.cwd(), "web")));
|
|
4556
|
+
app.use("/web/*", express.static(path13.join(process.cwd(), "web")));
|
|
4530
4557
|
app.use("/api/v1", router);
|
|
4531
4558
|
listen = (port2, host2) => {
|
|
4532
4559
|
server.listen(port2, host2, () => {
|
|
@@ -4611,7 +4638,7 @@ var init_ip = __esm({
|
|
|
4611
4638
|
|
|
4612
4639
|
// src/server/api/console.ts
|
|
4613
4640
|
import { promises as fs15 } from "node:fs";
|
|
4614
|
-
import
|
|
4641
|
+
import path14 from "node:path";
|
|
4615
4642
|
var ALLOWED_TYPES, MAX_FILE_SIZE, consoleRouter;
|
|
4616
4643
|
var init_console = __esm({
|
|
4617
4644
|
async "src/server/api/console.ts"() {
|
|
@@ -4648,7 +4675,7 @@ var init_console = __esm({
|
|
|
4648
4675
|
if (url.includes("..") || url.includes("~") || !url.match(/^[a-zA-Z0-9-_.]+$/)) {
|
|
4649
4676
|
return createForbiddenResponse(res, "\u975E\u6CD5\u8BF7\u6C42");
|
|
4650
4677
|
}
|
|
4651
|
-
const ext =
|
|
4678
|
+
const ext = path14.extname(url).toLowerCase();
|
|
4652
4679
|
if (!ALLOWED_TYPES[ext]) {
|
|
4653
4680
|
return createBadRequestResponse(res, "\u4E0D\u652F\u6301\u7684\u6587\u4EF6\u7C7B\u578B");
|
|
4654
4681
|
}
|
|
@@ -4666,7 +4693,7 @@ var init_console = __esm({
|
|
|
4666
4693
|
return createForbiddenResponse(res, "\u65E0\u6548\u7684 token");
|
|
4667
4694
|
}
|
|
4668
4695
|
}
|
|
4669
|
-
const file =
|
|
4696
|
+
const file = path14.join(consolePath, url);
|
|
4670
4697
|
try {
|
|
4671
4698
|
if (!file.startsWith(consolePath)) {
|
|
4672
4699
|
return createForbiddenResponse(res, "\u975E\u6CD5\u8BF7\u6C42");
|
|
@@ -5825,16 +5852,27 @@ var init_handler2 = __esm({
|
|
|
5825
5852
|
return true;
|
|
5826
5853
|
};
|
|
5827
5854
|
privateFilterEvent = (ctx3, config2, friend, cd) => {
|
|
5828
|
-
var _a, _b, _c, _d, _e, _f;
|
|
5855
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
5856
|
+
if (ctx3.isFriend) {
|
|
5857
|
+
if (!((_a = config2 == null ? void 0 : config2.user) == null ? void 0 : _a.enable)) {
|
|
5858
|
+
log(ctx3.userId, `\u5F53\u524D\u597D\u53CB\u4E8B\u4EF6\u672A\u542F\u7528: ${ctx3.eventId}`);
|
|
5859
|
+
return false;
|
|
5860
|
+
}
|
|
5861
|
+
} else {
|
|
5862
|
+
if (!((_b = config2 == null ? void 0 : config2.directs) == null ? void 0 : _b.enable)) {
|
|
5863
|
+
log(ctx3.userId, `\u5F53\u524D\u9891\u9053\u79C1\u4FE1\u4E8B\u4EF6\u672A\u542F\u7528: ${ctx3.eventId}`);
|
|
5864
|
+
return false;
|
|
5865
|
+
}
|
|
5866
|
+
}
|
|
5829
5867
|
if (!cd) {
|
|
5830
5868
|
log(ctx3.userId, `\u5F53\u524D\u5904\u4E8ECD\u4E2D: ${ctx3.eventId}`);
|
|
5831
5869
|
return false;
|
|
5832
5870
|
}
|
|
5833
|
-
if (((
|
|
5871
|
+
if (((_d = (_c = config2 == null ? void 0 : config2.user) == null ? void 0 : _c.enable_list) == null ? void 0 : _d.length) && !((_e = config2 == null ? void 0 : config2.user) == null ? void 0 : _e.enable_list.includes(ctx3.userId))) {
|
|
5834
5872
|
log(ctx3.userId, `\u7528\u6237\u672A\u5904\u4E8E\u767D\u540D\u5355: ${ctx3.eventId}`);
|
|
5835
5873
|
return false;
|
|
5836
5874
|
}
|
|
5837
|
-
if (((
|
|
5875
|
+
if (((_g = (_f = config2 == null ? void 0 : config2.user) == null ? void 0 : _f.disable_list) == null ? void 0 : _g.length) && ((_h = config2 == null ? void 0 : config2.user) == null ? void 0 : _h.disable_list.includes(ctx3.userId))) {
|
|
5838
5876
|
log(ctx3.userId, `\u7528\u6237\u5904\u4E8E\u9ED1\u540D\u5355: ${ctx3.eventId}`);
|
|
5839
5877
|
return false;
|
|
5840
5878
|
}
|
|
@@ -5877,63 +5915,74 @@ var init_handler2 = __esm({
|
|
|
5877
5915
|
return mode();
|
|
5878
5916
|
};
|
|
5879
5917
|
groupFilterEvent = (ctx3, config2, group, cd) => {
|
|
5880
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
|
|
5918
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D;
|
|
5919
|
+
if (ctx3.isGroup) {
|
|
5920
|
+
if (!((_a = config2 == null ? void 0 : config2.group) == null ? void 0 : _a.enable)) {
|
|
5921
|
+
log(ctx3.groupId, `\u5F53\u524D\u7FA4\u4E8B\u4EF6\u672A\u542F\u7528: ${ctx3.eventId}`);
|
|
5922
|
+
return false;
|
|
5923
|
+
}
|
|
5924
|
+
} else if (ctx3.isGuild) {
|
|
5925
|
+
if (!((_b = config2 == null ? void 0 : config2.guilds) == null ? void 0 : _b.enable)) {
|
|
5926
|
+
log(ctx3.guildId, `\u5F53\u524D\u9891\u9053\u4E8B\u4EF6\u672A\u542F\u7528: ${ctx3.eventId}`);
|
|
5927
|
+
return false;
|
|
5928
|
+
}
|
|
5929
|
+
}
|
|
5881
5930
|
if (!cd) {
|
|
5882
5931
|
log(ctx3.userId, `\u5F53\u524D\u5904\u4E8ECD\u4E2D: ${ctx3.eventId}`);
|
|
5883
5932
|
return false;
|
|
5884
5933
|
}
|
|
5885
|
-
if ((
|
|
5886
|
-
if (!((
|
|
5934
|
+
if ((_d = (_c = config2 == null ? void 0 : config2.user) == null ? void 0 : _c.enable_list) == null ? void 0 : _d.length) {
|
|
5935
|
+
if (!((_e = config2 == null ? void 0 : config2.user) == null ? void 0 : _e.enable_list.includes(ctx3.userId))) {
|
|
5887
5936
|
log(ctx3.userId, `\u7528\u6237\u672A\u5904\u4E8E\u767D\u540D\u5355: ${ctx3.eventId}`);
|
|
5888
5937
|
return false;
|
|
5889
5938
|
}
|
|
5890
5939
|
}
|
|
5891
|
-
if ((
|
|
5892
|
-
if ((
|
|
5940
|
+
if ((_g = (_f = config2 == null ? void 0 : config2.user) == null ? void 0 : _f.disable_list) == null ? void 0 : _g.length) {
|
|
5941
|
+
if ((_h = config2 == null ? void 0 : config2.user) == null ? void 0 : _h.disable_list.includes(ctx3.userId)) {
|
|
5893
5942
|
log(ctx3.userId, `\u7528\u6237\u5904\u4E8E\u9ED1\u540D\u5355: ${ctx3.eventId}`);
|
|
5894
5943
|
return false;
|
|
5895
5944
|
}
|
|
5896
5945
|
}
|
|
5897
5946
|
if (ctx3.isGroup) {
|
|
5898
|
-
if (((
|
|
5947
|
+
if (((_j = (_i = config2 == null ? void 0 : config2.group) == null ? void 0 : _i.enable_list) == null ? void 0 : _j.length) && !((_k = config2 == null ? void 0 : config2.group) == null ? void 0 : _k.enable_list.includes(ctx3.groupId))) {
|
|
5899
5948
|
log(ctx3.groupId, `\u7FA4\u672A\u5904\u4E8E\u767D\u540D\u5355: ${ctx3.eventId}`);
|
|
5900
5949
|
return false;
|
|
5901
5950
|
}
|
|
5902
|
-
if (((
|
|
5951
|
+
if (((_m = (_l = config2 == null ? void 0 : config2.group) == null ? void 0 : _l.disable_list) == null ? void 0 : _m.length) && ((_n = config2 == null ? void 0 : config2.group) == null ? void 0 : _n.disable_list.includes(ctx3.groupId))) {
|
|
5903
5952
|
log(ctx3.groupId, `\u7FA4\u5904\u4E8E\u9ED1\u540D\u5355: ${ctx3.eventId}`);
|
|
5904
5953
|
return false;
|
|
5905
5954
|
}
|
|
5906
|
-
if (((
|
|
5955
|
+
if (((_o = group.memberEnable) == null ? void 0 : _o.length) && !group.memberEnable.includes(ctx3.userId)) {
|
|
5907
5956
|
log(ctx3.userId, `\u7528\u6237\u672A\u5904\u4E8E\u7FA4\u6210\u5458\u767D\u540D\u5355: ${ctx3.eventId}`);
|
|
5908
5957
|
return false;
|
|
5909
5958
|
}
|
|
5910
|
-
if (((
|
|
5959
|
+
if (((_p = group.memberDisable) == null ? void 0 : _p.length) && group.memberDisable.includes(ctx3.userId)) {
|
|
5911
5960
|
log(ctx3.userId, `\u7528\u6237\u5904\u4E8E\u7FA4\u6210\u5458\u9ED1\u540D\u5355: ${ctx3.eventId}`);
|
|
5912
5961
|
return false;
|
|
5913
5962
|
}
|
|
5914
5963
|
}
|
|
5915
5964
|
if (ctx3.isGuild) {
|
|
5916
|
-
if (((
|
|
5965
|
+
if (((_r = (_q = config2 == null ? void 0 : config2.guilds) == null ? void 0 : _q.enable_list) == null ? void 0 : _r.length) && !((_s = config2 == null ? void 0 : config2.guilds) == null ? void 0 : _s.enable_list.includes(ctx3.guildId))) {
|
|
5917
5966
|
log(ctx3.guildId, `\u9891\u9053\u672A\u5904\u4E8E\u767D\u540D\u5355: ${ctx3.eventId}`);
|
|
5918
5967
|
return false;
|
|
5919
5968
|
}
|
|
5920
|
-
if (((
|
|
5969
|
+
if (((_u = (_t = config2 == null ? void 0 : config2.guilds) == null ? void 0 : _t.disable_list) == null ? void 0 : _u.length) && ((_v = config2 == null ? void 0 : config2.guilds) == null ? void 0 : _v.disable_list.includes(ctx3.guildId))) {
|
|
5921
5970
|
log(ctx3.guildId, `\u9891\u9053\u5904\u4E8E\u9ED1\u540D\u5355: ${ctx3.eventId}`);
|
|
5922
5971
|
return false;
|
|
5923
5972
|
}
|
|
5924
|
-
if (((
|
|
5973
|
+
if (((_x = (_w = config2 == null ? void 0 : config2.channels) == null ? void 0 : _w.enable_list) == null ? void 0 : _x.length) && !((_y = config2 == null ? void 0 : config2.channels) == null ? void 0 : _y.enable_list.includes(ctx3.channelId))) {
|
|
5925
5974
|
log(ctx3.channelId, `\u5B50\u9891\u9053\u672A\u5904\u4E8E\u767D\u540D\u5355: ${ctx3.eventId}`);
|
|
5926
5975
|
return false;
|
|
5927
5976
|
}
|
|
5928
|
-
if (((
|
|
5977
|
+
if (((_A = (_z = config2 == null ? void 0 : config2.channels) == null ? void 0 : _z.disable_list) == null ? void 0 : _A.length) && ((_B = config2 == null ? void 0 : config2.channels) == null ? void 0 : _B.disable_list.includes(ctx3.channelId))) {
|
|
5929
5978
|
log(ctx3.channelId, `\u5B50\u9891\u9053\u5904\u4E8E\u9ED1\u540D\u5355: ${ctx3.eventId}`);
|
|
5930
5979
|
return false;
|
|
5931
5980
|
}
|
|
5932
|
-
if (((
|
|
5981
|
+
if (((_C = group.memberEnable) == null ? void 0 : _C.length) && !group.memberEnable.includes(ctx3.userId)) {
|
|
5933
5982
|
log(ctx3.userId, `\u7528\u6237\u672A\u5904\u4E8E\u9891\u9053\u6210\u5458\u767D\u540D\u5355: ${ctx3.eventId}`);
|
|
5934
5983
|
return false;
|
|
5935
5984
|
}
|
|
5936
|
-
if (((
|
|
5985
|
+
if (((_D = group.memberDisable) == null ? void 0 : _D.length) && group.memberDisable.includes(ctx3.userId)) {
|
|
5937
5986
|
log(ctx3.userId, `\u7528\u6237\u5904\u4E8E\u9891\u9053\u6210\u5458\u9ED1\u540D\u5355: ${ctx3.eventId}`);
|
|
5938
5987
|
return false;
|
|
5939
5988
|
}
|
|
@@ -8447,7 +8496,7 @@ var init_event = __esm({
|
|
|
8447
8496
|
|
|
8448
8497
|
// src/adapter/input/index.ts
|
|
8449
8498
|
import fs16 from "node:fs";
|
|
8450
|
-
import
|
|
8499
|
+
import path15 from "node:path";
|
|
8451
8500
|
var index2, botID, AdapterConsole, adapter2;
|
|
8452
8501
|
var init_input = __esm({
|
|
8453
8502
|
async "src/adapter/input/index.ts"() {
|
|
@@ -8467,7 +8516,10 @@ var init_input = __esm({
|
|
|
8467
8516
|
AdapterConsole = class extends AdapterBase {
|
|
8468
8517
|
constructor() {
|
|
8469
8518
|
super();
|
|
8470
|
-
listeners.on(
|
|
8519
|
+
listeners.on(
|
|
8520
|
+
"karin:adapter:open",
|
|
8521
|
+
() => process.stdin.on("data", (data) => this.createEvent(data))
|
|
8522
|
+
);
|
|
8471
8523
|
listeners.on("karin:adapter:close", () => process.stdin.removeAllListeners("data"));
|
|
8472
8524
|
this.adapter.name = "@karinjs/console";
|
|
8473
8525
|
this.adapter.communication = "other";
|
|
@@ -8484,10 +8536,22 @@ var init_input = __esm({
|
|
|
8484
8536
|
get selfId() {
|
|
8485
8537
|
return this.account.selfId;
|
|
8486
8538
|
}
|
|
8487
|
-
createEvent(data) {
|
|
8539
|
+
async createEvent(data) {
|
|
8488
8540
|
const text2 = data.toString().trim();
|
|
8489
8541
|
const seq2 = Math.floor(Math.random() * 1e9);
|
|
8490
8542
|
const time2 = Date.now();
|
|
8543
|
+
if (text2.startsWith("log")) {
|
|
8544
|
+
const level2 = text2.replace(/^log/, "").trim();
|
|
8545
|
+
if (level2) {
|
|
8546
|
+
const list4 = ["trace", "debug", "info", "warn", "error", "fatal"];
|
|
8547
|
+
if (list4.includes(level2)) {
|
|
8548
|
+
const { updateLevel: updateLevel2 } = await init_config().then(() => config_exports);
|
|
8549
|
+
updateLevel2(level2);
|
|
8550
|
+
logger.info(`\u65E5\u5FD7\u7B49\u7EA7\u5DF2\u66F4\u65B0\u4E3A: ${level2}`);
|
|
8551
|
+
return;
|
|
8552
|
+
}
|
|
8553
|
+
}
|
|
8554
|
+
}
|
|
8491
8555
|
if (text2.startsWith("group")) {
|
|
8492
8556
|
const contact4 = contactGroup("10010");
|
|
8493
8557
|
createGroupMessage({
|
|
@@ -8557,7 +8621,7 @@ var init_input = __esm({
|
|
|
8557
8621
|
async getUrl(data, ext) {
|
|
8558
8622
|
const cfg = adapter();
|
|
8559
8623
|
const name = (++index2).toString();
|
|
8560
|
-
const file =
|
|
8624
|
+
const file = path15.join(consolePath, `${name}${ext}`);
|
|
8561
8625
|
await fs16.promises.writeFile(file, await buffer(data));
|
|
8562
8626
|
if (cfg.console.isLocal) {
|
|
8563
8627
|
return `http://127.0.0.1:${process.env.HTTP_PORT}/console/${name}${ext}`;
|
|
@@ -8702,8 +8766,8 @@ var init_cache2 = __esm({
|
|
|
8702
8766
|
|
|
8703
8767
|
// src/adapter/render/admin/template.ts
|
|
8704
8768
|
import fs17 from "node:fs";
|
|
8705
|
-
import
|
|
8706
|
-
import
|
|
8769
|
+
import path16 from "node:path";
|
|
8770
|
+
import chokidar4 from "chokidar";
|
|
8707
8771
|
import template from "art-template";
|
|
8708
8772
|
var cache11, watcherCache, renderTpl, getCacheData, getOutputPath, watch2;
|
|
8709
8773
|
var init_template = __esm({
|
|
@@ -8719,7 +8783,7 @@ var init_template = __esm({
|
|
|
8719
8783
|
if (options.file.startsWith("http")) {
|
|
8720
8784
|
throw TypeError("\u4ED6\u55B5\u7684 \u4E0D\u4F1A\u771F\u7684\u6709\u7B28\u6BD4\u4F20\u4E2Ahttp\u6765\u5F53\u505A\u6A21\u677F\u5427...");
|
|
8721
8785
|
}
|
|
8722
|
-
const file =
|
|
8786
|
+
const file = path16.resolve(options.file);
|
|
8723
8787
|
const tplData = getCacheData(file);
|
|
8724
8788
|
const renderData = template.render(tplData, options.data);
|
|
8725
8789
|
const outputPath = getOutputPath(options.file, renderData, options.name);
|
|
@@ -8746,10 +8810,10 @@ var init_template = __esm({
|
|
|
8746
8810
|
return tplData;
|
|
8747
8811
|
};
|
|
8748
8812
|
getOutputPath = (file, data, name) => {
|
|
8749
|
-
const extname =
|
|
8750
|
-
const basename =
|
|
8751
|
-
const fileDir =
|
|
8752
|
-
const filePath =
|
|
8813
|
+
const extname = path16.extname(file);
|
|
8814
|
+
const basename = path16.basename(file, extname);
|
|
8815
|
+
const fileDir = path16.join(htmlPath, name || "render");
|
|
8816
|
+
const filePath = path16.join(fileDir, `${basename}-${Date.now()}${extname}`);
|
|
8753
8817
|
existToMkdirSync(fileDir);
|
|
8754
8818
|
fs17.writeFileSync(filePath, data);
|
|
8755
8819
|
return filePath;
|
|
@@ -8757,7 +8821,7 @@ var init_template = __esm({
|
|
|
8757
8821
|
watch2 = async (file, data) => {
|
|
8758
8822
|
cache11.set(file, data);
|
|
8759
8823
|
if (watcherCache.has(file)) return;
|
|
8760
|
-
const watcher =
|
|
8824
|
+
const watcher = chokidar4.watch(file);
|
|
8761
8825
|
watcherCache.set(file, watcher);
|
|
8762
8826
|
watcher.on("change", () => {
|
|
8763
8827
|
cache11.set(file, fs17.readFileSync(file, "utf-8"));
|
|
@@ -10201,11 +10265,11 @@ var checkGitPluginUpdate = async (filePath, time2 = 120) => {
|
|
|
10201
10265
|
}
|
|
10202
10266
|
};
|
|
10203
10267
|
var getCommit = async (options) => {
|
|
10204
|
-
const { path:
|
|
10268
|
+
const { path: path17, count: count3 = 1, hash, branch } = options;
|
|
10205
10269
|
let cmd = `git log -${count3} --format="[%ad]%s %n" --date="format:%m-%d %H:%M"`;
|
|
10206
10270
|
if (hash) cmd = `git log ${hash}..HEAD --format="[%ad] %s %n" --date="format:%m-%d %H:%M"`;
|
|
10207
10271
|
if (branch) cmd = `git log -${count3} ${branch} --format="[%ad] %s %n" --date="format:%m-%d %H:%M"`;
|
|
10208
|
-
const { stdout, error } = await exec(cmd, { cwd:
|
|
10272
|
+
const { stdout, error } = await exec(cmd, { cwd: path17 });
|
|
10209
10273
|
if (error) {
|
|
10210
10274
|
throw error;
|
|
10211
10275
|
}
|