koishi-plugin-kkk 1.0.0 → 1.0.1

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # 更新日志
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### 修复
6
+ - 生产环境下 `/kkk` 配置面板报「assets/web/index.html 缺失」:插件根目录不再只按 `lib/` 的位置推断,
7
+ 改为从入口所在目录逐级向上找带 `assets/web/index.html` 的那一层(并兜底按包名解析、cwd / cwd/node_modules),
8
+ 启动日志里会打印解析结果,找不到时会给出警告。
9
+ - 配置面板不再强制登录:生产环境装了 auth 插件时,面板原本要求先登录 Koishi 控制台,现在默认免登录;
10
+ 需要恢复登录校验时把配置项 `webUiAuth` 打开即可。
11
+
3
12
  ## 1.0.0
4
13
 
5
14
  首个公开版本:**karin-plugin-kkk 的 Koishi 移植版**,把上游的解析 / 推送 / 面板能力完整搬到 Koishi 生态。
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="./assets/readme/banner-d-render-gallery.svg" width="100%" alt="koishi-plugin-kkk 的视频详情、抖音评论、B站动态推送和解析统计动画成果墙">
2
+ <img src="./banner-d-render-gallery.svg" width="100%" alt="koishi-plugin-kkk 的视频详情、抖音评论、B站动态推送和解析统计动画成果墙">
3
3
  </p>
4
4
 
5
5
  <p align="center">
package/lib/index.js CHANGED
@@ -60,8 +60,42 @@ const webui_1 = require("./webui");
60
60
  const configBridge_1 = require("./configBridge");
61
61
  const QqCardResolve_1 = require("./karin/module/utils/QqCardResolve");
62
62
  const schema_1 = require("./schema");
63
- /** 插件根目录(编译产物在 lib/ 下,向上一级即包根) */
64
- const pluginRootDir = node_path_1.default.resolve(__dirname, '..');
63
+ /**
64
+ * 插件根目录。
65
+ *
66
+ * 通常编译产物在 `lib/index.js`,向上一级就是包根;但生产环境不一定按这个位置加载
67
+ * (打包 / 转译缓存 / pnpm 的不同布局 / 直接跑源码都会让 `__dirname` 落到别处),
68
+ * 一旦猜错,`/kkk` 面板就会报「assets/web/index.html 缺失」。
69
+ *
70
+ * 所以这里从 `__dirname` 逐级向上找,直到找到带 `assets/web/index.html` 的那一层,
71
+ * 再兜底试「按包名解析」和「cwd / cwd/node_modules」。
72
+ */
73
+ function resolvePluginRoot() {
74
+ const marker = node_path_1.default.join('assets', 'web', 'index.html');
75
+ const candidates = [];
76
+ let dir = __dirname;
77
+ for (let i = 0; i < 6; i++) {
78
+ candidates.push(dir);
79
+ const parent = node_path_1.default.dirname(dir);
80
+ if (parent === dir)
81
+ break;
82
+ dir = parent;
83
+ }
84
+ try {
85
+ candidates.push(node_path_1.default.dirname(require.resolve('koishi-plugin-kkk/package.json')));
86
+ }
87
+ catch { /* 本地链接安装时解析不到,正常 */ }
88
+ candidates.push(process.cwd(), node_path_1.default.join(process.cwd(), 'node_modules', 'koishi-plugin-kkk'));
89
+ for (const candidate of candidates) {
90
+ try {
91
+ if (node_fs_1.default.existsSync(node_path_1.default.join(candidate, marker)))
92
+ return candidate;
93
+ }
94
+ catch { /* 权限之类的问题跳过 */ }
95
+ }
96
+ return node_path_1.default.resolve(__dirname, '..');
97
+ }
98
+ const pluginRootDir = resolvePluginRoot();
65
99
  /**
66
100
  * 网络兜底:优先 IPv4。
67
101
  *
@@ -98,7 +132,7 @@ exports.inject = {
98
132
  * 这里能改的项会被写回数据目录的 config.json(见 configBridge),在那之前 config.json 仍是权威来源。
99
133
  */
100
134
  /** 摊平后由「Koishi 原生设置」分组提供的字段 */
101
- const NATIVE_KEYS = ['masters', 'dataPath', 'debug', 'autoParse'];
135
+ const NATIVE_KEYS = ['masters', 'dataPath', 'debug', 'autoParse', 'webUiAuth'];
102
136
  exports.Config = koishi_1.Schema.intersect([
103
137
  koishi_1.Schema.object({
104
138
  webuiGuide: koishi_1.Schema.const('').description('**QQ 相关的开关都在下面的「QQ 适配器」分组里**(解析面板、画质档、图片切片、番剧选集表格、卡片识别)。' +
@@ -109,6 +143,7 @@ exports.Config = koishi_1.Schema.intersect([
109
143
  dataPath: koishi_1.Schema.string().default('data').description('数据目录:配置、数据库、临时文件都放在这里'),
110
144
  debug: koishi_1.Schema.boolean().default(false).description('在日志里输出调试信息,排查问题时才需要打开'),
111
145
  autoParse: koishi_1.Schema.boolean().default(true).description('群里有人发链接(或回复一条带链接的消息)就自动解析,不用打指令'),
146
+ webUiAuth: koishi_1.Schema.boolean().default(false).description('配置面板 /kkk 是否要求先登录 Koishi 控制台。默认关(免登录,打开就能改配置);装了 auth 插件且希望面板也走登录时再打开'),
112
147
  }).collapse().description('Koishi 原生设置(一般不用改,已折叠)'),
113
148
  }),
114
149
  koishi_1.Schema.object({
@@ -612,6 +647,10 @@ function registerCommands(ctx, logger, autoParse) {
612
647
  async function apply(ctx, rawConfig) {
613
648
  const logger = ctx.logger('kkk');
614
649
  (0, logger_1.setLogger)(logger);
650
+ {
651
+ const ok = node_fs_1.default.existsSync(node_path_1.default.join(pluginRootDir, 'assets', 'web', 'index.html'));
652
+ logger.info('[kkk] 插件根目录: ' + pluginRootDir + (ok ? '' : '(警告:这里没有 assets/web/index.html,/kkk 面板会打不开)'));
653
+ }
615
654
  /**
616
655
  * 控制台表单把选项分成两个折叠组(「QQ 适配器」和「Koishi 原生设置」),
617
656
  * 这里统一摊平回顶层 —— 代码里照旧读 config.qqPanel / config.sliceImageOnDemand 等。
package/lib/webui.js CHANGED
@@ -98,8 +98,13 @@ function registerWebUi({ ctx, config, rawConfig, logger, pluginRoot }) {
98
98
  return Buffer.from(text.includes('</body>') ? text.replace('</body>', autoLoginScript + '</body>') : text + autoLoginScript);
99
99
  };
100
100
  /* ---------------- 登录策略 ---------------- */
101
- /** 只有启用 auth 插件才需要登录;当前部署是关的 → 免登录 */
102
- const authRequired = () => !!ctx.get?.('auth');
101
+ /**
102
+ * 面板(/kkk)是否需要登录。
103
+ *
104
+ * 默认**免登录**:装了 auth 插件的生产环境也会直接进界面(否则用户要先登控制台才能改配置,很别扭)。
105
+ * 要恢复成「必须登录控制台」,把配置里的 `webUiAuth` 打开即可。
106
+ */
107
+ const authRequired = () => config?.webUiAuth === true;
103
108
  /** 控制台登录态:auth 插件的 cookie 形如 name=id:token,用它查 token 表 */
104
109
  const consoleAuthed = async (request) => {
105
110
  if (!authRequired())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-kkk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "抖音 / B站 / 快手 / 小红书 视频解析与动态推送,带 QQ 交互面板与弹幕烧录(karin-plugin-kkk 的 Koishi 移植版)",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -51,9 +51,9 @@
51
51
  "koishi": "^4.18.7"
52
52
  },
53
53
  "dependencies": {
54
+ "@icons-pack/react-simple-icons": "^13.15.1",
54
55
  "@ikenxuan/amagi": "6.6.0",
55
56
  "@ikenxuan/qrcode": "1.5.0",
56
- "@icons-pack/react-simple-icons": "^13.15.1",
57
57
  "@outpacelabs/avatars": "0.6.0",
58
58
  "@phosphor-icons/react": "^2.1.10",
59
59
  "@thesvg/icons": "^3.3.7",
package/src/index.ts CHANGED
@@ -23,8 +23,40 @@ import { applyUpstreamOverrides } from './configBridge'
23
23
  import { resolveQqCardContent } from './karin/module/utils/QqCardResolve'
24
24
  import { buildUpstreamSchema } from './schema'
25
25
 
26
- /** 插件根目录(编译产物在 lib/ 下,向上一级即包根) */
27
- const pluginRootDir = path.resolve(__dirname, '..')
26
+ /**
27
+ * 插件根目录。
28
+ *
29
+ * 通常编译产物在 `lib/index.js`,向上一级就是包根;但生产环境不一定按这个位置加载
30
+ * (打包 / 转译缓存 / pnpm 的不同布局 / 直接跑源码都会让 `__dirname` 落到别处),
31
+ * 一旦猜错,`/kkk` 面板就会报「assets/web/index.html 缺失」。
32
+ *
33
+ * 所以这里从 `__dirname` 逐级向上找,直到找到带 `assets/web/index.html` 的那一层,
34
+ * 再兜底试「按包名解析」和「cwd / cwd/node_modules」。
35
+ */
36
+ function resolvePluginRoot (): string {
37
+ const marker = path.join('assets', 'web', 'index.html')
38
+ const candidates: string[] = []
39
+ let dir = __dirname
40
+ for (let i = 0; i < 6; i++) {
41
+ candidates.push(dir)
42
+ const parent = path.dirname(dir)
43
+ if (parent === dir) break
44
+ dir = parent
45
+ }
46
+ try {
47
+ candidates.push(path.dirname(require.resolve('koishi-plugin-kkk/package.json')))
48
+ } catch { /* 本地链接安装时解析不到,正常 */ }
49
+ candidates.push(process.cwd(), path.join(process.cwd(), 'node_modules', 'koishi-plugin-kkk'))
50
+
51
+ for (const candidate of candidates) {
52
+ try {
53
+ if (fs.existsSync(path.join(candidate, marker))) return candidate
54
+ } catch { /* 权限之类的问题跳过 */ }
55
+ }
56
+ return path.resolve(__dirname, '..')
57
+ }
58
+
59
+ const pluginRootDir = resolvePluginRoot()
28
60
 
29
61
  /**
30
62
  * 网络兜底:优先 IPv4。
@@ -63,6 +95,8 @@ export interface Config {
63
95
  debug: boolean
64
96
  /** 消息里的链接自动解析 */
65
97
  autoParse: boolean
98
+ /** 配置面板(/kkk)是否要求先登录 Koishi 控制台(默认关,即免登录) */
99
+ webUiAuth: boolean
66
100
  /** QQ 平台解析前先发交互面板(Markdown + 按钮)让用户选解析内容和画质 */
67
101
  qqPanel: boolean
68
102
  /** QQ 面板里隐藏超过该体积(MB)的画质按钮 */
@@ -91,7 +125,7 @@ export interface Config {
91
125
  * 这里能改的项会被写回数据目录的 config.json(见 configBridge),在那之前 config.json 仍是权威来源。
92
126
  */
93
127
  /** 摊平后由「Koishi 原生设置」分组提供的字段 */
94
- const NATIVE_KEYS = ['masters', 'dataPath', 'debug', 'autoParse']
128
+ const NATIVE_KEYS = ['masters', 'dataPath', 'debug', 'autoParse', 'webUiAuth']
95
129
 
96
130
  export const Config: Schema<Config> = Schema.intersect([
97
131
  Schema.object({
@@ -105,6 +139,7 @@ export const Config: Schema<Config> = Schema.intersect([
105
139
  dataPath: Schema.string().default('data').description('数据目录:配置、数据库、临时文件都放在这里'),
106
140
  debug: Schema.boolean().default(false).description('在日志里输出调试信息,排查问题时才需要打开'),
107
141
  autoParse: Schema.boolean().default(true).description('群里有人发链接(或回复一条带链接的消息)就自动解析,不用打指令'),
142
+ webUiAuth: Schema.boolean().default(false).description('配置面板 /kkk 是否要求先登录 Koishi 控制台。默认关(免登录,打开就能改配置);装了 auth 插件且希望面板也走登录时再打开'),
108
143
  }).collapse().description('Koishi 原生设置(一般不用改,已折叠)'),
109
144
  }),
110
145
  Schema.object({
@@ -612,6 +647,10 @@ function registerCommands (
612
647
  export async function apply (ctx: Context, rawConfig: Config) {
613
648
  const logger = ctx.logger('kkk')
614
649
  setLogger(logger)
650
+ {
651
+ const ok = fs.existsSync(path.join(pluginRootDir, 'assets', 'web', 'index.html'))
652
+ logger.info('[kkk] 插件根目录: ' + pluginRootDir + (ok ? '' : '(警告:这里没有 assets/web/index.html,/kkk 面板会打不开)'))
653
+ }
615
654
 
616
655
  /**
617
656
  * 控制台表单把选项分成两个折叠组(「QQ 适配器」和「Koishi 原生设置」),
package/src/webui.ts CHANGED
@@ -107,8 +107,13 @@ export function registerWebUi ({ ctx, config, rawConfig, logger, pluginRoot }: W
107
107
 
108
108
  /* ---------------- 登录策略 ---------------- */
109
109
 
110
- /** 只有启用 auth 插件才需要登录;当前部署是关的 → 免登录 */
111
- const authRequired = () => !!(ctx as any).get?.('auth')
110
+ /**
111
+ * 面板(/kkk)是否需要登录。
112
+ *
113
+ * 默认**免登录**:装了 auth 插件的生产环境也会直接进界面(否则用户要先登控制台才能改配置,很别扭)。
114
+ * 要恢复成「必须登录控制台」,把配置里的 `webUiAuth` 打开即可。
115
+ */
116
+ const authRequired = () => (config as any)?.webUiAuth === true
112
117
 
113
118
  /** 控制台登录态:auth 插件的 cookie 形如 name=id:token,用它查 token 表 */
114
119
  const consoleAuthed = async (request: any): Promise<boolean> => {