@fabianactor/dsh-lil-whale-group-ui 1.12.1 → 1.12.3
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/lib/client.js +53 -20
- package/lib/index.js +22 -27
- package/lib/version-core.js +45 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -121,7 +121,7 @@ window.__ModuleLoader__.load({
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
|
-
* 版本:读两个包当前版本;「检查更新」才去问
|
|
124
|
+
* 版本:读两个包当前版本;「检查更新」才去问 GitHub Releases。
|
|
125
125
|
* 两个包必须一起用,所以两条一起显示、一起说"有没有新的"。
|
|
126
126
|
*/
|
|
127
127
|
async function loadVersions() {
|
|
@@ -967,13 +967,17 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
967
967
|
|
|
968
968
|
async function markRead(channel, peer) {
|
|
969
969
|
try {
|
|
970
|
-
await fetch('/group/api/read', {
|
|
970
|
+
const response = await fetch('/group/api/read', {
|
|
971
971
|
method: 'POST',
|
|
972
972
|
headers: { 'content-type': 'application/json', 'x-llw-panel': '1' },
|
|
973
973
|
body: JSON.stringify({ channel, peer }),
|
|
974
974
|
})
|
|
975
|
+
// 2026-11-19(Fabian 报"红点清了又回来"):以前不看 response.ok,
|
|
976
|
+
// 403/500 也当读过了。返回值给调用方,失败才谈得上重试。
|
|
977
|
+
return response.ok
|
|
975
978
|
} catch {
|
|
976
979
|
// 清不掉就继续亮着,比假装看过好
|
|
980
|
+
return false
|
|
977
981
|
}
|
|
978
982
|
}
|
|
979
983
|
|
|
@@ -1755,7 +1759,9 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
1755
1759
|
multiple: true,
|
|
1756
1760
|
style: { display: 'none' },
|
|
1757
1761
|
onChange: (event) => {
|
|
1758
|
-
|
|
1762
|
+
// FileList 是活的:先摘出文件再清 value。反过来会把 files 清空——
|
|
1763
|
+
// 2026-11-20 他报:点按钮选图选得动、但图不进输入框;拖入正常(拖入不走这个 input)。
|
|
1764
|
+
const files = Array.from(event.target.files ?? [])
|
|
1759
1765
|
event.target.value = ''
|
|
1760
1766
|
void attachImages(files)
|
|
1761
1767
|
},
|
|
@@ -2119,8 +2125,11 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
2119
2125
|
|
|
2120
2126
|
// 贴底了就把"回到历史未读"收掉:人已经看见最新的了,留着只剩误导。
|
|
2121
2127
|
// 2026-11-17 第 2 条:清完红点后来新消息,长消息把分割线顶出视口上沿,提示又亮。
|
|
2128
|
+
// 2026-11-19 第 3 条:贴底时提示消失、稍一上滑又出现——"到底"本身就是"已经见过这截"的证据,
|
|
2129
|
+
// 记进 historyVisitedRef;之后同一根线不再亮,等读完一批(markRead)才放行。
|
|
2122
2130
|
useEffect(() => {
|
|
2123
2131
|
if (!atBottom) return
|
|
2132
|
+
historyVisitedRef.current = true
|
|
2124
2133
|
if (historyAboveRef.current) { historyAboveRef.current = false; setHistoryAbove(false) }
|
|
2125
2134
|
}, [atBottom])
|
|
2126
2135
|
|
|
@@ -2158,21 +2167,39 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
2158
2167
|
// 看过 1.5 秒才算读过:让红点有出现的余地,也不至于一闪就没。
|
|
2159
2168
|
// 依赖里必须有 atBottom:翻历史回到底部的那一下才是"看见了";
|
|
2160
2169
|
// 以前少了它,读完了未读也不清(2026-11-15 第 5 条)。
|
|
2170
|
+
// 2026-11-19(Fabian 报"切走再回来红点又出现"):两个坑补上——
|
|
2171
|
+
// ①定时器被 clearTimeout 吞掉:1.5 秒内切走/离开页面,这次"读完"永远不会记;
|
|
2172
|
+
// ②markRead 失败没人重试,而依赖不变,effect 不会再来一遍。
|
|
2173
|
+
const groupReadTimerRef = useRef(null)
|
|
2174
|
+
const finishGroupRead = useCallback(() => {
|
|
2175
|
+
groupReadTimerRef.current = null
|
|
2176
|
+
void markRead('group').then((ok) => {
|
|
2177
|
+
if (!ok) {
|
|
2178
|
+
// 服务端没记上:五秒后再来一次,别让"清不掉"沉成"以为清掉了"。
|
|
2179
|
+
groupReadTimerRef.current = setTimeout(finishGroupRead, 5000)
|
|
2180
|
+
return
|
|
2181
|
+
}
|
|
2182
|
+
historyVisitedRef.current = false
|
|
2183
|
+
// 读完一批后分割线会挪到新位置:立刻重量,别等下一次滚动。
|
|
2184
|
+
measureHistory()
|
|
2185
|
+
refresh()
|
|
2186
|
+
// 面板读完一批,喊一声;侧边栏红点不用等下一轮轮询。
|
|
2187
|
+
window.dispatchEvent(new Event('dsh-group-read'))
|
|
2188
|
+
})
|
|
2189
|
+
}, [refresh, measureHistory])
|
|
2161
2190
|
useEffect(() => {
|
|
2162
|
-
if (tab !== 'group' || unread.group === 0 || !atBottom) return
|
|
2163
|
-
if (typeof document !== 'undefined' && document.visibilityState !== 'visible') return
|
|
2164
|
-
const timer = setTimeout(
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
return () => clearTimeout(timer)
|
|
2175
|
-
}, [tab, unread.group, refresh, atBottom])
|
|
2191
|
+
if (tab !== 'group' || unread.group === 0 || !atBottom) return undefined
|
|
2192
|
+
if (typeof document !== 'undefined' && document.visibilityState !== 'visible') return undefined
|
|
2193
|
+
const timer = setTimeout(finishGroupRead, 1500)
|
|
2194
|
+
groupReadTimerRef.current = timer
|
|
2195
|
+
return () => {
|
|
2196
|
+
// 切 tab / 离开页面:先把这次"读完"记上,再让定时器走开。
|
|
2197
|
+
clearTimeout(timer)
|
|
2198
|
+
if (groupReadTimerRef.current !== timer) return
|
|
2199
|
+
groupReadTimerRef.current = null
|
|
2200
|
+
void markRead('group')
|
|
2201
|
+
}
|
|
2202
|
+
}, [tab, unread.group, refresh, atBottom, finishGroupRead])
|
|
2176
2203
|
// 翻历史时底下来了新消息:只数"最后一条之后新增了几条",回到底部就清零。
|
|
2177
2204
|
// 不用未读数(未读是服务器口径,可能包含别的窗口看过的,不能当"你还没看"的证据)。
|
|
2178
2205
|
const lastSeenTsRef = useRef('')
|
|
@@ -2414,7 +2441,9 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
2414
2441
|
},
|
|
2415
2442
|
},
|
|
2416
2443
|
item.key === 'group'
|
|
2417
|
-
|
|
2444
|
+
// 2026-11-19:以前"在群聊且贴底"就把计数藏起来,看着像清了;
|
|
2445
|
+
// 切到别的页又照实显示。现在只信服务端给的数,"清了"就等于真清了。
|
|
2446
|
+
? (unread.group > 0 ? item.label + ' (' + unread.group + ')' : item.label)
|
|
2418
2447
|
: item.key === 'dm'
|
|
2419
2448
|
? (dmTotal(unread) > 0 ? item.label + ' (' + dmTotal(unread) + ')' : item.label)
|
|
2420
2449
|
: item.label,
|
|
@@ -2707,7 +2736,9 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
2707
2736
|
multiple: true,
|
|
2708
2737
|
style: { display: 'none' },
|
|
2709
2738
|
onChange: (event) => {
|
|
2710
|
-
|
|
2739
|
+
// FileList 是活的:先摘出文件再清 value。反过来会把 files 清空——
|
|
2740
|
+
// 2026-11-20 他报:点按钮选图选得动、但图不进输入框;拖入正常(拖入不走这个 input)。
|
|
2741
|
+
const files = Array.from(event.target.files ?? [])
|
|
2711
2742
|
event.target.value = ''
|
|
2712
2743
|
void attachImages(files)
|
|
2713
2744
|
},
|
|
@@ -3081,6 +3112,8 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
3081
3112
|
: null,
|
|
3082
3113
|
),
|
|
3083
3114
|
|
|
3115
|
+
h('div', { style: { fontSize: 12, lineHeight: '18px', color: 'var(--dsw-alias-label-tertiary)', marginTop: 6 } },
|
|
3116
|
+
'查的是 GitHub Releases;npm 上只有两块 bundle,安装与更新请走仓库。'),
|
|
3084
3117
|
h('div', {
|
|
3085
3118
|
style: { marginTop: 16, fontSize: 12, lineHeight: '18px', color: 'var(--dsw-alias-label-tertiary)' },
|
|
3086
3119
|
}, status || '改动会自动保存。侧边栏名称要刷新页面才变。'),
|
|
@@ -3800,7 +3833,7 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
3800
3833
|
inject: ['slots'],
|
|
3801
3834
|
apply(ctx) {
|
|
3802
3835
|
// 一行"我跑的是哪一版"的自报,方便判断浏览器是不是还在用旧 bundle
|
|
3803
|
-
console.info('[dsh-lil-whale-group-ui] client build
|
|
3836
|
+
console.info('[dsh-lil-whale-group-ui] client build v57 · image-picker-files:', Object.keys(MARKDOWN_LABELS).join(','))
|
|
3804
3837
|
// 「正在回复…」那三个点的呼吸动画 + 过场转圈。只在浏览器里注入一次。
|
|
3805
3838
|
if (typeof document !== 'undefined' && !document.getElementById('dsh-lil-whale-group-keyframes')) {
|
|
3806
3839
|
const style = document.createElement('style')
|
package/lib/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import { createRequire } from 'node:module'
|
|
|
15
15
|
import { config } from './config.js'
|
|
16
16
|
import { parseMessageLines } from './messages-core.js'
|
|
17
17
|
import { presenceReasonOf } from './presence-core.js'
|
|
18
|
+
import { newerThan, latestReleaseOf, LATEST_RELEASE_API } from './version-core.js'
|
|
18
19
|
|
|
19
20
|
export const name = '@fabianactor/dsh-lil-whale-group-ui'
|
|
20
21
|
export const inject = ['webServer', 'agents']
|
|
@@ -60,7 +61,7 @@ const IMAGE_EXT = { png: 'image/png', jpg: 'image/jpeg', webp: 'image/webp', gif
|
|
|
60
61
|
const IMAGE_FMT = 2
|
|
61
62
|
const IMAGE_ALGO = 'sha256'
|
|
62
63
|
|
|
63
|
-
// 版本:设置页要显示「当前版本」并检查
|
|
64
|
+
// 版本:设置页要显示「当前版本」并检查 GitHub Releases 上的最新版。
|
|
64
65
|
// 当前版本从两个包自己的 package.json 读(ui 就是自己;host 走模块解析,
|
|
65
66
|
// 解析不到再按同 scope 的兄弟目录找)——不写死数字,免得代码和 package.json 各说各话。
|
|
66
67
|
const UI_PACKAGE = JSON.parse(readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8'))
|
|
@@ -87,34 +88,21 @@ function versionState() {
|
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
|
|
91
|
-
function newerThan(latest, current) {
|
|
92
|
-
if (!latest || !current) return null
|
|
93
|
-
const a = String(latest).split('-')[0].split('.').map((n) => Number(n) || 0)
|
|
94
|
-
const b = String(current).split('-')[0].split('.').map((n) => Number(n) || 0)
|
|
95
|
-
for (let i = 0; i < 3; i += 1) {
|
|
96
|
-
if ((a[i] ?? 0) > (b[i] ?? 0)) return true
|
|
97
|
-
if ((a[i] ?? 0) < (b[i] ?? 0)) return false
|
|
98
|
-
}
|
|
99
|
-
return false
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async function latestOnNpm(packageName) {
|
|
91
|
+
async function latestReleaseOnGitHub() {
|
|
103
92
|
const controller = new AbortController()
|
|
104
93
|
const timer = setTimeout(() => controller.abort(), 8000)
|
|
105
94
|
try {
|
|
106
|
-
const response = await fetch(
|
|
95
|
+
const response = await fetch(LATEST_RELEASE_API, {
|
|
107
96
|
signal: controller.signal,
|
|
108
|
-
headers: { accept:
|
|
97
|
+
headers: { accept: "application/vnd.github+json", "user-agent": "dsh-lil-whale-panel" },
|
|
109
98
|
})
|
|
110
99
|
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
111
100
|
const data = await response.json()
|
|
112
|
-
return
|
|
101
|
+
return latestReleaseOf(data)
|
|
113
102
|
} finally {
|
|
114
103
|
clearTimeout(timer)
|
|
115
104
|
}
|
|
116
105
|
}
|
|
117
|
-
|
|
118
106
|
/**
|
|
119
107
|
* 读不到的图片必须留痕,否则"没有图"和"图丢了"看起来一样(小肥鱼的原话:
|
|
120
108
|
* 校验的价值不在拦住坏路径,在让坏路径有痕迹)。
|
|
@@ -914,7 +902,7 @@ export function apply(ctx) {
|
|
|
914
902
|
},
|
|
915
903
|
}))
|
|
916
904
|
|
|
917
|
-
// 版本:当前版本随时能看;「检查更新」才去问 npm
|
|
905
|
+
// 版本:当前版本随时能看;「检查更新」才去问 GitHub Releases(npm 只作镜像,不再当渠道)。
|
|
918
906
|
// 网络不通要说清楚,不能装成"已是最新"——那和真的检查过长得一样(§60)。
|
|
919
907
|
disposers.push(ctx.webServer.register({
|
|
920
908
|
kind: 'exact',
|
|
@@ -938,14 +926,21 @@ export function apply(ctx) {
|
|
|
938
926
|
return
|
|
939
927
|
}
|
|
940
928
|
const base = versionState()
|
|
941
|
-
const result = { checkedAt: new Date().toISOString(), host: { ...base.host }, ui: { ...base.ui } }
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
929
|
+
const result = { checkedAt: new Date().toISOString(), source: "github-releases", host: { ...base.host }, ui: { ...base.ui } }
|
|
930
|
+
// 两个包同一个仓库、同一条 Release:查一次就够,别各查一次(结果不一致时还得分谁对)。
|
|
931
|
+
let release = null
|
|
932
|
+
let releaseError = null
|
|
933
|
+
try {
|
|
934
|
+
release = await latestReleaseOnGitHub()
|
|
935
|
+
} catch (error) {
|
|
936
|
+
releaseError = String(error?.message ?? error)
|
|
937
|
+
}
|
|
938
|
+
for (const side of ["host", "ui"]) {
|
|
939
|
+
if (release) {
|
|
940
|
+
result[side].latest = release.version
|
|
941
|
+
result[side].updateAvailable = newerThan(release.version, result[side].current)
|
|
942
|
+
} else {
|
|
943
|
+
result[side].error = releaseError
|
|
949
944
|
}
|
|
950
945
|
}
|
|
951
946
|
sendJson(res, 200, result)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 「有没有新版本」的纯计算:读 GitHub Releases 的 tag、比版本号。
|
|
3
|
+
*
|
|
4
|
+
* 为什么数据源从 npm 换成 GitHub(2026-11-20,Fabian 定的口径):
|
|
5
|
+
* npm 上只有两块 bundle,缺 pool\homes\模板\启动脚本——只从 npm 装出来的鱼塘跑不起来
|
|
6
|
+
* (面板会显示「没装完整」,写接口回 409)。所以 npm 从"安装/更新渠道"降级成镜像;
|
|
7
|
+
* 唯一可信的更新来源是 GitHub 仓库与它的 Releases。设置页的「检查更新」跟着改查 Releases,
|
|
8
|
+
* 不然以后不再拿 npm 当渠道时,那个按钮会永远显示"已是最新"。
|
|
9
|
+
*
|
|
10
|
+
* 这里只做纯计算(不联网):tag 解析、版本比较。网络与超时在 index.js 里。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** 仓库:唯一安装与更新来源。 */
|
|
14
|
+
export const REPO = 'FabianActor/dsh-lil-whale'
|
|
15
|
+
|
|
16
|
+
/** Releases API:最新一条正式 Release。预发布(prerelease)不算。 */
|
|
17
|
+
export const LATEST_RELEASE_API = `https://api.github.com/repos/${REPO}/releases/latest`
|
|
18
|
+
|
|
19
|
+
/** `v1.12.2` → `1.12.2`;认不出的 tag 返回 null(不猜)。 */
|
|
20
|
+
export function versionFromTag(tag) {
|
|
21
|
+
const text = String(tag ?? '').trim().replace(/^v/i, '')
|
|
22
|
+
return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(text) ? text : null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 只比 x.y.z 的数字段;预发布标签(-rc.1)忽略——给人看的是版本,不是 semver 全集。 */
|
|
26
|
+
export function newerThan(latest, current) {
|
|
27
|
+
if (!latest || !current) return null
|
|
28
|
+
const a = String(latest).split('-')[0].split('.').map((n) => Number(n) || 0)
|
|
29
|
+
const b = String(current).split('-')[0].split('.').map((n) => Number(n) || 0)
|
|
30
|
+
for (let i = 0; i < 3; i += 1) {
|
|
31
|
+
if ((a[i] ?? 0) > (b[i] ?? 0)) return true
|
|
32
|
+
if ((a[i] ?? 0) < (b[i] ?? 0)) return false
|
|
33
|
+
}
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Releases API 的 JSON → 最新版本号。
|
|
39
|
+
* 读不出 tag 就抛错:宁可让面板写"查不到原因",也不要装成"已是最新"(§60)。
|
|
40
|
+
*/
|
|
41
|
+
export function latestReleaseOf(json) {
|
|
42
|
+
const version = versionFromTag(json?.tag_name)
|
|
43
|
+
if (!version) throw new Error(`Release 里没有能读的 tag_name:${JSON.stringify(json?.tag_name ?? null)}`)
|
|
44
|
+
return { version, tag: String(json.tag_name), url: typeof json?.html_url === 'string' ? json.html_url : null }
|
|
45
|
+
}
|