@fengye_nobug/dsh-qq-bot 0.2.5 → 0.2.6
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 +5 -0
- package/README.md +25 -21
- package/client/client.js +1 -1
- package/cordis.patch.yml +6 -3
- package/index.js +2 -0
- package/package.json +1 -1
- package/updates.js +496 -45
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v0.2.6 — 2026-10-30
|
|
4
|
+
|
|
5
|
+
- **一键更新之后,Cordis 按实际装上的包名挂 `qq-bridge`**:npm 包是 `@fengye_nobug/dsh-qq-bot`。v0.2.5 自带的 `cordis.patch.yml` 仍写 `name: dsh-qq-bot`。Cordis 按这个名字去加载,无作用域包并不存在,插件 id `qq-bridge` 不会挂上,`/api/qq-bridge/settings` 就是 HTTP 404,设置页显示本机接口不可用。现在插件自带的补丁把 `name` 写成 `@fengye_nobug/dsh-qq-bot`。安装成功后,还会看 profile 的 `cordis.patch.yml`、`$DSH_HOME/cordis.patch.yml`(这份文件里有 `qq-bridge` 才改),以及已经装进 profile 的插件补丁。这三处里 `qq-bridge` 的 `name` 如果还是 `dsh-qq-bot` 或 `dsh-qq-bridge`,就改成磁盘上 `package.json` 的包名。别的插件不动,`config` 里的设置不动。界面显示名和消息来源仍是 `dsh-qq-bot`,Cordis id 仍是 `qq-bridge`。从 0.2.5 点「更新」时,跑的仍是 0.2.5 里的安装程序,profile 里手写的旧 `name` 要先改成 `@fengye_nobug/dsh-qq-bot` 再重启;这一版自己跑一键更新时会改。
|
|
6
|
+
- **一键更新卡住时会停掉安装进程**:`dsh plugin add` 或它拉起的 `pnpm add` 超过三分钟没有结束,会停掉这一组进程,并用白话说明,不带路径和堆栈。profile 里的 `.plugin-manager/run.json` 只在记录的进程已经不在、或记录读不懂时删掉;进程还在就不删,也不会再开第二个安装。超时之后如果磁盘上已经是这次要装的版本,仍把 `qq-bridge` 的 `name` 改成实际包名,但不会自动重启,需要自己重启 dsh-web,设置页才会出来。没有确认装上时,可以再点一次「更新」。
|
|
7
|
+
|
|
3
8
|
## v0.2.5 — 2026-10-30
|
|
4
9
|
|
|
5
10
|
- **设置卡片可以一键更新**:有新正式版时出现「更新到 vX.Y.Z」。点下去才安装,并重启面板。优先执行 `dsh plugin --profile web add @fengye_nobug/dsh-qq-bot@版本`,走本机 npm / pnpm 已经配置的 registry。插件不写死镜像地址。registry 里找不到这个版本时,改从 GitHub 下载官方源码包(先 github.com,连不上再试同一标签的 codeload.github.com),不走第三方镜像。v0.2.3 及更早标签里的 `package.json` 仍是无作用域名,这种源码包仍然能装。装完提示刷新页面,登录口令可能会变。现有设置还在,不改 NapCat。已经是最新时没有这个按钮。不会安装更旧的版本,也不装草稿和预发布。连不上、安装失败、没能重启,都用白话说明。
|
package/README.md
CHANGED
|
@@ -8,22 +8,22 @@
|
|
|
8
8
|
|
|
9
9
|
本仓库 fork 自 [sj244/dsh-qq-bridge](https://github.com/sj244/dsh-qq-bridge)。上游许可证为 MIT,版权归 sj244;本 fork 的版权声明见 [`LICENSE`](./LICENSE)。安装和更新都走 `dsh plugin`,不要在服务器上打补丁脚本。
|
|
10
10
|
|
|
11
|
-
**Cordis 插件 id 仍是 `qq-bridge`**(`cordis.patch.yml` 里的 `id`)。npm 包名是 **`@fengye_nobug/dsh-qq-bot
|
|
11
|
+
**Cordis 插件 id 仍是 `qq-bridge`**(`cordis.patch.yml` 里的 `id`)。npm 包名是 **`@fengye_nobug/dsh-qq-bot`**。`cordis.patch.yml` 的 `name` 必须写成这个包名,Cordis 靠它加载模块。界面显示名仍是 **dsh-qq-bot**,消息来源仍是 `plugin:dsh-qq-bot`。无作用域的 `dsh-qq-bot` 发不出去:npm 认为它和已有的 `dsh-qqbot` 太像。已有 profile 里按 `id: qq-bridge` 写的覆盖继续生效;如果那一行还写着 `name: dsh-qq-bot`,要改成 `@fengye_nobug/dsh-qq-bot`,否则插件挂不上,设置接口是 HTTP 404。设置命名空间、状态文件和 `/api/qq-bridge/...` 也沿用这个 id,避免升级时对不上。
|
|
12
12
|
|
|
13
13
|
**想装:** 优先用 npm 上已经发出的版本。连不上 npm,或 registry 里还没有这一版时,再用已经发布的 GitHub tag,不要盯着 main。
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
|
-
dsh plugin --profile web add @fengye_nobug/dsh-qq-bot@0.2.
|
|
16
|
+
dsh plugin --profile web add @fengye_nobug/dsh-qq-bot@0.2.5
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
|
-
dsh plugin --profile web add github:yunfengnobug/dsh-qq-bot#v0.2.
|
|
20
|
+
dsh plugin --profile web add github:yunfengnobug/dsh-qq-bot#v0.2.5
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
在 GitHub 上 Watch → Custom → **Releases**,比盯 main 稳。环境、第一次怎么开白名单、怎么升级、和官方插件为什么不能一起挂,写在[安装](#安装)。
|
|
24
24
|
|
|
25
25
|
- 设计:[`DESIGN.md`](./DESIGN.md) | 里程碑与真机实录:[`HANDOVER.md`](./HANDOVER.md) | 变更:[`CHANGELOG.md`](./CHANGELOG.md)
|
|
26
|
-
- 源码版本 **0.2.
|
|
26
|
+
- 源码版本 **0.2.6**(一键更新会把 Cordis 的包名改成实际装上的 `@fengye_nobug/dsh-qq-bot`)。已经发布的是 **v0.2.5**,npm 上对应 `@fengye_nobug/dsh-qq-bot@0.2.5`。源码这一版还没打 tag,也还没 `npm publish`。v0.2.5 自带补丁里的 `name` 仍是无作用域的 `dsh-qq-bot`,装完若设置页是 HTTP 404,先把 `qq-bridge` 的 `name` 改成 `@fengye_nobug/dsh-qq-bot` 再重启。见 [`CHANGELOG.md`](./CHANGELOG.md)。
|
|
27
27
|
- **M1–M8 全部完成**,已在**真实 NapCat + 真实 QQ** 上端到端跑通(Windows 真机)
|
|
28
28
|
|
|
29
29
|
## 目录
|
|
@@ -49,7 +49,7 @@ dsh plugin --profile web add github:yunfengnobug/dsh-qq-bot#v0.2.3
|
|
|
49
49
|
也认 `[表情182]` 和 `[CQ:face,id=182]`。详见[出站](#出站三种模式--来源闸门)。
|
|
50
50
|
- **有设置卡片**:名称是白话(哪些群可以叫醒、群里发出去的是哪一段、忙的时候怎么插话等),
|
|
51
51
|
配置键仍是英文。在 `设置 → 插件 → 插件配置` 里修改,保存即生效。
|
|
52
|
-
- **可以一键更新**:先点「检查更新」。有新正式版时再点「更新到 vX.Y.Z」,面板会装上并重启。优先从 npm 安装 `@fengye_nobug/dsh-qq-bot@版本`;这一版还没发到 npm 时,改从 GitHub
|
|
52
|
+
- **可以一键更新**:先点「检查更新」。有新正式版时再点「更新到 vX.Y.Z」,面板会装上并重启。优先从 npm 安装 `@fengye_nobug/dsh-qq-bot@版本`;这一版还没发到 npm 时,改从 GitHub 下载。装完把 Cordis 里 `qq-bridge` 的 `name` 改成实际装上的包名。超过三分钟没有结束就停掉卡住的安装进程;要装的版本已经在磁盘上时仍改包名,并请你自己重启 dsh-web。启动时检查不会自动安装。
|
|
53
53
|
- **NapCat 自助托管**:插件可以按需下载、校验、解包、写配置、启停 NapCat。
|
|
54
54
|
|
|
55
55
|
**不做的三件事**:
|
|
@@ -60,16 +60,16 @@ dsh plugin --profile web add github:yunfengnobug/dsh-qq-bot#v0.2.3
|
|
|
60
60
|
|
|
61
61
|
## 安装
|
|
62
62
|
|
|
63
|
-
日常安装用 npm 上已经发出的 **`@fengye_nobug/dsh-qq-bot@0.2.
|
|
63
|
+
日常安装用 npm 上已经发出的 **`@fengye_nobug/dsh-qq-bot@0.2.5`**。无作用域的 `dsh-qq-bot@版本` 装不上:npm 不接受这个名字,它和已有的 `dsh-qqbot` 太像。GitHub [Releases](https://github.com/yunfengnobug/dsh-qq-bot/releases) 上已经发出的是 **v0.2.5**。仓库源码如果已经是 0.2.6,那是还没打 tag、也还没发到 npm 的版本,日常不要装 main。某一版还没出现在 registry 里时,一键更新会改从 GitHub 下载。v0.2.5 的补丁仍把 Cordis 的 `name` 写成 `dsh-qq-bot`。装上这一版后,一键更新会在安装成功时把 profile、home(写了 `qq-bridge` 才改)和插件补丁里的 `name` 改成磁盘上的包名。
|
|
64
64
|
|
|
65
65
|
```sh
|
|
66
|
-
dsh plugin --profile web add @fengye_nobug/dsh-qq-bot@0.2.
|
|
66
|
+
dsh plugin --profile web add @fengye_nobug/dsh-qq-bot@0.2.5
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
GitHub 备用:
|
|
70
70
|
|
|
71
71
|
```sh
|
|
72
|
-
dsh plugin --profile web add github:yunfengnobug/dsh-qq-bot#v0.2.
|
|
72
|
+
dsh plugin --profile web add github:yunfengnobug/dsh-qq-bot#v0.2.5
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
不写 tag 会装 main 上最新一次提交。主分支随时在改,日常别用这条:
|
|
@@ -98,14 +98,18 @@ dsh plugin --profile web add github:yunfengnobug/dsh-qq-bot
|
|
|
98
98
|
|
|
99
99
|
四条路。装完都要让 dsh-web 重新加载插件:
|
|
100
100
|
|
|
101
|
-
1. 设置卡片里先点「检查更新」。有新正式版时出现「更新到 vX.Y.Z」。点下去优先执行 `dsh plugin --profile web add @fengye_nobug/dsh-qq-bot@X.Y.Z`,走这台机器上 pnpm 已经配置的 registry
|
|
102
|
-
2. 自己执行同一条命令。npm 上已经发出的是 `@fengye_nobug/dsh-qq-bot@0.2.
|
|
101
|
+
1. 设置卡片里先点「检查更新」。有新正式版时出现「更新到 vX.Y.Z」。点下去优先执行 `dsh plugin --profile web add @fengye_nobug/dsh-qq-bot@X.Y.Z`,走这台机器上 pnpm 已经配置的 registry,然后重启面板。装完会把 profile、`$DSH_HOME/cordis.patch.yml`(写了 `qq-bridge` 才改)和插件补丁里 `qq-bridge` 的 `name` 改成磁盘上的包名,`config` 不动。设置还在,不改 NapCat。重启后刷新页面;登录口令可能会变。
|
|
102
|
+
2. 自己执行同一条命令。npm 上已经发出的是 `@fengye_nobug/dsh-qq-bot@0.2.5`。自己装不会自动改 profile 里的旧 `name`。
|
|
103
103
|
3. 指定 GitHub tag:`dsh plugin --profile web add github:yunfengnobug/dsh-qq-bot#vX.Y.Z`
|
|
104
104
|
4. 卸掉再装,然后重启。
|
|
105
105
|
|
|
106
|
-
无作用域名字发不出去。第 1 步如果发现 registry 里没有 `@fengye_nobug/dsh-qq-bot` 的这一版,会改从 GitHub 下载该标签的官方源码包:先 `github.com`,连不上再试同一标签的 `codeload.github.com`,然后交给 `dsh plugin add`。v0.2.
|
|
106
|
+
无作用域名字发不出去。第 1 步如果发现 registry 里没有 `@fengye_nobug/dsh-qq-bot` 的这一版,会改从 GitHub 下载该标签的官方源码包:先 `github.com`,连不上再试同一标签的 `codeload.github.com`,然后交给 `dsh plugin add`。v0.2.4 及更早标签里的 `package.json` 仍是无作用域名,这种源码包仍然能装,Cordis 的 `name` 也保持 `dsh-qq-bot`。v0.2.5 的 `package.json` 已是作用域包,但补丁里的 `name` 还是旧的,所以会 404。插件不写死第三方镜像。registry 里已经有比当前新的正式版时,检查和安装不再访问 GitHub。
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
从 0.2.5 点「更新」时,执行的还是那一版里的安装程序,不会改 profile。若设置页变成 HTTP 404,把 profile 和插件目录里 `qq-bridge` 的 `name` 改成 `@fengye_nobug/dsh-qq-bot`,再重启 dsh-web。这一版(0.2.6)自己跑一键更新时会改。
|
|
109
|
+
|
|
110
|
+
「检查更新」和「启动时检查一次」只询问,不会安装。已经是最新正式版时不出现更新按钮。不会装比当前更旧的版本,也不装草稿和预发布。连不上、安装失败、面板没能重启,都用白话说明。安装已经成功但没能安排重启时,新版本在磁盘上,需要自己重启 dsh-web。包名已经改好的话,重启后设置页会回来。
|
|
111
|
+
|
|
112
|
+
安装超过三分钟没有结束时,会停掉卡住的 dsh 和它带起来的 pnpm,并用白话说明。profile 里的 `.plugin-manager/run.json` 只在记录的进程已经不在、或记录读不懂时删掉;进程还在就不会再开一次安装。超时后如果要装的版本已经在磁盘上,包名仍会改成实际安装的包,但不会自动重启,需要自己重启 dsh-web。没有确认装上时,可以再点一次「更新」。
|
|
109
113
|
|
|
110
114
|
在 Linux 上,进程由 systemd 拉起并且能认出具体服务时,大约 3 秒后只重启那个服务。只看到用户会话、认不出单独服务时,请自己重启 dsh-web。没有被 systemd 拉起时,响应发出后按当前的 node 命令行再拉起一次。这次更新不改 NapCat 的配置,也不去停它。插件自己拉起的 NapCat 会随 dsh-web 退出而结束;已经在外面跑着的 NapCat 继续运行。
|
|
111
115
|
|
|
@@ -119,12 +123,12 @@ dsh plugin --profile web add github:yunfengnobug/dsh-qq-bot
|
|
|
119
123
|
|
|
120
124
|
```sh
|
|
121
125
|
dsh plugin --profile web remove dsh-qq-bridge
|
|
122
|
-
dsh plugin --profile web add @fengye_nobug/dsh-qq-bot@0.2.
|
|
126
|
+
dsh plugin --profile web add @fengye_nobug/dsh-qq-bot@0.2.5
|
|
123
127
|
```
|
|
124
128
|
|
|
125
|
-
连不上 npm 时,把上面第二条换成 `dsh plugin --profile web add github:yunfengnobug/dsh-qq-bot#v0.2.
|
|
129
|
+
连不上 npm 时,把上面第二条换成 `dsh plugin --profile web add github:yunfengnobug/dsh-qq-bot#v0.2.5`。
|
|
126
130
|
|
|
127
|
-
然后重启 dsh-web。profile 里原来按 `id: qq-bridge`
|
|
131
|
+
然后重启 dsh-web。profile 里原来按 `id: qq-bridge` 写的覆盖可以留着。若其中有 `name`,写成 `@fengye_nobug/dsh-qq-bot`,不要留着 `dsh-qq-bot` 或 `dsh-qq-bridge`。`list` 里如果包名不是 `dsh-qq-bridge`,卸你看到的那一个官方包,不要卸别的插件。
|
|
128
132
|
|
|
129
133
|
### 开发期
|
|
130
134
|
|
|
@@ -158,18 +162,18 @@ Release 不附带密钥、日志或本机文件。源码压缩包让 GitHub 自
|
|
|
158
162
|
|
|
159
163
|
## 用 npm 安装
|
|
160
164
|
|
|
161
|
-
`dsh plugin` 是 pnpm 的包装。安装和一键更新都用作用域包名。npm 上已经发出的是 0.2.
|
|
165
|
+
`dsh plugin` 是 pnpm 的包装。安装和一键更新都用作用域包名。npm 上已经发出的是 0.2.5:
|
|
162
166
|
|
|
163
167
|
```sh
|
|
164
|
-
dsh plugin --profile web add @fengye_nobug/dsh-qq-bot@0.2.
|
|
168
|
+
dsh plugin --profile web add @fengye_nobug/dsh-qq-bot@0.2.5
|
|
165
169
|
```
|
|
166
170
|
|
|
167
171
|
无作用域的 `dsh-qq-bot` 发不出去,npm 认为它和已有的 `dsh-qqbot` 太像。不要写成 `dsh plugin add dsh-qq-bot@版本`。
|
|
168
172
|
|
|
169
|
-
registry 里还没有要装的那一版时(源码 0.2.
|
|
173
|
+
registry 里还没有要装的那一版时(源码 0.2.6 尚未发布),改用 GitHub:
|
|
170
174
|
|
|
171
175
|
```sh
|
|
172
|
-
dsh plugin --profile web add github:yunfengnobug/dsh-qq-bot#v0.2.
|
|
176
|
+
dsh plugin --profile web add github:yunfengnobug/dsh-qq-bot#v0.2.5
|
|
173
177
|
```
|
|
174
178
|
|
|
175
179
|
一键更新的顺利路径是 npm,不再要求打开 github.com。某台机器上的 `dsh plugin --help` 如果只认 `github:`,就继续用 Release tag。想用镜像,配置这台机器的 npm / pnpm registry,不要等插件内置一个镜像地址。
|
|
@@ -193,7 +197,7 @@ dsh plugin --profile web add github:yunfengnobug/dsh-qq-bot#v0.2.3
|
|
|
193
197
|
2. 把本仓库的 [`docs/awesome-dsh-plugin-entry.yml`](./docs/awesome-dsh-plugin-entry.yml) 复制成对方仓库的 `data/plugins/yunfengnobug__dsh-qq-bot.yml`,提一个 PR。不要改上游那条。一个 PR 最多 3 条。对方的 README 由脚本生成,不要手改。
|
|
194
198
|
3. 描述只写插件实际做的事。`repository` 必须指回本仓库(`package.json` 里已经是了)。yml 里不要手写 `npm:`,市场自己从 registry 认。
|
|
195
199
|
|
|
196
|
-
npm 上已经有 `@fengye_nobug/dsh-qq-bot`(目前是 0.2.
|
|
200
|
+
npm 上已经有 `@fengye_nobug/dsh-qq-bot`(目前是 0.2.5)。无作用域名发不出去。发到 npm 之后,市场才能显示下载量;不发也能收录。
|
|
197
201
|
|
|
198
202
|
用着有问题,到 [Issues](https://github.com/yunfengnobug/dsh-qq-bot/issues/new/choose) 选模板:**连不上**、**不回**、**发不出**。不要在 Issue 里贴真实 QQ 号、群号、token 或服务器地址。
|
|
199
203
|
|
|
@@ -473,7 +477,7 @@ QQ 的“拍一拍”在 OneBot 里走的是 **notice 事件**,不是消息段
|
|
|
473
477
|
|
|
474
478
|
卡片上方显示**当前版本**,并有 **检查更新**。接口是 `GET/POST /api/qq-bridge/update`,准入和设置接口相同。GET 只读当前版本,不去 npm,也不去 GitHub。POST 不带 `action` 才对比版本:先问 npm registry 里的 `@fengye_nobug/dsh-qq-bot` 正式版。有比当前新的版本时,写出版本号和 `dsh plugin --profile web add @fengye_nobug/dsh-qq-bot@x.y.z`,并且不再访问 GitHub。npm 上还没有更新、但 GitHub Release 上有更新时,才改问 GitHub,并说明一键更新会从 GitHub 下载。没有新版、连不上、被限流,都用白话说明。检查本身不会下载或安装。
|
|
475
479
|
|
|
476
|
-
有新版时出现 **更新到 vX.Y.Z**。点下去才发送 `POST { "action": "apply", "version": "x.y.z" }`。优先 `dsh plugin --profile web add @fengye_nobug/dsh-qq-bot@x.y.z`。registry 里没有这个版本时,改从 GitHub
|
|
480
|
+
有新版时出现 **更新到 vX.Y.Z**。点下去才发送 `POST { "action": "apply", "version": "x.y.z" }`。优先 `dsh plugin --profile web add @fengye_nobug/dsh-qq-bot@x.y.z`。registry 里没有这个版本时,改从 GitHub 的官方源码包装上。安装成功后,把 profile、`$DSH_HOME/cordis.patch.yml`(有 `qq-bridge` 这一行才改)和已安装插件补丁里的 `name` 改成磁盘上 `package.json` 的包名,然后重启面板。只改我们自己的旧包名(`dsh-qq-bot`、`dsh-qq-bridge`),不改 `config`,也不改别的插件。按钮下面写着:设置还在,不改 NapCat;重启后请刷新,登录口令可能会变;安装如果超过三分钟没有动静,会停掉卡住的进程,并用白话说明。进行中显示「正在更新…」。已经是最新正式版时没有这个按钮。超过三分钟还没装完时停掉这次的 dsh 和 pnpm。`.plugin-manager/run.json` 里的进程还在就不删,也不再开第二个安装;进程已经不在或记录读不懂才删。超时后如果磁盘上已经是要装的版本,仍改包名,请自己重启 dsh-web,不会自动重启。
|
|
477
481
|
|
|
478
482
|
「启动时检查一次」默认关。打开并保存后,下次启动 dsh-web 才问一次,结果只写在日志里,不会安装。
|
|
479
483
|
|
package/client/client.js
CHANGED
|
@@ -862,7 +862,7 @@ window.__ModuleLoader__.load({
|
|
|
862
862
|
),
|
|
863
863
|
h('div', { style: S.hint }, '先问 npm 上有没有新版本。这里只检查,不会安装。'),
|
|
864
864
|
updateOffer
|
|
865
|
-
? h('div', { style: S.hint }, '优先从 npm 安装 @fengye_nobug/dsh-qq-bot 的这一版并重启面板。这一版还没发到 npm 时,会改从 GitHub 下载。设置还在,不改 NapCat
|
|
865
|
+
? h('div', { style: S.hint }, '优先从 npm 安装 @fengye_nobug/dsh-qq-bot 的这一版并重启面板。这一版还没发到 npm 时,会改从 GitHub 下载。设置还在,不改 NapCat。重启后请刷新,登录口令可能会变。安装如果超过三分钟没有动静,会停掉卡住的进程,并用白话说明。')
|
|
866
866
|
: null,
|
|
867
867
|
updateNote
|
|
868
868
|
? h('div', { style: { ...(updateIsError ? S.err : S.note), whiteSpace: 'pre-wrap' } }, updateNote)
|
package/cordis.patch.yml
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# dsh-qq-bot bundle patch: one insert row carrying the whole plugin config.
|
|
2
|
-
# Cordis 插件 id 仍是 qq-bridge
|
|
2
|
+
# Cordis 插件 id 仍是 qq-bridge(与上游兼容)。界面显示名仍是 dsh-qq-bot。
|
|
3
|
+
# name 是 Node 用来加载插件的包名,必须等于实际安装的 npm 包。
|
|
4
|
+
# 无作用域的 dsh-qq-bot 发不出去;写成那个名字时 Cordis 解析不到模块,
|
|
5
|
+
# qq-bridge 不会挂上,/api/qq-bridge/settings 就是 HTTP 404。
|
|
3
6
|
# 用户在 profile 的 cordis.patch.yml 里按 id 覆盖这一行;patch 会替换整份 config,
|
|
4
|
-
#
|
|
7
|
+
# 所以要保留的键请全部重述。覆盖里如果写了 name,也要写成同一个包名。
|
|
5
8
|
- insert:
|
|
6
9
|
- id: qq-bridge
|
|
7
|
-
name: dsh-qq-bot
|
|
10
|
+
name: '@fengye_nobug/dsh-qq-bot'
|
|
8
11
|
config:
|
|
9
12
|
# 固定目标会话:QQ 的一切都注入这一个会话(保留其上下文)。
|
|
10
13
|
# 留空表示不驱动任何会话。
|
package/index.js
CHANGED
|
@@ -3971,6 +3971,8 @@ export function apply(ctx, config) {
|
|
|
3971
3971
|
version: typeof payload.version === 'string' ? payload.version : '',
|
|
3972
3972
|
force: payload.force === true,
|
|
3973
3973
|
proxy: proxyFor(readSettings()),
|
|
3974
|
+
home: process.env.DSH_HOME || join(homedir(), '.dsh'),
|
|
3975
|
+
profile: 'web',
|
|
3974
3976
|
})
|
|
3975
3977
|
} catch {
|
|
3976
3978
|
return sendJson(res, 200, { ok: false, stage: 'install', error: '更新没有完成。稍后再试。' })
|
package/package.json
CHANGED
package/updates.js
CHANGED
|
@@ -7,11 +7,15 @@
|
|
|
7
7
|
// 插件不写死第三方镜像。包还没发到 npm,或 registry 里没有这个版本时,才改从 GitHub 下载:
|
|
8
8
|
// 先要 github.com 上的官方源码包,连不上再试同一标签的 codeload。只跟随仍指向同一标签的
|
|
9
9
|
// github.com、api.github.com 或 codeload.github.com。不用 git 协议。
|
|
10
|
+
// 安装成功后,若 profile、home 或插件自己的 cordis.patch.yml 里 qq-bridge 的 name
|
|
11
|
+
// 仍是旧的无作用域名,会改成磁盘上 package.json 里的包名。不改 config,不改设置,不改 NapCat。
|
|
12
|
+
// 安装超过三分钟还没结束时,停掉这次拉起的进程组,并清掉已经退出的安装记录。
|
|
13
|
+
// 超时后若磁盘上已是目标版本,仍改包名,但不自动重启。
|
|
10
14
|
|
|
11
15
|
import { spawn } from 'node:child_process'
|
|
12
|
-
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
16
|
+
import { chmodSync, mkdtempSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
13
17
|
import { tmpdir } from 'node:os'
|
|
14
|
-
import { join } from 'node:path'
|
|
18
|
+
import { isAbsolute, join } from 'node:path'
|
|
15
19
|
import { gunzipSync, gzipSync } from 'node:zlib'
|
|
16
20
|
|
|
17
21
|
export const UPDATE_REPO = 'yunfengnobug/dsh-qq-bot'
|
|
@@ -27,6 +31,8 @@ const MAX_TARBALL_BYTES = 20 * 1024 * 1024
|
|
|
27
31
|
const MAX_UNPACKED_BYTES = 40 * 1024 * 1024
|
|
28
32
|
const MAX_TAR_ENTRIES = 4000
|
|
29
33
|
const INSTALL_TIMEOUT_MS = 180000
|
|
34
|
+
/** 先劝退,再强制停。给子进程一点时间自己退出。 */
|
|
35
|
+
const KILL_GRACE_MS = 1500
|
|
30
36
|
const DOWNLOAD_TIMEOUT_MS = 60000
|
|
31
37
|
/** 先把 HTTP 响应发出去,再重启,避免面板还没回答就被掐掉。 */
|
|
32
38
|
const RESTART_DELAY_MS = 2500
|
|
@@ -613,14 +619,29 @@ function downloadError(code) {
|
|
|
613
619
|
return '连不上 GitHub,这次没有把新版本下下来。稍后再试。'
|
|
614
620
|
}
|
|
615
621
|
|
|
616
|
-
function installError(code, command) {
|
|
622
|
+
function installError(code, command, extra = {}) {
|
|
617
623
|
const hint = command ? `也可以自己执行:${command}` : '也可以按卡片上的安装命令自己装。'
|
|
618
624
|
if (code === 'ENOENT') return `没找到 dsh 命令,没有安装。${hint}`
|
|
619
|
-
if (code === '
|
|
625
|
+
if (code === 'busy') {
|
|
626
|
+
const pid = Number(extra.pid)
|
|
627
|
+
const which = Number.isSafeInteger(pid) && pid > 1 ? `(进程 ${pid})` : ''
|
|
628
|
+
return `已经有一个安装进程还在跑${which},这次没有再启动。等它结束再点「更新」。如果确认它已经卡死,先停掉那个进程,再点一次。`
|
|
629
|
+
}
|
|
630
|
+
if (code === 'timeout' && extra.packageName) {
|
|
631
|
+
return `安装超时,已经停掉卡住的进程。新版本的文件已经在磁盘上,qq-bridge 的包名也改成了 ${extra.packageName}。请重启 dsh-web,设置页才会出来。`
|
|
632
|
+
}
|
|
633
|
+
if (code === 'timeout' && extra.leftover) {
|
|
634
|
+
return `安装超时,卡住的安装进程还没停干净。请先停掉 dsh 和 pnpm,再点一次「更新」。${hint}`
|
|
635
|
+
}
|
|
636
|
+
if (code === 'timeout') {
|
|
637
|
+
return `安装超时,已经停掉卡住的安装进程,并清掉这次留下的安装记录。没有确认装上。可以再点一次「更新」。${hint}`
|
|
638
|
+
}
|
|
620
639
|
if (code === 'wrong-name') return '下到的安装包不是这个插件,没有安装。'
|
|
621
640
|
if (code === 'wrong-version') return '下到的版本和发布标签对不上,没有安装。'
|
|
622
641
|
if (code === 'bad-package') return '下到的安装包读不懂,没有安装。'
|
|
623
|
-
|
|
642
|
+
const base = `安装没有成功。${hint}`
|
|
643
|
+
if (extra.packageName) return `${base}Cordis 里 qq-bridge 的包名已经改成实际安装的 ${extra.packageName}。请重启 dsh-web,设置页才会出来。`
|
|
644
|
+
return base
|
|
624
645
|
}
|
|
625
646
|
|
|
626
647
|
function restartError() {
|
|
@@ -1167,16 +1188,147 @@ export function dshPluginAddSpec(spec) {
|
|
|
1167
1188
|
return { command: 'dsh', args: pluginArgs, shell: false }
|
|
1168
1189
|
}
|
|
1169
1190
|
|
|
1191
|
+
function defaultAlive(pid) {
|
|
1192
|
+
try {
|
|
1193
|
+
process.kill(pid, 0)
|
|
1194
|
+
return true
|
|
1195
|
+
} catch (error) {
|
|
1196
|
+
return error?.code === 'EPERM'
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
function defaultKill(target, signal, child) {
|
|
1201
|
+
if (typeof target === 'number' && target < 0) {
|
|
1202
|
+
process.kill(target, signal)
|
|
1203
|
+
return
|
|
1204
|
+
}
|
|
1205
|
+
if (child && typeof child.kill === 'function') {
|
|
1206
|
+
child.kill(signal)
|
|
1207
|
+
return
|
|
1208
|
+
}
|
|
1209
|
+
process.kill(target, signal)
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
function defaultTaskkill(pid) {
|
|
1213
|
+
const killer = spawn('taskkill', ['/PID', String(pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' })
|
|
1214
|
+
killer.on?.('error', () => {})
|
|
1215
|
+
killer.unref?.()
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
* 停掉安装进程,以及它在 POSIX 上拉起来的进程组。
|
|
1220
|
+
* 测试要传入 kill,避免对一个碰巧存在的 pid 发信号。
|
|
1221
|
+
* @param {{ pid?: number, kill?: (signal: string) => void }} child
|
|
1222
|
+
* @param {{ platform?: string, graceMs?: number, kill?: (target: number, signal: string) => void, taskkill?: (pid: number) => void, group?: boolean }} [options]
|
|
1223
|
+
*/
|
|
1224
|
+
export function stopProcessTree(child, options = {}) {
|
|
1225
|
+
const pid = Number(child?.pid)
|
|
1226
|
+
const known = Number.isSafeInteger(pid) && pid > 1
|
|
1227
|
+
const platform = options.platform || process.platform
|
|
1228
|
+
const graceMs = options.graceMs ?? KILL_GRACE_MS
|
|
1229
|
+
const group = options.group !== false && platform !== 'win32'
|
|
1230
|
+
const kill = options.kill || ((target, signal) => defaultKill(target, signal, child))
|
|
1231
|
+
const targets = []
|
|
1232
|
+
if (known && group) targets.push(-pid)
|
|
1233
|
+
if (known) targets.push(pid)
|
|
1234
|
+
const send = (signal) => {
|
|
1235
|
+
if (platform === 'win32' && signal === 'SIGKILL') {
|
|
1236
|
+
if (!known) return
|
|
1237
|
+
const taskkill = options.taskkill || defaultTaskkill
|
|
1238
|
+
try { taskkill(pid) } catch { /* 停不掉时由调用方再看进程还在不在 */ }
|
|
1239
|
+
return
|
|
1240
|
+
}
|
|
1241
|
+
for (const target of targets) {
|
|
1242
|
+
try { kill(target, signal) } catch { /* 进程已经退出 */ }
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
send('SIGTERM')
|
|
1246
|
+
const timer = setTimeout(() => send('SIGKILL'), graceMs)
|
|
1247
|
+
if (typeof timer.unref === 'function') timer.unref()
|
|
1248
|
+
return {
|
|
1249
|
+
pid: known ? pid : 0,
|
|
1250
|
+
stop() { clearTimeout(timer) },
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/** DSH 把正在跑的 pnpm 记在 profile 的这个文件里。 */
|
|
1255
|
+
export function runRecordPath(profileDir) {
|
|
1256
|
+
return join(profileDir, '.plugin-manager', 'run.json')
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
/** 只认 `{ pid, grouped }`。pid 必须是大于 1 的整数,避免把 1 号进程当成安装进程。 */
|
|
1260
|
+
export function parseRunRecord(text) {
|
|
1261
|
+
let value
|
|
1262
|
+
try {
|
|
1263
|
+
value = JSON.parse(String(text ?? ''))
|
|
1264
|
+
} catch {
|
|
1265
|
+
return null
|
|
1266
|
+
}
|
|
1267
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null
|
|
1268
|
+
const pid = value.pid
|
|
1269
|
+
if (!Number.isSafeInteger(pid) || pid <= 1 || typeof value.grouped !== 'boolean') return null
|
|
1270
|
+
return { pid, grouped: value.grouped }
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
/**
|
|
1274
|
+
* 安装记录里的进程已经不在,或记录本身读不懂时,把文件删掉。
|
|
1275
|
+
* 进程还活着就不删,免得下一次安装和还在写目录的 pnpm 抢在一起。
|
|
1276
|
+
* 测试要传入 alive。默认探测会向真实 pid 发 0 信号。
|
|
1277
|
+
* @param {string} profileDir
|
|
1278
|
+
* @param {{ alive?: (pid: number) => boolean }} [options]
|
|
1279
|
+
*/
|
|
1280
|
+
export function clearStaleRunRecord(profileDir, options = {}) {
|
|
1281
|
+
const path = runRecordPath(profileDir)
|
|
1282
|
+
let text
|
|
1283
|
+
try {
|
|
1284
|
+
text = readFileSync(path, 'utf8')
|
|
1285
|
+
} catch (error) {
|
|
1286
|
+
if (error?.code === 'ENOENT') return { removed: false, alive: false, missing: true }
|
|
1287
|
+
throw error
|
|
1288
|
+
}
|
|
1289
|
+
const record = parseRunRecord(text)
|
|
1290
|
+
if (!record) {
|
|
1291
|
+
try {
|
|
1292
|
+
rmSync(path, { force: true })
|
|
1293
|
+
} catch {
|
|
1294
|
+
return { removed: false, invalid: true, alive: false }
|
|
1295
|
+
}
|
|
1296
|
+
return { removed: true, invalid: true, alive: false }
|
|
1297
|
+
}
|
|
1298
|
+
const probe = options.alive || defaultAlive
|
|
1299
|
+
let living = false
|
|
1300
|
+
try {
|
|
1301
|
+
living = probe(record.pid) === true
|
|
1302
|
+
} catch {
|
|
1303
|
+
// 看不出来就当成还在跑,避免删掉记录后再开一个安装。
|
|
1304
|
+
living = true
|
|
1305
|
+
}
|
|
1306
|
+
if (living) return { removed: false, alive: true, pid: record.pid, grouped: record.grouped }
|
|
1307
|
+
try {
|
|
1308
|
+
rmSync(path, { force: true })
|
|
1309
|
+
} catch {
|
|
1310
|
+
return { removed: false, alive: false, pid: record.pid }
|
|
1311
|
+
}
|
|
1312
|
+
return { removed: true, alive: false, pid: record.pid }
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1170
1315
|
function runChild(spawnImpl, command, args, options = {}) {
|
|
1171
1316
|
return new Promise((resolve) => {
|
|
1172
1317
|
let settled = false
|
|
1173
1318
|
let timer
|
|
1319
|
+
let graceTimer
|
|
1320
|
+
let stopper = null
|
|
1321
|
+
let timedOut = false
|
|
1174
1322
|
const finish = (value) => {
|
|
1175
1323
|
if (settled) return
|
|
1176
1324
|
settled = true
|
|
1177
1325
|
if (timer) clearTimeout(timer)
|
|
1326
|
+
if (graceTimer) clearTimeout(graceTimer)
|
|
1327
|
+
stopper?.stop()
|
|
1178
1328
|
resolve(value)
|
|
1179
1329
|
}
|
|
1330
|
+
const platform = options.platform || process.platform
|
|
1331
|
+
const detached = options.detached === true && platform !== 'win32'
|
|
1180
1332
|
let child
|
|
1181
1333
|
try {
|
|
1182
1334
|
child = spawnImpl(command, args, {
|
|
@@ -1185,6 +1337,7 @@ function runChild(spawnImpl, command, args, options = {}) {
|
|
|
1185
1337
|
windowsHide: true,
|
|
1186
1338
|
shell: false,
|
|
1187
1339
|
stdio: options.stdio || ['ignore', 'pipe', 'pipe'],
|
|
1340
|
+
detached,
|
|
1188
1341
|
})
|
|
1189
1342
|
} catch (error) {
|
|
1190
1343
|
finish({ ok: false, code: error?.code === 'ENOENT' ? 'ENOENT' : 'error' })
|
|
@@ -1204,29 +1357,120 @@ function runChild(spawnImpl, command, args, options = {}) {
|
|
|
1204
1357
|
if (stderr.length >= 4000) return
|
|
1205
1358
|
stderr += chunk.toString().slice(0, 4000 - stderr.length)
|
|
1206
1359
|
})
|
|
1207
|
-
child.on('error', (error) =>
|
|
1360
|
+
child.on('error', (error) => {
|
|
1361
|
+
if (timedOut) return
|
|
1362
|
+
finish({ ok: false, code: error?.code === 'ENOENT' ? 'ENOENT' : 'error', stdout, stderr })
|
|
1363
|
+
})
|
|
1364
|
+
const graceMs = options.killGraceMs ?? KILL_GRACE_MS
|
|
1208
1365
|
timer = setTimeout(() => {
|
|
1209
|
-
|
|
1210
|
-
|
|
1366
|
+
timedOut = true
|
|
1367
|
+
stopper = stopProcessTree(child, {
|
|
1368
|
+
platform,
|
|
1369
|
+
graceMs,
|
|
1370
|
+
kill: options.kill,
|
|
1371
|
+
taskkill: options.taskkill,
|
|
1372
|
+
group: detached,
|
|
1373
|
+
})
|
|
1374
|
+
if (settled) {
|
|
1375
|
+
stopper.stop()
|
|
1376
|
+
return
|
|
1377
|
+
}
|
|
1378
|
+
graceTimer = setTimeout(() => {
|
|
1379
|
+
const pid = Number(child.pid)
|
|
1380
|
+
const known = Number.isSafeInteger(pid) && pid > 1
|
|
1381
|
+
let leftover = false
|
|
1382
|
+
if (known) {
|
|
1383
|
+
const probe = options.alive || defaultAlive
|
|
1384
|
+
try { leftover = probe(pid) === true } catch { leftover = true }
|
|
1385
|
+
}
|
|
1386
|
+
finish({ ok: false, code: 'timeout', leftover, pid: known ? pid : 0, stdout, stderr })
|
|
1387
|
+
}, graceMs + 50)
|
|
1211
1388
|
}, options.timeoutMs ?? INSTALL_TIMEOUT_MS)
|
|
1212
|
-
child.on('close', (code) =>
|
|
1389
|
+
child.on('close', (code) => {
|
|
1390
|
+
if (timedOut && code === 0) {
|
|
1391
|
+
finish({ ok: true, code: 0, stdout, stderr })
|
|
1392
|
+
return
|
|
1393
|
+
}
|
|
1394
|
+
if (timedOut) {
|
|
1395
|
+
finish({ ok: false, code: 'timeout', leftover: false, stdout, stderr, pid: Number.isSafeInteger(Number(child.pid)) ? Number(child.pid) : 0 })
|
|
1396
|
+
return
|
|
1397
|
+
}
|
|
1398
|
+
finish({ ok: code === 0, code: code === 0 ? 0 : 'exit', stdout, stderr })
|
|
1399
|
+
})
|
|
1213
1400
|
})
|
|
1214
1401
|
}
|
|
1215
1402
|
|
|
1216
|
-
|
|
1403
|
+
/**
|
|
1404
|
+
* 执行 `dsh plugin add`。开始前清掉已经退出的安装记录;记录里的进程还在就不再开一次。
|
|
1405
|
+
* 超时后停掉进程组。记录里如果是另一个还活着的 pid,也停掉,但活着的记录文件留着。
|
|
1406
|
+
* @param {{ packageSpec?: string, tarballPath?: string, platform?: string, profile?: string, profileDir?: string, cwd?: string, env?: NodeJS.ProcessEnv, spawnImpl?: typeof spawn, timeoutMs?: number, killGraceMs?: number, kill?: (target: number, signal: string) => void, alive?: (pid: number) => boolean, taskkill?: (pid: number) => void }} spec
|
|
1407
|
+
*/
|
|
1408
|
+
export async function runPluginAdd(spec) {
|
|
1409
|
+
const profileDir = typeof spec.profileDir === 'string' ? spec.profileDir : ''
|
|
1410
|
+
const platform = spec.platform || process.platform
|
|
1411
|
+
if (profileDir !== '') {
|
|
1412
|
+
let stale = null
|
|
1413
|
+
try {
|
|
1414
|
+
stale = clearStaleRunRecord(profileDir, { alive: spec.alive })
|
|
1415
|
+
} catch {
|
|
1416
|
+
stale = null
|
|
1417
|
+
}
|
|
1418
|
+
if (stale?.alive) return { ok: false, code: 'busy', pid: stale.pid }
|
|
1419
|
+
}
|
|
1217
1420
|
const planned = dshPluginAddSpec(spec)
|
|
1218
1421
|
const ran = await runChild(spec.spawnImpl || spawn, planned.command, planned.args, {
|
|
1219
1422
|
cwd: spec.cwd || process.cwd(),
|
|
1220
1423
|
env: spec.env || process.env,
|
|
1221
1424
|
timeoutMs: spec.timeoutMs ?? INSTALL_TIMEOUT_MS,
|
|
1222
1425
|
capture: true,
|
|
1426
|
+
detached: platform !== 'win32',
|
|
1427
|
+
platform,
|
|
1428
|
+
kill: spec.kill,
|
|
1429
|
+
alive: spec.alive,
|
|
1430
|
+
taskkill: spec.taskkill,
|
|
1431
|
+
killGraceMs: spec.killGraceMs,
|
|
1223
1432
|
})
|
|
1224
1433
|
if (ran.ok) return { ok: true, code: 0 }
|
|
1434
|
+
if (ran.code === 'timeout') {
|
|
1435
|
+
let leftover = ran.leftover === true
|
|
1436
|
+
let pid = ran.pid
|
|
1437
|
+
if (profileDir !== '') {
|
|
1438
|
+
try {
|
|
1439
|
+
const record = parseRunRecord(readFileSync(runRecordPath(profileDir), 'utf8'))
|
|
1440
|
+
if (record && record.pid !== ran.pid) {
|
|
1441
|
+
// 记录里的 grouped 为真时,这个 pid 才是进程组负责人。CLI 安装记的是 false,只停这个进程。
|
|
1442
|
+
stopProcessTree({ pid: record.pid }, {
|
|
1443
|
+
platform,
|
|
1444
|
+
graceMs: 0,
|
|
1445
|
+
kill: spec.kill,
|
|
1446
|
+
taskkill: spec.taskkill,
|
|
1447
|
+
group: record.grouped === true,
|
|
1448
|
+
})
|
|
1449
|
+
}
|
|
1450
|
+
} catch {
|
|
1451
|
+
// 没有留下记录,或记录读不懂。下面再按进程是否还在决定删不删。
|
|
1452
|
+
}
|
|
1453
|
+
try {
|
|
1454
|
+
const again = clearStaleRunRecord(profileDir, { alive: spec.alive })
|
|
1455
|
+
if (again.alive) {
|
|
1456
|
+
leftover = true
|
|
1457
|
+
pid = again.pid
|
|
1458
|
+
}
|
|
1459
|
+
} catch {
|
|
1460
|
+
// 清不掉就按超时说明,不把路径写进给用户的句子。
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
return { ok: false, code: 'timeout', leftover, pid }
|
|
1464
|
+
}
|
|
1465
|
+
if (ran.code === 'ENOENT') return { ok: false, code: 'ENOENT' }
|
|
1225
1466
|
if (spec.packageSpec && isRegistryMiss(ran.stderr)) return { ok: false, code: 'unpublished' }
|
|
1226
|
-
if (ran.code === 'ENOENT' || ran.code === 'timeout') return { ok: false, code: ran.code }
|
|
1227
1467
|
return { ok: false, code: 'error' }
|
|
1228
1468
|
}
|
|
1229
1469
|
|
|
1470
|
+
function defaultRunCommand(spec) {
|
|
1471
|
+
return runPluginAdd(spec)
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1230
1474
|
function readOwnCgroup() {
|
|
1231
1475
|
try {
|
|
1232
1476
|
return readFileSync('/proc/self/cgroup', 'utf8')
|
|
@@ -1363,11 +1607,187 @@ export async function schedulePanelRestart(input = {}) {
|
|
|
1363
1607
|
return { ok: true, mode: 'reexec' }
|
|
1364
1608
|
}
|
|
1365
1609
|
|
|
1366
|
-
|
|
1610
|
+
const CORDIS_ID = 'qq-bridge'
|
|
1611
|
+
|
|
1612
|
+
function isWritablePackageName(name) {
|
|
1613
|
+
return name === PACKAGE_NAME || name === LEGACY_UNSCOPED_NAME || name === 'dsh-qq-bridge'
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
/** profile 目录。profile 名只接受 dsh 自己的那一档,避免把 `..` 拼进路径。 */
|
|
1617
|
+
export function profileDirectory(home, profile = 'web') {
|
|
1618
|
+
const root = String(home ?? '')
|
|
1619
|
+
if (root === '' || root.includes('\0')) return ''
|
|
1620
|
+
const name = String(profile || 'web')
|
|
1621
|
+
if (!/^[a-z][a-z0-9_-]{0,31}$/.test(name)) return ''
|
|
1622
|
+
return join(root, 'profiles', name)
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
function profileDirOf(input) {
|
|
1626
|
+
if (input && typeof input.profileDir === 'string' && input.profileDir !== '') return input.profileDir
|
|
1627
|
+
if (input && typeof input.home === 'string' && input.home !== '') return profileDirectory(input.home, input.profile || 'web')
|
|
1628
|
+
return ''
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
function bundlePatchPath(dir, manifest) {
|
|
1632
|
+
const raw = manifest?.dsh?.bundle?.patch
|
|
1633
|
+
const rel = typeof raw === 'string' && raw !== '' ? raw : 'cordis.patch.yml'
|
|
1634
|
+
if (isAbsolute(rel) || rel.split(/[\\/]/).includes('..')) return ''
|
|
1635
|
+
return join(dir, rel)
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
function readInstalledManifest(dir) {
|
|
1639
|
+
let manifest
|
|
1640
|
+
try {
|
|
1641
|
+
manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))
|
|
1642
|
+
} catch {
|
|
1643
|
+
return null
|
|
1644
|
+
}
|
|
1645
|
+
if (!manifest || typeof manifest !== 'object' || !isWritablePackageName(manifest.name)) return null
|
|
1646
|
+
return {
|
|
1647
|
+
dir,
|
|
1648
|
+
name: manifest.name,
|
|
1649
|
+
version: String(manifest.version ?? ''),
|
|
1650
|
+
patchFile: bundlePatchPath(dir, manifest),
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
/**
|
|
1655
|
+
* 只改 `qq-bridge` 这一行的 `name`。config 和别的插件保持原样,包括注释和空行。
|
|
1656
|
+
* 只认我们自己的三个包名;别人写的路径或别的包不动。
|
|
1657
|
+
* @param {string} text
|
|
1658
|
+
* @param {string} packageName
|
|
1659
|
+
* @param {string} [pluginId]
|
|
1660
|
+
*/
|
|
1661
|
+
export function rewriteCordisPackageName(text, packageName, pluginId = CORDIS_ID) {
|
|
1662
|
+
const source = String(text ?? '')
|
|
1663
|
+
if (!isWritablePackageName(packageName) || !/^[A-Za-z0-9_-]+$/.test(pluginId)) return { text: source, changed: false }
|
|
1664
|
+
const newline = source.includes('\r\n') ? '\r\n' : '\n'
|
|
1665
|
+
const endsWithNewline = /\n$/.test(source)
|
|
1666
|
+
const lines = source.split(/\r?\n/)
|
|
1667
|
+
if (endsWithNewline && lines[lines.length - 1] === '') lines.pop()
|
|
1668
|
+
let changed = false
|
|
1669
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1670
|
+
const idMatch = lines[i].match(/^(\s*)(?:-\s+)?id:\s*(['"]?)([A-Za-z0-9_-]+)\2\s*(#.*)?$/)
|
|
1671
|
+
if (!idMatch || idMatch[3] !== pluginId) continue
|
|
1672
|
+
const entryIndent = idMatch[1].length
|
|
1673
|
+
let keyIndent = -1
|
|
1674
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
1675
|
+
const line = lines[j]
|
|
1676
|
+
if (line.includes('\t')) break
|
|
1677
|
+
if (line.trim() === '' || /^\s*#/.test(line)) continue
|
|
1678
|
+
const indent = line.match(/^ */)?.[0].length ?? 0
|
|
1679
|
+
if (indent <= entryIndent) break
|
|
1680
|
+
if (keyIndent < 0) keyIndent = indent
|
|
1681
|
+
if (indent !== keyIndent) continue
|
|
1682
|
+
if (!/^\s*name:/.test(line)) continue
|
|
1683
|
+
const nameMatch = line.match(/^(\s*)name:\s*(['"]?)([^'"\s#]+)\2\s*(#.*)?$/)
|
|
1684
|
+
if (!nameMatch) break
|
|
1685
|
+
const current = nameMatch[3]
|
|
1686
|
+
if (isWritablePackageName(current) && current !== packageName) {
|
|
1687
|
+
const comment = nameMatch[4] ? ` ${nameMatch[4]}` : ''
|
|
1688
|
+
lines[j] = `${nameMatch[1]}name: '${packageName}'${comment}`
|
|
1689
|
+
changed = true
|
|
1690
|
+
}
|
|
1691
|
+
break
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
if (!changed) return { text: source, changed: false }
|
|
1695
|
+
let next = lines.join(newline)
|
|
1696
|
+
if (endsWithNewline) next += newline
|
|
1697
|
+
return { text: next, changed: true }
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
function writeTextAtomic(file, text) {
|
|
1701
|
+
const tmp = `${file}.tmp-${process.pid}`
|
|
1702
|
+
writeFileSync(tmp, text)
|
|
1703
|
+
try {
|
|
1704
|
+
chmodSync(tmp, statSync(file).mode)
|
|
1705
|
+
} catch {
|
|
1706
|
+
// 读不到原权限就按这次写入的默认权限留下。
|
|
1707
|
+
}
|
|
1708
|
+
try {
|
|
1709
|
+
renameSync(tmp, file)
|
|
1710
|
+
} catch (error) {
|
|
1711
|
+
try { rmSync(tmp, { force: true }) } catch { /* 临时文件清不掉时,仍把写入失败抛回去 */ }
|
|
1712
|
+
throw error
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
/**
|
|
1717
|
+
* 把 profile、home(有这份文件才改)和已安装插件自己的补丁里,
|
|
1718
|
+
* `qq-bridge` 的 `name` 改成磁盘上 package.json 的包名。
|
|
1719
|
+
* 传入 expectedVersion 时,只有版本对得上才改,避免把半截安装写成错误的包名。
|
|
1720
|
+
* @param {{ profileDir?: string, home?: string, expectedVersion?: string }} input
|
|
1721
|
+
*/
|
|
1722
|
+
export function alignCordisNames(input = {}) {
|
|
1723
|
+
const profileDir = String(input.profileDir ?? '')
|
|
1724
|
+
if (profileDir === '') return { ok: false, reason: 'no-profile', changed: [], name: '' }
|
|
1725
|
+
const scoped = readInstalledManifest(join(profileDir, 'node_modules', '@fengye_nobug', 'dsh-qq-bot'))
|
|
1726
|
+
const legacy = readInstalledManifest(join(profileDir, 'node_modules', 'dsh-qq-bot'))
|
|
1727
|
+
const candidates = [scoped, legacy].filter(Boolean)
|
|
1728
|
+
let installed = null
|
|
1729
|
+
if (input.expectedVersion) {
|
|
1730
|
+
installed = candidates.find((item) => compareSemver(item.version, input.expectedVersion) === 0) || null
|
|
1731
|
+
if (!installed) return { ok: false, reason: 'version', changed: [], name: '' }
|
|
1732
|
+
} else {
|
|
1733
|
+
installed = scoped || legacy
|
|
1734
|
+
}
|
|
1735
|
+
if (!installed) return { ok: false, reason: 'missing', changed: [], name: '' }
|
|
1736
|
+
const files = []
|
|
1737
|
+
if (installed.patchFile) files.push(installed.patchFile)
|
|
1738
|
+
files.push(join(profileDir, 'cordis.patch.yml'))
|
|
1739
|
+
if (typeof input.home === 'string' && input.home !== '') files.push(join(input.home, 'cordis.patch.yml'))
|
|
1740
|
+
const changed = []
|
|
1741
|
+
let failed = false
|
|
1742
|
+
for (const file of files) {
|
|
1743
|
+
let text
|
|
1744
|
+
try {
|
|
1745
|
+
text = readFileSync(file, 'utf8')
|
|
1746
|
+
} catch {
|
|
1747
|
+
continue
|
|
1748
|
+
}
|
|
1749
|
+
const next = rewriteCordisPackageName(text, installed.name)
|
|
1750
|
+
if (!next.changed) continue
|
|
1751
|
+
try {
|
|
1752
|
+
writeTextAtomic(file, next.text)
|
|
1753
|
+
changed.push(file)
|
|
1754
|
+
} catch {
|
|
1755
|
+
failed = true
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
return {
|
|
1759
|
+
ok: !failed,
|
|
1760
|
+
failed,
|
|
1761
|
+
reason: failed ? 'write' : 'ok',
|
|
1762
|
+
changed,
|
|
1763
|
+
name: installed.name,
|
|
1764
|
+
version: installed.version,
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
function alignNote(input, expectedVersion) {
|
|
1769
|
+
const profileDir = profileDirOf(input)
|
|
1770
|
+
if (profileDir === '') return ''
|
|
1771
|
+
try {
|
|
1772
|
+
const result = alignCordisNames({
|
|
1773
|
+
profileDir,
|
|
1774
|
+
home: typeof input?.home === 'string' ? input.home : '',
|
|
1775
|
+
expectedVersion,
|
|
1776
|
+
})
|
|
1777
|
+
if (result.failed) return '没能改 Cordis 的包名。若重启后设置页打不开,把 qq-bridge 的 name 改成实际安装的包名再重启。'
|
|
1778
|
+
if (result.changed.length > 0) return `Cordis 里 qq-bridge 的包名已经改成实际安装的 ${result.name}。`
|
|
1779
|
+
return ''
|
|
1780
|
+
} catch {
|
|
1781
|
+
return '没能改 Cordis 的包名。若重启后设置页打不开,把 qq-bridge 的 name 改成实际安装的包名再重启。'
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
function successMessage(tag, channel, note = '') {
|
|
1367
1786
|
const via = channel === 'npm'
|
|
1368
1787
|
? '这次是从 npm 装的。'
|
|
1369
1788
|
: '这一版在 npm 上还没有,所以从 GitHub 装上。'
|
|
1370
|
-
|
|
1789
|
+
const base = `已经装上 ${tag},面板即将重启。请刷新页面;登录口令可能会变,用新的面板地址再打开。${via}现有设置还在,没有改动 NapCat。`
|
|
1790
|
+
return note ? `${base}${note}` : base
|
|
1371
1791
|
}
|
|
1372
1792
|
|
|
1373
1793
|
function shownInstall(channel, version, repo) {
|
|
@@ -1375,6 +1795,53 @@ function shownInstall(channel, version, repo) {
|
|
|
1375
1795
|
return { install: installSpec(version, repo), command: installCommand(version, repo) }
|
|
1376
1796
|
}
|
|
1377
1797
|
|
|
1798
|
+
function installRunSpec(input, extra) {
|
|
1799
|
+
return {
|
|
1800
|
+
...extra,
|
|
1801
|
+
platform: input.platform,
|
|
1802
|
+
profile: input.profile || 'web',
|
|
1803
|
+
profileDir: profileDirOf(input),
|
|
1804
|
+
spawnImpl: input.spawnImpl,
|
|
1805
|
+
timeoutMs: input.timeoutMs,
|
|
1806
|
+
killGraceMs: input.killGraceMs,
|
|
1807
|
+
kill: input.kill,
|
|
1808
|
+
alive: input.alive,
|
|
1809
|
+
taskkill: input.taskkill,
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
/** 安装失败时,只有目标版本已经在磁盘上、并且进程已经停干净,才改包名。不在这里重启。 */
|
|
1814
|
+
function failInstall(input, decision, ran, command, install) {
|
|
1815
|
+
const code = ran?.code
|
|
1816
|
+
const leftover = ran?.leftover === true
|
|
1817
|
+
let packageName = ''
|
|
1818
|
+
const profileDir = profileDirOf(input)
|
|
1819
|
+
if (!leftover && (code === 'timeout' || code === 'exit' || code === 'error') && profileDir !== '') {
|
|
1820
|
+
try {
|
|
1821
|
+
const aligned = alignCordisNames({
|
|
1822
|
+
profileDir,
|
|
1823
|
+
home: typeof input.home === 'string' ? input.home : '',
|
|
1824
|
+
expectedVersion: decision.version,
|
|
1825
|
+
})
|
|
1826
|
+
if (aligned.changed.length > 0) packageName = aligned.name
|
|
1827
|
+
} catch {
|
|
1828
|
+
// 对不齐就只说明安装失败。
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
const message = installError(code, command, { packageName, leftover, pid: ran?.pid })
|
|
1832
|
+
return {
|
|
1833
|
+
ok: false,
|
|
1834
|
+
stage: 'install',
|
|
1835
|
+
current: decision.current,
|
|
1836
|
+
error: message,
|
|
1837
|
+
message,
|
|
1838
|
+
tag: decision.tag,
|
|
1839
|
+
version: decision.version,
|
|
1840
|
+
command,
|
|
1841
|
+
install: install || decision.install,
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1378
1845
|
/**
|
|
1379
1846
|
* 下载并安装一次检查允许的版本,然后安排重启。
|
|
1380
1847
|
* 调用方要自己做登录校验。这里不读设置文件,也不碰 NapCat。
|
|
@@ -1405,36 +1872,26 @@ export async function applyPluginUpdate(input = {}) {
|
|
|
1405
1872
|
updateAvailable: false,
|
|
1406
1873
|
}
|
|
1407
1874
|
}
|
|
1875
|
+
const profileDir = profileDirOf(input)
|
|
1876
|
+
if (profileDir !== '') {
|
|
1877
|
+
try {
|
|
1878
|
+
const stale = clearStaleRunRecord(profileDir, { alive: input.alive })
|
|
1879
|
+
if (stale.alive) return failInstall(input, decision, { ok: false, code: 'busy', pid: stale.pid }, decision.command, decision.install)
|
|
1880
|
+
} catch {
|
|
1881
|
+
// 记录读不出来就继续,安装命令自己会再看一遍。
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1408
1884
|
let channel = decision.channel
|
|
1409
1885
|
if (channel === 'npm') {
|
|
1410
1886
|
let ran
|
|
1411
1887
|
try {
|
|
1412
1888
|
const run = input.runCommand || defaultRunCommand
|
|
1413
|
-
ran = await run({
|
|
1414
|
-
packageSpec: decision.install,
|
|
1415
|
-
platform: input.platform,
|
|
1416
|
-
profile: 'web',
|
|
1417
|
-
spawnImpl: input.spawnImpl,
|
|
1418
|
-
timeoutMs: input.timeoutMs,
|
|
1419
|
-
})
|
|
1889
|
+
ran = await run(installRunSpec(input, { packageSpec: decision.install }))
|
|
1420
1890
|
} catch {
|
|
1421
1891
|
ran = { ok: false, code: 'error' }
|
|
1422
1892
|
}
|
|
1423
1893
|
if (ran?.ok === true) return finishApply(input, decision, 'npm')
|
|
1424
|
-
if (ran?.code !== 'unpublished')
|
|
1425
|
-
const message = installError(ran?.code, decision.command)
|
|
1426
|
-
return {
|
|
1427
|
-
ok: false,
|
|
1428
|
-
stage: 'install',
|
|
1429
|
-
current: decision.current,
|
|
1430
|
-
error: message,
|
|
1431
|
-
message,
|
|
1432
|
-
tag: decision.tag,
|
|
1433
|
-
version: decision.version,
|
|
1434
|
-
command: decision.command,
|
|
1435
|
-
install: decision.install,
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1894
|
+
if (ran?.code !== 'unpublished') return failInstall(input, decision, ran, decision.command, decision.install)
|
|
1438
1895
|
channel = 'github'
|
|
1439
1896
|
}
|
|
1440
1897
|
const shown = shownInstall(channel, decision.version, repo)
|
|
@@ -1469,26 +1926,20 @@ export async function applyPluginUpdate(input = {}) {
|
|
|
1469
1926
|
try {
|
|
1470
1927
|
writeFileSync(tarballPath, packed)
|
|
1471
1928
|
const run = input.runCommand || defaultRunCommand
|
|
1472
|
-
ran = await run({
|
|
1473
|
-
tarballPath,
|
|
1474
|
-
platform: input.platform,
|
|
1475
|
-
profile: 'web',
|
|
1476
|
-
spawnImpl: input.spawnImpl,
|
|
1477
|
-
timeoutMs: input.timeoutMs,
|
|
1478
|
-
})
|
|
1929
|
+
ran = await run(installRunSpec(input, { tarballPath }))
|
|
1479
1930
|
} catch {
|
|
1480
1931
|
ran = { ok: false, code: 'error' }
|
|
1481
1932
|
} finally {
|
|
1482
1933
|
rmSync(dir, { recursive: true, force: true })
|
|
1483
1934
|
}
|
|
1484
1935
|
if (!ran || ran.ok !== true) {
|
|
1485
|
-
|
|
1486
|
-
return { ok: false, stage: 'install', current: decision.current, error: message, message, tag: decision.tag, version: decision.version, command: shown.command, install: shown.install }
|
|
1936
|
+
return failInstall(input, { ...decision, install: shown.install, command: shown.command }, ran, shown.command, shown.install)
|
|
1487
1937
|
}
|
|
1488
1938
|
return finishApply(input, { ...decision, install: shown.install, command: shown.command }, 'github')
|
|
1489
1939
|
}
|
|
1490
1940
|
|
|
1491
1941
|
async function finishApply(input, decision, channel) {
|
|
1942
|
+
const note = alignNote(input)
|
|
1492
1943
|
let restart
|
|
1493
1944
|
try {
|
|
1494
1945
|
const schedule = input.scheduleRestart || schedulePanelRestart
|
|
@@ -1497,7 +1948,7 @@ async function finishApply(input, decision, channel) {
|
|
|
1497
1948
|
restart = { ok: false, error: restartError() }
|
|
1498
1949
|
}
|
|
1499
1950
|
if (!restart || restart.ok !== true) {
|
|
1500
|
-
const message = restart?.error || restartError()
|
|
1951
|
+
const message = `${restart?.error || restartError()}${note}`
|
|
1501
1952
|
return {
|
|
1502
1953
|
ok: false,
|
|
1503
1954
|
stage: 'restart',
|
|
@@ -1512,7 +1963,7 @@ async function finishApply(input, decision, channel) {
|
|
|
1512
1963
|
message,
|
|
1513
1964
|
}
|
|
1514
1965
|
}
|
|
1515
|
-
const message = successMessage(decision.tag, channel)
|
|
1966
|
+
const message = successMessage(decision.tag, channel, note)
|
|
1516
1967
|
return {
|
|
1517
1968
|
ok: true,
|
|
1518
1969
|
applied: true,
|