@yusho/server 0.0.0-stage → 0.1.17
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/README.md +135 -2
- package/app/appguide.mjs +33 -0
- package/app/asr.mjs +82 -0
- package/app/assets/agents/claude-192.webp +0 -0
- package/app/assets/agents/claude-96.webp +0 -0
- package/app/assets/agents/codex-192.webp +0 -0
- package/app/assets/agents/codex-96.webp +0 -0
- package/app/assets/agents/default-192.webp +0 -0
- package/app/assets/agents/default-96.webp +0 -0
- package/app/assets/agents/dsh-192.webp +0 -0
- package/app/assets/agents/dsh-96.webp +0 -0
- package/app/assets/brand/logo.webp +0 -0
- package/app/assets/lib/THIRD-PARTY.txt +1 -0
- package/app/assets/lib/jsqr.js +10102 -0
- package/app/assets/linux/alpine-arm64.tar.gz +0 -0
- package/app/assets/linux/alpine-x64.tar.gz +0 -0
- package/app/assets/live/claude.livliv +0 -0
- package/app/assets/live/dafeiyu.livliv +0 -0
- package/app/assets/live/gpt.livliv +0 -0
- package/app/assets/live/sho.livliv +0 -0
- package/app/assets/live//345/275/242/350/261/241/346/235/245/346/272/220.md +5 -0
- package/app/assets/livliv/LICENSE +202 -0
- package/app/assets/livliv/NOTICE +7 -0
- package/app/assets/livliv/player.mjs +15 -0
- package/app/assets/looks/claude.webp +0 -0
- package/app/assets/looks/dafeiyu.webp +0 -0
- package/app/assets/looks/gpt.webp +0 -0
- package/app/assets/looks//345/275/242/350/261/241/346/235/245/346/272/220.md +5 -0
- package/app/assets/sho/avatar.webp +0 -0
- package/app/assets/sho/done.webp +0 -0
- package/app/assets/sho/eat.webp +0 -0
- package/app/assets/sho/idle-blink.webp +0 -0
- package/app/assets/sho/idle.webp +0 -0
- package/app/assets/sho/listen.webp +0 -0
- package/app/assets/sho/need.webp +0 -0
- package/app/assets/sho/work.webp +0 -0
- package/app/companion.mjs +519 -0
- package/app/diag.mjs +51 -0
- package/app/index.html +497 -0
- package/app/judge.mjs +103 -0
- package/app/lanxfer.mjs +157 -0
- package/app/launcher.mjs +2715 -0
- package/app/linux.mjs +97 -0
- package/app/livliv-pack.mjs +12 -0
- package/app/memory.mjs +53 -0
- package/app/net.mjs +717 -0
- package/app/office.mjs +172 -0
- package/app/p2plink.mjs +134 -0
- package/app/pcupdate.mjs +55 -0
- package/app/plans.mjs +126 -0
- package/app/plugins.mjs +79 -0
- package/app/realtime.mjs +67 -0
- package/app/skills/app-icon/SKILL.md +31 -0
- package/app/skills/daily-brief/SKILL.md +29 -0
- package/app/skills/expense-review/SKILL.md +28 -0
- package/app/skills/make-app/SKILL.md +92 -0
- package/app/skills/make-skin/SKILL.md +51 -0
- package/app/skills/meeting-notes/SKILL.md +23 -0
- package/app/skills/reading-notes/SKILL.md +25 -0
- package/app/skills/sho-stickers/SKILL.md +34 -0
- package/app/skills/sho-stickers/stickers/eat.webp +0 -0
- package/app/skills/sho-stickers/stickers/got-it.webp +0 -0
- package/app/skills/sho-stickers/stickers/hi.webp +0 -0
- package/app/skills/sho-stickers/stickers/huh.webp +0 -0
- package/app/skills/sho-stickers/stickers/on-it.webp +0 -0
- package/app/skills/sho-stickers/stickers/yay.webp +0 -0
- package/app/skills/sho-stickers/stickers.json +12 -0
- package/app/skills/study-plan/SKILL.md +30 -0
- package/app/skills/trip-planner/SKILL.md +29 -0
- package/app/skills/weekly-report/SKILL.md +30 -0
- package/app/skills/workout-plan/SKILL.md +30 -0
- package/app/skills/writing-polish/SKILL.md +33 -0
- package/app/skills.mjs +173 -0
- package/app/skins.mjs +40 -0
- package/app/social.mjs +1067 -0
- package/app/storage.mjs +143 -0
- package/app/tts.mjs +68 -0
- package/app/ttslocal.mjs +77 -0
- package/app/voices.mjs +102 -0
- package/backup.mjs +109 -0
- package/bin/yusho.mjs +141 -0
- package/connector/lib/api.mjs +14 -0
- package/connector/lib/autostart.mjs +40 -0
- package/connector/lib/client.js +165 -0
- package/connector/lib/connector.mjs +468 -0
- package/connector/lib/dsh-acp.mjs +129 -0
- package/connector/lib/dsh-headless.patch.yml +4 -0
- package/connector/lib/dsh-plugin.mjs +80 -0
- package/connector/lib/lanfile.mjs +151 -0
- package/connector/lib/nostr.mjs +53 -0
- package/connector/lib/page.html +121 -0
- package/connector/lib/qr.mjs +4 -0
- package/connector/lib/service.mjs +54 -0
- package/node_modules/@local/shoal-mobile/lib/index.js +485 -0
- package/node_modules/@local/shoal-mobile/lib/polyfill.js +82 -0
- package/node_modules/@local/shoal-mobile/lib/session-context.js +34 -0
- package/node_modules/@local/shoal-mobile/lib/shell.js +60 -0
- package/node_modules/@local/shoal-mobile/lib/web-startup.js +33 -0
- package/node_modules/@local/shoal-mobile/package.json +24 -0
- package/node_modules/@local/yusho-pc/lib/client.js +9100 -0
- package/node_modules/@local/yusho-pc/lib/index.js +3 -0
- package/node_modules/@local/yusho-pc/package.json +28 -0
- package/node_modules/@local/yusho-web-login/brand/icon-192.webp +0 -0
- package/node_modules/@local/yusho-web-login/brand/logo-dark.svg +25 -0
- package/node_modules/@local/yusho-web-login/brand.mjs +8 -0
- package/node_modules/@local/yusho-web-login/dsh-web-login.mjs +974 -0
- package/node_modules/@local/yusho-web-login/lib/client.js +607 -0
- package/node_modules/@local/yusho-web-login/login-page.mjs +609 -0
- package/node_modules/@local/yusho-web-login/login-store.mjs +708 -0
- package/node_modules/@local/yusho-web-login/package.json +25 -0
- package/node_modules/@local/yusho-web-login/whale-scene.mjs +509 -0
- package/node_modules/@local/yusho-web-login/yusho-scene.mjs +227 -0
- package/package.json +38 -4
- package/pc.patch.yml +83 -0
- package/run.mjs +138 -0
package/README.md
CHANGED
|
@@ -1,3 +1,136 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 鱼Sho 服务器版
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
完整的 **DeepSeek Harness(DSH)网页版**,加上鱼Sho 的会话、圈子、Sho 酱、工作台和接单,装在服务器上,用浏览器打开。
|
|
4
|
+
装法、启动参数都和 DSH 官方网页版一样(`dsh web` → `yusho`)。
|
|
5
|
+
|
|
6
|
+
## 要什么
|
|
7
|
+
|
|
8
|
+
- Node.js **24.11 或更新**(`node -v` 看一下;没有就装官方的 LTS,或者用 nvm:`nvm install 24`)
|
|
9
|
+
- Linux(x64 / arm64)、macOS 或 Windows 都行。DSH 用到的本机模块装的时候按系统自动装对应的。
|
|
10
|
+
|
|
11
|
+
## 装
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm i -g @yusho/server --allow-scripts=@deepseek-ai/dsh-subprocess-local,koffi,node-pty,protobufjs
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`--allow-scripts` 是给 npm 11 的:它默认不跑依赖的安装脚本,而 DSH 跑命令、开终端要用的这几个本机模块得在安装时编好。npm 10 及更早不用加。
|
|
18
|
+
|
|
19
|
+
## 跑起来
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
yusho
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
起来后会打印一个带一次性口令的地址,用浏览器打开;然后用手机鱼Sho 扫页面上的码登录,就和手机是同一个号:手机能把活派给这台服务器,要批的事两边都能批。
|
|
26
|
+
|
|
27
|
+
再要地址:`yusho url`。停:Ctrl+C(或者停 systemd 服务)。
|
|
28
|
+
|
|
29
|
+
| 参数 | 说明 |
|
|
30
|
+
|---|---|
|
|
31
|
+
| `--port 8080` | 网页端口(默认 8791) |
|
|
32
|
+
| `--data <目录>` | 数据放哪(默认 `~/.yusho`:身份、聊天记录、DSH 的任务、工作区、日志) |
|
|
33
|
+
| `--name <名字>` | 手机里看到的这台机器叫什么(默认主机名) |
|
|
34
|
+
| `--host <本机地址>` | 不只听 127.0.0.1(DSH 不接受 `0.0.0.0` 这种通配地址,要写具体的网卡地址;不开 TLS 时别直接暴露到公网) |
|
|
35
|
+
| `--public-url <https://…/>` | 放在反向代理后面时,浏览器用的公开地址 |
|
|
36
|
+
| `--trusted-host <域名>` | 浏览器用来访问的域名(可以写多次) |
|
|
37
|
+
| `--tls-cert <文件> --tls-key <文件>` | 自己提供 HTTPS(完整证书链 + 不带口令的私钥) |
|
|
38
|
+
|
|
39
|
+
这几个网页参数原样交给 DSH,规则和 DSH 文档《在反向代理之后发布 Web UI》一样。
|
|
40
|
+
|
|
41
|
+
## 放到公网(推荐:反向代理负责 HTTPS)
|
|
42
|
+
|
|
43
|
+
鱼Sho 还是只听本机,前面放 Caddy / Nginx:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
yusho --public-url https://yusho.example.com/ --trusted-host yusho.example.com
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Caddy(自动申请证书):
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
yusho.example.com {
|
|
53
|
+
reverse_proxy 127.0.0.1:8791
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Nginx(要转发 WebSocket,保留浏览器看到的 Host):
|
|
58
|
+
|
|
59
|
+
```nginx
|
|
60
|
+
server {
|
|
61
|
+
listen 443 ssl;
|
|
62
|
+
server_name yusho.example.com;
|
|
63
|
+
# ssl_certificate / ssl_certificate_key ...
|
|
64
|
+
location / {
|
|
65
|
+
proxy_pass http://127.0.0.1:8791;
|
|
66
|
+
proxy_http_version 1.1;
|
|
67
|
+
proxy_set_header Host $host;
|
|
68
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
69
|
+
proxy_set_header Connection "upgrade";
|
|
70
|
+
proxy_read_timeout 1h;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
挂在子路径(比如 `https://example.com/yusho/`)时,代理要把前缀去掉再转给鱼Sho,cookie 的 Path 改成前缀——细节见 DSH 文档。
|
|
76
|
+
|
|
77
|
+
## 开机自动跑(systemd,用户服务)
|
|
78
|
+
|
|
79
|
+
`~/.config/systemd/user/yusho.service`:
|
|
80
|
+
|
|
81
|
+
```ini
|
|
82
|
+
[Unit]
|
|
83
|
+
Description=鱼Sho 服务器版
|
|
84
|
+
After=network-online.target
|
|
85
|
+
|
|
86
|
+
[Service]
|
|
87
|
+
ExecStart=/usr/bin/env yusho --public-url https://yusho.example.com/ --trusted-host yusho.example.com
|
|
88
|
+
Restart=on-failure
|
|
89
|
+
Environment=PATH=%h/.nvm/versions/node/v24.11.0/bin:/usr/local/bin:/usr/bin:/bin
|
|
90
|
+
|
|
91
|
+
[Install]
|
|
92
|
+
WantedBy=default.target
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
systemctl --user daemon-reload
|
|
97
|
+
systemctl --user enable --now yusho
|
|
98
|
+
loginctl enable-linger "$USER" # 没登录时也跑
|
|
99
|
+
journalctl --user -u yusho -f # 看日志(登录地址也在里面)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`Environment=PATH` 写成你 `which node` 所在的目录。
|
|
103
|
+
|
|
104
|
+
## Docker
|
|
105
|
+
|
|
106
|
+
```dockerfile
|
|
107
|
+
FROM node:24-bookworm-slim
|
|
108
|
+
RUN npm i -g @yusho/server --allow-scripts=@deepseek-ai/dsh-subprocess-local,koffi,node-pty,protobufjs
|
|
109
|
+
VOLUME /root/.yusho
|
|
110
|
+
EXPOSE 8791
|
|
111
|
+
# DSH 不接受 0.0.0.0:用容器自己的地址
|
|
112
|
+
CMD ["sh", "-c", "yusho --host \"$(hostname -i | awk '{print $1}')\" --public-url \"$PUBLIC_URL\" --trusted-host \"$PUBLIC_HOST\""]
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
docker run -d --name yusho -p 127.0.0.1:8791:8791 -v yusho-data:/root/.yusho \
|
|
117
|
+
-e PUBLIC_URL=https://yusho.example.com/ -e PUBLIC_HOST=yusho.example.com yusho
|
|
118
|
+
docker logs yusho | grep token # 登录地址
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 更新、卸载
|
|
122
|
+
|
|
123
|
+
```sh
|
|
124
|
+
npm i -g @yusho/server@latest # 更新,然后重启服务
|
|
125
|
+
npm rm -g @yusho/server # 卸载;数据在 ~/.yusho,要删自己删
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## 和电脑版(EXE)的区别
|
|
129
|
+
|
|
130
|
+
同一套程序:EXE 外面多了一层 Windows 窗口、托盘、开机启动和系统通知;服务器版没有窗口,用浏览器打开,后台一直跑。插件、技能、MCP 的装法和改法两边一样,都是 DSH 自己的插件页。
|
|
131
|
+
|
|
132
|
+
## 安全
|
|
133
|
+
|
|
134
|
+
- 登录地址里带口令,只发给你自己。
|
|
135
|
+
- 鱼Sho 的内核接口只听本机(127.0.0.1),带随机口令;网页那一层的访问规则是 DSH 的。
|
|
136
|
+
- 不要不开 HTTPS 就直接把端口暴露到公网。
|
package/app/appguide.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// 告诉模型 App 能显示什么(写进 $DSH_HOME/AGENTS.md,DSH 每次放进系统提示)。只说“有什么、怎么写”,用不用由模型自己判断。
|
|
2
|
+
// 文件第一行是我们的标记:是我们写的才覆盖(用户自己写了 AGENTS.md 就不碰)
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
|
|
6
|
+
const MARK = '<!-- 鱼Sho App 自动生成:App 每次启动会更新这个文件。想自己写,删掉这一行就不会再被覆盖 -->'
|
|
7
|
+
const GUIDE = `${MARK}
|
|
8
|
+
# 鱼Sho App 能显示的内容
|
|
9
|
+
|
|
10
|
+
你的回复显示在鱼Sho 的对话里(手机上是竖屏气泡,宽约 320;电脑上是宽屏窗口)。除了普通文字,App 还能显示:
|
|
11
|
+
|
|
12
|
+
- Markdown:标题、列表、表格、引用、加粗、链接、图片链接、代码块(带“复制”按钮)。
|
|
13
|
+
- \`\`\`dsh-ui 代码块:里面写一份 JSON,App 把它画成卡片。组件:
|
|
14
|
+
- chart:\`{"type":"chart","kind":"bar|hbar|line|donut","title":"可选","categories":["A","B"],"series":[{"name":"可选","values":[1,2]}],"unit":"可选"}\`(hbar 横条适合名字长、项目少;line 适合随时间变化;donut 适合占比)
|
|
15
|
+
- metric:\`{"type":"metric","label":"","value":"","caption":"可选","tone":"good|warn|bad|info,可选"}\`
|
|
16
|
+
- compare:\`{"type":"compare","items":[{"title":"","badge":"可选","rows":[["名称","值"]]}]}\`(2–4 项并排对比)
|
|
17
|
+
- table:\`{"type":"table","columns":["",""],"rows":[["",""]]}\`;keyValue:\`{"type":"keyValue","items":[["名称","值"]]}\`
|
|
18
|
+
- steps:\`{"type":"steps","items":[{"label":"","status":"done|current|todo|failed"}]}\`;callout:\`{"type":"callout","text":"","tone":"info|good|warn|bad"}\`;progress:\`{"type":"progress","label":"","value":30,"max":100}\`;list:\`{"type":"list","items":[{"title":"","subtitle":"","trailing":""}]}\`
|
|
19
|
+
- options:\`{"type":"options","options":[{"label":"","description":"可选"}]}\`——用户点了哪个,那一项的文字会作为用户的下一句话发给你
|
|
20
|
+
- 组合:\`{"type":"stack","children":[…]}\`(竖排)、\`{"type":"row","children":[…]}\`(横排,窄了自动折行)
|
|
21
|
+
|
|
22
|
+
用不用、用哪种由你判断:只在图表或卡片确实比文字更清楚、更好用时才用,大多数回答用普通文字就好。用的时候前后照常用文字把结论说清楚;JSON 要合法、精简(建议 40 个节点以内)。
|
|
23
|
+
`
|
|
24
|
+
|
|
25
|
+
export function writeAppGuide(home, log = () => {}) {
|
|
26
|
+
try {
|
|
27
|
+
const f = path.join(home, 'AGENTS.md')
|
|
28
|
+
let old = null; try { old = fs.readFileSync(f, 'utf8') } catch {}
|
|
29
|
+
if (old != null && !old.startsWith(MARK)) return log('AGENTS.md 是用户自己写的,不覆盖')
|
|
30
|
+
if (old === GUIDE) return
|
|
31
|
+
fs.mkdirSync(home, { recursive: true }); fs.writeFileSync(f, GUIDE)
|
|
32
|
+
} catch (e) { log('写 AGENTS.md 失败:', e?.message) }
|
|
33
|
+
}
|
package/app/asr.mjs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// 离线语音识别(SenseVoice,sherpa-onnx):模型约 230 MB,用户在设置里点了才下载,不打进安装包。
|
|
2
|
+
// 原始文件在国外(HuggingFace),国内慢甚至下不了,所以按顺序试:ModelScope 上的几份转存(国内快)→ hf-mirror → HuggingFace。
|
|
3
|
+
// 每个文件下完都核对 SHA-256(和 HuggingFace 上官方文件的一致),转存被改过也用不进来。支持断点续传。
|
|
4
|
+
import fs from 'node:fs'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
import crypto from 'node:crypto'
|
|
7
|
+
|
|
8
|
+
const FILES = [
|
|
9
|
+
{ name: 'tokens.txt', size: 315894, sha256: 'f449eb28dc567533d7fa59be34e2abca8784f771850c78a47fb731a31429a1dc' },
|
|
10
|
+
{ name: 'model.int8.onnx', size: 239233841, sha256: 'c71f0ce00bec95b07744e116345e33d8cbbe08cef896382cf907bf4b51a2cd51' },
|
|
11
|
+
]
|
|
12
|
+
const SOURCES = [
|
|
13
|
+
(f) => 'https://modelscope.cn/models/pengzhendong/sherpa-onnx-sense-voice-zh-en-ja-ko-yue/resolve/master/' + f,
|
|
14
|
+
(f) => 'https://modelscope.cn/models/chriscrs/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-int8-2024-07-17/resolve/master/' + f,
|
|
15
|
+
(f) => 'https://modelscope.cn/models/mariolux/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17/resolve/master/' + f,
|
|
16
|
+
(f) => 'https://hf-mirror.com/csukuangfj/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17/resolve/main/' + f,
|
|
17
|
+
(f) => 'https://huggingface.co/csukuangfj/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17/resolve/main/' + f,
|
|
18
|
+
]
|
|
19
|
+
const TOTAL = FILES.reduce((a, f) => a + f.size, 0)
|
|
20
|
+
|
|
21
|
+
export function createAsr({ appDir, log = () => {} }) {
|
|
22
|
+
const DIR = path.join(appDir, 'models', 'sensevoice'), CFG = path.join(appDir, 'asr.json')
|
|
23
|
+
let job = null, prog = { got: 0, total: TOTAL, source: null, error: null, speed: 0 }
|
|
24
|
+
const cfg = () => { try { return JSON.parse(fs.readFileSync(CFG, 'utf8')) } catch { return {} } }
|
|
25
|
+
const ok = () => FILES.every((f) => { try { return fs.statSync(path.join(DIR, f.name)).size === f.size } catch { return false } }) && fs.existsSync(path.join(DIR, '.verified'))
|
|
26
|
+
const sha = (p) => new Promise((res, rej) => { const h = crypto.createHash('sha256'); fs.createReadStream(p).on('data', (d) => h.update(d)).on('end', () => res(h.digest('hex'))).on('error', rej) })
|
|
27
|
+
async function fetchOne(f, done) {
|
|
28
|
+
const dst = path.join(DIR, f.name), part = dst + '.part'
|
|
29
|
+
let lastErr = null
|
|
30
|
+
for (const src of SOURCES) {
|
|
31
|
+
const url = src(f.name)
|
|
32
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
33
|
+
if (job?.cancel) throw new Error('取消了')
|
|
34
|
+
const have = fs.existsSync(part) ? fs.statSync(part).size : 0
|
|
35
|
+
if (have >= f.size) break
|
|
36
|
+
try {
|
|
37
|
+
prog.source = new URL(url).hostname
|
|
38
|
+
const r = await fetch(url, { headers: have ? { range: 'bytes=' + have + '-' } : {}, redirect: 'follow', signal: AbortSignal.timeout(30 * 60_000) })
|
|
39
|
+
if (!(r.status === 200 || r.status === 206)) throw new Error('HTTP ' + r.status)
|
|
40
|
+
const append = have && r.status === 206
|
|
41
|
+
const out = fs.createWriteStream(part, { flags: append ? 'a' : 'w' })
|
|
42
|
+
let got = append ? have : 0, t0 = Date.now(), b0 = got
|
|
43
|
+
for await (const chunk of r.body) {
|
|
44
|
+
if (job?.cancel) { out.close(); throw new Error('取消了') }
|
|
45
|
+
if (!out.write(chunk)) await new Promise((x) => out.once('drain', x))
|
|
46
|
+
got += chunk.length; prog.got = done + got
|
|
47
|
+
const dt = (Date.now() - t0) / 1000; if (dt > 1) prog.speed = Math.round((got - b0) / dt)
|
|
48
|
+
if (got > f.size) throw new Error('文件比预期大,换个地方下')
|
|
49
|
+
}
|
|
50
|
+
await new Promise((x) => out.end(x))
|
|
51
|
+
} catch (e) { lastErr = e; if (/取消/.test(e.message)) throw e; log('[识别模型] ' + prog.source + ' 没下成:' + e.message + (e.cause ? '(' + (e.cause.code || e.cause.message) + ')' : '')); if (/HTTP 4/.test(e.message)) break }
|
|
52
|
+
}
|
|
53
|
+
const size = fs.existsSync(part) ? fs.statSync(part).size : 0
|
|
54
|
+
if (size === f.size) {
|
|
55
|
+
if ((await sha(part)) === f.sha256) { fs.renameSync(part, dst); return }
|
|
56
|
+
log('[识别模型] ' + prog.source + ' 的 ' + f.name + ' 校验不对,删掉换一个'); fs.rmSync(part, { force: true }); lastErr = new Error('校验不对')
|
|
57
|
+
} else if (size > f.size) fs.rmSync(part, { force: true })
|
|
58
|
+
}
|
|
59
|
+
throw new Error('几个下载地址都没成:' + (lastErr?.message ?? '未知原因'))
|
|
60
|
+
}
|
|
61
|
+
function download() {
|
|
62
|
+
if (ok()) return Promise.resolve()
|
|
63
|
+
if (job) return job.p
|
|
64
|
+
fs.mkdirSync(DIR, { recursive: true }); prog = { got: 0, total: TOTAL, source: null, error: null, speed: 0 }
|
|
65
|
+
job = { cancel: false }
|
|
66
|
+
job.p = (async () => {
|
|
67
|
+
try { let done = 0; for (const f of FILES) { const dst = path.join(DIR, f.name); if (!(fs.existsSync(dst) && fs.statSync(dst).size === f.size)) await fetchOne(f, done); done += f.size; prog.got = done }
|
|
68
|
+
fs.writeFileSync(path.join(DIR, '.verified'), new Date().toISOString()); fs.writeFileSync(CFG, JSON.stringify({ ...cfg(), on: true })) }
|
|
69
|
+
catch (e) { prog.error = e.message; throw e }
|
|
70
|
+
finally { job = null }
|
|
71
|
+
})()
|
|
72
|
+
job.p.catch(() => {})
|
|
73
|
+
return job.p
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
dir: DIR,
|
|
77
|
+
status: () => ({ ready: ok(), on: ok() && cfg().on !== false, downloading: !!job, ...prog, sizeMB: Math.round(TOTAL / 1048576) }),
|
|
78
|
+
download, cancel() { if (job) job.cancel = true },
|
|
79
|
+
setOn(v) { fs.writeFileSync(CFG, JSON.stringify({ ...cfg(), on: !!v })) },
|
|
80
|
+
remove() { if (job) throw new Error('正在下载,先取消'); fs.rmSync(DIR, { recursive: true, force: true }); fs.writeFileSync(CFG, JSON.stringify({ ...cfg(), on: false })) },
|
|
81
|
+
}
|
|
82
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
jsqr.js:jsQR 1.4.0(https://github.com/cozmo/jsQR),Apache License 2.0,原样未改。用于手机扫电脑上鱼Sho 连接器的二维码。
|