koishi-plugin-kkk 1.0.6 → 1.0.7

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,16 @@
1
1
  # 更新日志
2
2
 
3
+ ## 1.0.7
4
+
5
+ ### 修复
6
+ - **面板报「加载配置失败 / 鉴权失败: 缺少authorization」**:面板自己的登录 token 存在服务端内存里,
7
+ Koishi 一重启就失效,而自动登录脚本看到 localStorage 里已经有 token 就跳过登录,
8
+ 于是一直拿着废 token 请求、所有接口 401。现在:
9
+ - 每次打开面板都会重新换一个新的 token(不再因为 localStorage 有值就跳过);
10
+ - 接口鉴权同时接受「控制台换来的面板 cookie」,即使前端 token 过期也能正常读写配置。
11
+ - 1.0.6 引入的登录校验配合这次修复才算完整:现在(装了 auth 插件时)未登录打不开面板、
12
+ 登录后配置能正常加载与保存。
13
+
3
14
  ## 1.0.6
4
15
 
5
16
  ### 变更
package/lib/webui.js CHANGED
@@ -78,7 +78,8 @@ function registerWebUi({ ctx, config, rawConfig, logger, pluginRoot }) {
78
78
  // 面板把登录态存在 localStorage 的 accessToken / userId / refreshToken 三个键里,
79
79
  // 登录页只是个表单壳子 —— 与其去点 DOM(React 受控组件很脆),不如直接调登录接口把凭据写进去再刷新。
80
80
  try {
81
- if (localStorage.getItem('accessToken')) return;
81
+ // 每次都重新换一次:面板自己的 token 存在服务端内存里,Koishi 重启就失效,
82
+ // 之前这里看到 localStorage 有值就直接 return,结果一直拿着废 token 请求,全部 401。
82
83
  // 防呆:万一接口一直不给凭据,也别在这里无限刷新
83
84
  if (sessionStorage.getItem('kkk-autologin') === '1') return;
84
85
  sessionStorage.setItem('kkk-autologin', '1');
@@ -249,6 +250,10 @@ function registerWebUi({ ctx, config, rawConfig, logger, pluginRoot }) {
249
250
  const authed = (request) => {
250
251
  if (!authRequired())
251
252
  return true;
253
+ // 面板 cookie(控制台换来的)本身就是授权凭据,接口请求直接用账号密码也不用再走一遍
254
+ const panelCookie = new RegExp(COOKIE_NAME + '_panel=([0-9a-f]+)').exec(String(request?.headers?.cookie || ''));
255
+ if (panelCookie && panelTokenValid(panelCookie[1]))
256
+ return true;
252
257
  const header = String(request?.headers?.authorization || request?.headers?.['x-access-token'] || '');
253
258
  if (header && tokens.has(header.replace(/^Bearer\s+/i, '')))
254
259
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-kkk",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "抖音 / B站 / 快手 / 小红书 视频解析与动态推送,带 QQ 交互面板与弹幕烧录(karin-plugin-kkk 的 Koishi 移植版)",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
package/src/webui.ts CHANGED
@@ -86,7 +86,8 @@ export function registerWebUi ({ ctx, config, rawConfig, logger, pluginRoot }: W
86
86
  // 面板把登录态存在 localStorage 的 accessToken / userId / refreshToken 三个键里,
87
87
  // 登录页只是个表单壳子 —— 与其去点 DOM(React 受控组件很脆),不如直接调登录接口把凭据写进去再刷新。
88
88
  try {
89
- if (localStorage.getItem('accessToken')) return;
89
+ // 每次都重新换一次:面板自己的 token 存在服务端内存里,Koishi 重启就失效,
90
+ // 之前这里看到 localStorage 有值就直接 return,结果一直拿着废 token 请求,全部 401。
90
91
  // 防呆:万一接口一直不给凭据,也别在这里无限刷新
91
92
  if (sessionStorage.getItem('kkk-autologin') === '1') return;
92
93
  sessionStorage.setItem('kkk-autologin', '1');
@@ -256,6 +257,9 @@ export function registerWebUi ({ ctx, config, rawConfig, logger, pluginRoot }: W
256
257
 
257
258
  const authed = (request: any): boolean => {
258
259
  if (!authRequired()) return true
260
+ // 面板 cookie(控制台换来的)本身就是授权凭据,接口请求直接用账号密码也不用再走一遍
261
+ const panelCookie = new RegExp(COOKIE_NAME + '_panel=([0-9a-f]+)').exec(String(request?.headers?.cookie || ''))
262
+ if (panelCookie && panelTokenValid(panelCookie[1])) return true
259
263
  const header = String(request?.headers?.authorization || request?.headers?.['x-access-token'] || '')
260
264
  if (header && tokens.has(header.replace(/^Bearer\s+/i, ''))) return true
261
265
  const cookie = String(request?.headers?.cookie || '')