@fabianactor/dsh-lil-whale-group-ui 1.9.0 → 1.10.0
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/icon.png +0 -0
- package/lib/client.js +68 -0
- package/lib/index.js +95 -0
- package/locale/en.json +1 -0
- package/locale/zh.json +1 -0
- package/package.json +9 -4
package/icon.png
ADDED
|
Binary file
|
package/lib/client.js
CHANGED
|
@@ -120,6 +120,41 @@ window.__ModuleLoader__.load({
|
|
|
120
120
|
return cachedConfig
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/**
|
|
124
|
+
* 版本:读两个包当前版本;「检查更新」才去问 npm。
|
|
125
|
+
* 两个包必须一起用,所以两条一起显示、一起说"有没有新的"。
|
|
126
|
+
*/
|
|
127
|
+
async function loadVersions() {
|
|
128
|
+
const response = await fetch('/group/api/version', { headers: { accept: 'application/json' } })
|
|
129
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
130
|
+
return await response.json()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function checkUpdates() {
|
|
134
|
+
const response = await fetch('/group/api/check-update', {
|
|
135
|
+
method: 'POST',
|
|
136
|
+
headers: { 'x-llw-panel': '1' },
|
|
137
|
+
})
|
|
138
|
+
const data = await response.json().catch(() => null)
|
|
139
|
+
if (!response.ok) throw new Error(data?.error ?? `HTTP ${response.status}`)
|
|
140
|
+
return data
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** 版本状态 → 一句人话。检查失败要说出原因,不能显示成"已是最新"。 */
|
|
144
|
+
function versionLineOf(state) {
|
|
145
|
+
if (!state) return '还没读到版本'
|
|
146
|
+
if (state.error) return `检查失败:${state.error}`
|
|
147
|
+
const part = (label, side) => {
|
|
148
|
+
if (!side) return `${label} 未知`
|
|
149
|
+
if (side.error) return `${label} ${side.current ?? '未知'}(检查失败:${side.error})`
|
|
150
|
+
if (side.latest == null) return `${label} ${side.current ?? '未知'}`
|
|
151
|
+
if (side.updateAvailable === true) return `${label} ${side.current} → 最新 ${side.latest}`
|
|
152
|
+
if (side.updateAvailable === false) return `${label} ${side.current}(已是最新)`
|
|
153
|
+
return `${label} ${side.current}(最新 ${side.latest},无法比较)`
|
|
154
|
+
}
|
|
155
|
+
return `${part('宿主', state.host)};${part('面板', state.ui)}`
|
|
156
|
+
}
|
|
157
|
+
|
|
123
158
|
/**
|
|
124
159
|
* 名字:默认按成员 id 取。
|
|
125
160
|
* 但同一个人的多段会话会共用一个 id(`lee`),所以如果能拿到这条消息的 `s`,
|
|
@@ -2762,6 +2797,23 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
2762
2797
|
const fileInputs = useRef({})
|
|
2763
2798
|
const [avatarBusy, setAvatarBusy] = useState('')
|
|
2764
2799
|
|
|
2800
|
+
// 版本:进设置页先读当前版本;「检查更新」是显式动作(要联网,不自动跑)。
|
|
2801
|
+
const [versions, setVersions] = useState(null)
|
|
2802
|
+
const [updateState, setUpdateState] = useState(null)
|
|
2803
|
+
const [updateBusy, setUpdateBusy] = useState(false)
|
|
2804
|
+
useEffect(() => {
|
|
2805
|
+
void loadVersions()
|
|
2806
|
+
.then((data) => setVersions(data))
|
|
2807
|
+
.catch(() => setVersions({ error: '连不上宿主,读不到版本' }))
|
|
2808
|
+
}, [])
|
|
2809
|
+
const runCheckUpdate = () => {
|
|
2810
|
+
setUpdateBusy(true)
|
|
2811
|
+
void checkUpdates()
|
|
2812
|
+
.then((data) => setUpdateState(data))
|
|
2813
|
+
.catch((error) => setUpdateState({ error: String(error?.message ?? error) }))
|
|
2814
|
+
.finally(() => setUpdateBusy(false))
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2765
2817
|
const uploadAvatar = (member, file) => {
|
|
2766
2818
|
if (!file) return
|
|
2767
2819
|
if (!/^image\/(png|jpeg|webp)$/.test(file.type)) {
|
|
@@ -2931,6 +2983,22 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
2931
2983
|
: '群里任何人说的话都算未读(除了你自己发的)。'),
|
|
2932
2984
|
),
|
|
2933
2985
|
|
|
2986
|
+
h(SettingsSection, { title: '版本', hint: '两个包必须一起装:宿主 + 面板。版本也一起看。' },
|
|
2987
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginTop: 8, flexWrap: 'wrap' } },
|
|
2988
|
+
h('div', { style: { flex: 1, minWidth: 220, fontSize: 13, lineHeight: '20px', color: 'var(--dsw-alias-label-primary)' } },
|
|
2989
|
+
versionLineOf(updateState ?? versions)),
|
|
2990
|
+
h('button', {
|
|
2991
|
+
onClick: runCheckUpdate,
|
|
2992
|
+
disabled: updateBusy,
|
|
2993
|
+
style: { ...smallBtnStyle, opacity: updateBusy ? 0.6 : 1 },
|
|
2994
|
+
}, updateBusy ? '检查中…' : '检查更新'),
|
|
2995
|
+
),
|
|
2996
|
+
updateState?.checkedAt
|
|
2997
|
+
? h('div', { style: { fontSize: 12, lineHeight: '18px', color: 'var(--dsw-alias-label-tertiary)', marginTop: 6 } },
|
|
2998
|
+
`检查时间:${String(updateState.checkedAt).replace('T', ' ').slice(0, 19)}`)
|
|
2999
|
+
: null,
|
|
3000
|
+
),
|
|
3001
|
+
|
|
2934
3002
|
h('div', {
|
|
2935
3003
|
style: { marginTop: 16, fontSize: 12, lineHeight: '18px', color: 'var(--dsw-alias-label-tertiary)' },
|
|
2936
3004
|
}, status || '改动会自动保存。侧边栏名称要刷新页面才变。'),
|
package/lib/index.js
CHANGED
|
@@ -10,6 +10,8 @@ import { join } from 'node:path'
|
|
|
10
10
|
import { createHash } from 'node:crypto'
|
|
11
11
|
import { spawn } from 'node:child_process'
|
|
12
12
|
import { Socket } from 'node:net'
|
|
13
|
+
import { fileURLToPath } from 'node:url'
|
|
14
|
+
import { createRequire } from 'node:module'
|
|
13
15
|
import { config } from './config.js'
|
|
14
16
|
|
|
15
17
|
export const name = '@fabianactor/dsh-lil-whale-group-ui'
|
|
@@ -56,6 +58,61 @@ const IMAGE_EXT = { png: 'image/png', jpg: 'image/jpeg', webp: 'image/webp', gif
|
|
|
56
58
|
const IMAGE_FMT = 2
|
|
57
59
|
const IMAGE_ALGO = 'sha256'
|
|
58
60
|
|
|
61
|
+
// 版本:设置页要显示「当前版本」并检查 npm 上的最新版。
|
|
62
|
+
// 当前版本从两个包自己的 package.json 读(ui 就是自己;host 走模块解析,
|
|
63
|
+
// 解析不到再按同 scope 的兄弟目录找)——不写死数字,免得代码和 package.json 各说各话。
|
|
64
|
+
const UI_PACKAGE = JSON.parse(readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8'))
|
|
65
|
+
const HOST_PACKAGE_NAME = '@fabianactor/dsh-lil-whale-group'
|
|
66
|
+
|
|
67
|
+
function hostPackageVersion() {
|
|
68
|
+
try {
|
|
69
|
+
const req = createRequire(import.meta.url)
|
|
70
|
+
const file = req.resolve(HOST_PACKAGE_NAME + '/package.json')
|
|
71
|
+
return JSON.parse(readFileSync(file, 'utf8')).version ?? null
|
|
72
|
+
} catch {
|
|
73
|
+
try {
|
|
74
|
+
return JSON.parse(readFileSync(fileURLToPath(new URL('../../dsh-lil-whale-group/package.json', import.meta.url)), 'utf8')).version ?? null
|
|
75
|
+
} catch {
|
|
76
|
+
return null
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function versionState() {
|
|
82
|
+
return {
|
|
83
|
+
host: { name: HOST_PACKAGE_NAME, current: hostPackageVersion() },
|
|
84
|
+
ui: { name: UI_PACKAGE.name, current: UI_PACKAGE.version ?? null },
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** 只比 x.y.z 的数字段;预发布标签(-rc.1)忽略——给人看的是版本,不是 semver 全集。 */
|
|
89
|
+
function newerThan(latest, current) {
|
|
90
|
+
if (!latest || !current) return null
|
|
91
|
+
const a = String(latest).split('-')[0].split('.').map((n) => Number(n) || 0)
|
|
92
|
+
const b = String(current).split('-')[0].split('.').map((n) => Number(n) || 0)
|
|
93
|
+
for (let i = 0; i < 3; i += 1) {
|
|
94
|
+
if ((a[i] ?? 0) > (b[i] ?? 0)) return true
|
|
95
|
+
if ((a[i] ?? 0) < (b[i] ?? 0)) return false
|
|
96
|
+
}
|
|
97
|
+
return false
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function latestOnNpm(packageName) {
|
|
101
|
+
const controller = new AbortController()
|
|
102
|
+
const timer = setTimeout(() => controller.abort(), 8000)
|
|
103
|
+
try {
|
|
104
|
+
const response = await fetch(`https://registry.npmjs.org/${packageName.replace('/', '%2F')}/latest`, {
|
|
105
|
+
signal: controller.signal,
|
|
106
|
+
headers: { accept: 'application/json' },
|
|
107
|
+
})
|
|
108
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
109
|
+
const data = await response.json()
|
|
110
|
+
return typeof data?.version === 'string' ? data.version : null
|
|
111
|
+
} finally {
|
|
112
|
+
clearTimeout(timer)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
59
116
|
/**
|
|
60
117
|
* 读不到的图片必须留痕,否则"没有图"和"图丢了"看起来一样(小肥鱼的原话:
|
|
61
118
|
* 校验的价值不在拦住坏路径,在让坏路径有痕迹)。
|
|
@@ -877,6 +934,44 @@ export function apply(ctx) {
|
|
|
877
934
|
},
|
|
878
935
|
}))
|
|
879
936
|
|
|
937
|
+
// 版本:当前版本随时能看;「检查更新」才去问 npm。
|
|
938
|
+
// 网络不通要说清楚,不能装成"已是最新"——那和真的检查过长得一样(§60)。
|
|
939
|
+
disposers.push(ctx.webServer.register({
|
|
940
|
+
kind: 'exact',
|
|
941
|
+
path: '/group/api/version',
|
|
942
|
+
handler(req, res) {
|
|
943
|
+
if (req.method !== 'GET') {
|
|
944
|
+
sendJson(res, 405, { error: 'method-not-allowed' })
|
|
945
|
+
return
|
|
946
|
+
}
|
|
947
|
+
sendJson(res, 200, versionState())
|
|
948
|
+
},
|
|
949
|
+
}))
|
|
950
|
+
|
|
951
|
+
disposers.push(ctx.webServer.register({
|
|
952
|
+
kind: 'exact',
|
|
953
|
+
path: '/group/api/check-update',
|
|
954
|
+
async handler(req, res) {
|
|
955
|
+
if (!guardWrite(req, res, '/group/api/check-update')) return
|
|
956
|
+
if (req.method !== 'POST') {
|
|
957
|
+
sendJson(res, 405, { error: 'method-not-allowed' })
|
|
958
|
+
return
|
|
959
|
+
}
|
|
960
|
+
const base = versionState()
|
|
961
|
+
const result = { checkedAt: new Date().toISOString(), host: { ...base.host }, ui: { ...base.ui } }
|
|
962
|
+
for (const side of ['host', 'ui']) {
|
|
963
|
+
try {
|
|
964
|
+
const latest = await latestOnNpm(result[side].name)
|
|
965
|
+
result[side].latest = latest
|
|
966
|
+
result[side].updateAvailable = newerThan(latest, result[side].current)
|
|
967
|
+
} catch (error) {
|
|
968
|
+
result[side].error = String(error?.message ?? error)
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
sendJson(res, 200, result)
|
|
972
|
+
},
|
|
973
|
+
}))
|
|
974
|
+
|
|
880
975
|
/**
|
|
881
976
|
* 头像照片:读一张、换一张、去掉。
|
|
882
977
|
*
|
package/locale/en.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"lil-whale panel","description":"Sidebar panel for the lil-whale group: group chat, DMs, unread badges, images and a pond page that starts and stops each agent. Requires the host package @fabianactor/dsh-lil-whale-group."}}
|
package/locale/zh.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"小小肥鱼 · 面板","description":"侧边栏面板:群聊、私聊、未读红点、图片,以及开关每条鱼的鱼塘页。需同时安装宿主包 @fabianactor/dsh-lil-whale-group。"}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabianactor/dsh-lil-whale-group-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "群聊页面:侧边栏一个图标,点开是三条鱼的群(读写 lil-whale\\group\\messages.jsonl)",
|
|
6
6
|
"author": "Fabian",
|
|
@@ -25,11 +25,15 @@
|
|
|
25
25
|
},
|
|
26
26
|
"exports": {
|
|
27
27
|
".": "./lib/index.js",
|
|
28
|
-
"./client": "./lib/client.js"
|
|
28
|
+
"./client": "./lib/client.js",
|
|
29
|
+
"./package.json": "./package.json",
|
|
30
|
+
"./locale/*": "./locale/*"
|
|
29
31
|
},
|
|
30
32
|
"files": [
|
|
31
33
|
"lib/*.js",
|
|
32
|
-
"cordis.patch.yml"
|
|
34
|
+
"cordis.patch.yml",
|
|
35
|
+
"icon.png",
|
|
36
|
+
"locale"
|
|
33
37
|
],
|
|
34
38
|
"dsh": {
|
|
35
39
|
"bundle": {
|
|
@@ -42,5 +46,6 @@
|
|
|
42
46
|
"@deepseek-ai/dsh-client-ui-primitives"
|
|
43
47
|
]
|
|
44
48
|
}
|
|
45
|
-
}
|
|
49
|
+
},
|
|
50
|
+
"icon": "icon.png"
|
|
46
51
|
}
|