dsh-gallery 0.10.6 → 0.11.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/CHANGELOG.md +90 -0
- package/README.md +26 -5
- package/client.js +86 -159
- package/index.js +136 -50
- package/locale/en.json +6 -6
- package/locale/zh.json +6 -6
- package/package.json +7 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,96 @@
|
|
|
2
2
|
|
|
3
3
|
本项目遵循[语义化版本](https://semver.org/lang/zh-CN/)。
|
|
4
4
|
|
|
5
|
+
## [0.11.0] - 2026-11-08
|
|
6
|
+
|
|
7
|
+
**主题:媒体播放换成真 HTTP Range —— 大视频也能拖进度条了。**
|
|
8
|
+
|
|
9
|
+
### 根本改动:路由 API 从 `connection.fetch` 换成 `webServer`
|
|
10
|
+
|
|
11
|
+
之前(0.10.x)的判断是「DSH 的 HTTP 通道不支持 206」,于是退而求其次:
|
|
12
|
+
≤60 MB 用 blob 播放(能拖但占内存)、>60 MB 引导用系统播放器。
|
|
13
|
+
|
|
14
|
+
**那个判断是错的** —— 不是 DSH 不支持 206,是**用错了 API**:
|
|
15
|
+
|
|
16
|
+
| API | 参数 | 206 支持 |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| `ctx.connection.fetch.register` | Web Fetch API(`Request`/`Response`) | ❌ 网关层不透传 |
|
|
19
|
+
| **`ctx.webServer.register`** | **Node 原生 `(req, res)`** | ✅ **完全支持** |
|
|
20
|
+
|
|
21
|
+
探针实测确认(12 项全过):HEAD 200 / `bytes=0-1023` → 206 / 中段 → 206 /
|
|
22
|
+
后缀 `bytes=-1024` → 206。
|
|
23
|
+
|
|
24
|
+
### 结果对比
|
|
25
|
+
|
|
26
|
+
| | 0.10.7 | **0.11.0** |
|
|
27
|
+
|---|---|---|
|
|
28
|
+
| 127 MB 视频 | ❌ 只能外部打开 | ✅ **面板内直接播 + 拖进度条** |
|
|
29
|
+
| 拖进度条 | ✅ 仅 ≤60 MB | ✅ **任意大小** |
|
|
30
|
+
| 内存占用 | 等于文件大小(blob) | **恒定几 MB**(流式) |
|
|
31
|
+
| 点开的等待 | 等整个文件载入 | **立即开播**(只拉首段) |
|
|
32
|
+
|
|
33
|
+
### 安全(三道防护)
|
|
34
|
+
|
|
35
|
+
媒体路由独立注册、不经 `/api` 网关认证,所以必须自己防护:
|
|
36
|
+
|
|
37
|
+
1. **只读** —— GET / HEAD,其余 405
|
|
38
|
+
2. **跨站拒绝** —— `sec-fetch-site: cross-site` 或 origin/host 不匹配 → 403
|
|
39
|
+
3. **路径白名单** —— 必须落在扫描 `roots` 内,否则能读任意文件
|
|
40
|
+
4. 附带 `x-content-type-options: nosniff`
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## [0.10.7] - 2026-11-08
|
|
45
|
+
|
|
46
|
+
统一更新音视频说明:`package.json` description、`locale` 中英双语 meta、
|
|
47
|
+
README 新增「音视频画廊」章节、版本 badge 0.7.2 → 0.10.7。
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## [0.10.6] - 2026-11-08
|
|
52
|
+
|
|
53
|
+
### 修复
|
|
54
|
+
|
|
55
|
+
- **媒体文件 404**:`resolveReadable` 用**图片的 64 MB 上限**卡音视频,
|
|
56
|
+
127 MB 视频被判「不可读」→ 前端收到 404,「打开所在文件夹」点了没反应。
|
|
57
|
+
修法:`resolveReadable` 加 `byteCap` 参数,媒体传 `maxMediaBytes`(200 MB)。
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## [0.10.5] - 2026-11-08
|
|
62
|
+
|
|
63
|
+
### 修复
|
|
64
|
+
|
|
65
|
+
- **「打开所在文件夹」点了没反应**:`spawn('explorer.exe', ['/select,<中文路径>'])`
|
|
66
|
+
对**含中文的路径**会静默以退出码 1 失败。实测对比确认后改用
|
|
67
|
+
`cmd /c start "" explorer.exe /select,"<path>"`,退出码 0,正常。
|
|
68
|
+
- 客户端把失败原因**显示出来**(以前是 `.catch(e => console.error(...))` 静默吞掉)。
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## [0.10.4] - 2026-11-08
|
|
73
|
+
|
|
74
|
+
### 新增 / 修复
|
|
75
|
+
|
|
76
|
+
- 大文件提示加「📂 打开所在文件夹」按钮(与「▶ 用系统播放器打开」并列)。
|
|
77
|
+
- 修按钮显示为灰色不可点:原来的 `dg-btn` / `dg-primaryBtn` 在媒体弹层里
|
|
78
|
+
没有对应样式,改成独立定义的 `.dg-mediaActBtn` / `.dg-mediaActPrimary`。
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## [0.10.3] - 2026-11-08
|
|
83
|
+
|
|
84
|
+
### 修复 / 新增
|
|
85
|
+
|
|
86
|
+
- **播放器「浏览器无法解码该格式」**:GET 路由**缺 HEAD 方法** ——
|
|
87
|
+
浏览器加载媒体前会先发 HEAD 探测,只给 GET 就被判为不可解码。
|
|
88
|
+
同时补 `requestBody: 'buffered'`(与官方 `/api/file` 一致)。
|
|
89
|
+
- **Blob 分档播放**:≤60 MB 完整载入内存(能拖进度条),>60 MB 引导外部打开。
|
|
90
|
+
- **截取当前帧**:播放时一键把当前画面存成 PNG,文件名带时间码。
|
|
91
|
+
- 文件名高对比显示(原来用了未定义的 CSS 变量,显示很暗像没渲染)。
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
5
95
|
## [0.10.2] - 2026-11-08
|
|
6
96
|
|
|
7
97
|
**主题:修 v0.10.1 音视频画廊的两个渲染 bug。**
|
package/README.md
CHANGED
|
@@ -4,16 +4,17 @@
|
|
|
4
4
|
> DSH 默认**只在任务结束时**才列出产出的文件名和路径 —— 中间生成的东西你看不见,
|
|
5
5
|
> 出了偏差只能等它跑完再返工。
|
|
6
6
|
>
|
|
7
|
-
>
|
|
7
|
+
> 这个插件把产出目录变成右侧栏里的**实时画廊**:图片生成就可见、文件点开就预览、
|
|
8
|
+
> 视频音频能在面板里直接播放并拖进度条,
|
|
8
9
|
> **让你在任务进行中就能校验和干预,而不是结束后才知道做错了。**
|
|
9
10
|
|
|
10
|
-
[](#)
|
|
11
12
|
[](LICENSE)
|
|
12
13
|
[](#技术说明给想改代码的人)
|
|
13
14
|
[](#兼容性)
|
|
14
15
|
[](#)
|
|
15
16
|
|
|
16
|
-
**关键词**:DeepSeek Harness 插件 · DSH plugin · 产出画廊 · output gallery · 图片画廊 · image gallery · 文件预览 · file preview · 侧边栏面板 · sidebar panel · Agent 产出管理 · output artifacts
|
|
17
|
+
**关键词**:DeepSeek Harness 插件 · DSH plugin · 产出画廊 · output gallery · 图片画廊 · image gallery · 文件预览 · file preview · **音视频画廊 · media gallery · 视频预览 · video preview** · 侧边栏面板 · sidebar panel · Agent 产出管理 · output artifacts
|
|
17
18
|
|
|
18
19
|
---
|
|
19
20
|
|
|
@@ -81,7 +82,27 @@
|
|
|
81
82
|
| 点「⧉ 复制路径」 | 复制绝对路径,按钮变 `✓ 已复制` 反馈 1.6 秒 |
|
|
82
83
|
| 点「📂」 | 在资源管理器里定位该文件 |
|
|
83
84
|
|
|
84
|
-
###
|
|
85
|
+
### 音视频画廊
|
|
86
|
+
|
|
87
|
+
列视频 / 音频,共 16 种扩展名(视频 7 种、音频 9 种),**独立第三栏**,不混进文件列表。
|
|
88
|
+
|
|
89
|
+
| 操作 | 行为 |
|
|
90
|
+
|---|---|
|
|
91
|
+
| 点整张卡片 | 在面板内弹出播放器 |
|
|
92
|
+
| 视频卡片 | 显示**首帧缩略图**(进入视口才抽帧,避免一次解码几十个视频) |
|
|
93
|
+
| **拖进度条** | ✅ **任意大小的文件都能拖** —— 宿主用 HTTP Range(206)分片下发 |
|
|
94
|
+
| **边下边播** | ✅ 不预先载入整个文件,点开几乎立即开始 |
|
|
95
|
+
| 播放器里「📷 截取当前帧」 | 把当前画面存成 PNG,文件名带时间码(如 `片子_00-12-34.png`) |
|
|
96
|
+
| 浏览器解不了格式 | 显示提示 +「▶ 用系统播放器打开」/「📂 打开所在文件夹」两个按钮 |
|
|
97
|
+
|
|
98
|
+
> **技术说明**:媒体路由用 `ctx.webServer.register` 注册(Node 原生 `req`/`res`),
|
|
99
|
+
> 支持 `Range: bytes=...` 的常规区间、开放区间、后缀区间,以及 416 不可满足。
|
|
100
|
+
> 这样浏览器才能边下边播、任意 seek,**127 MB 的视频也能在面板里直接拖动查看**,
|
|
101
|
+
> 内存占用与文件大小无关(流式下发)。
|
|
102
|
+
>
|
|
103
|
+
> 体积上限默认 200 MB,可用 `maxMediaBytes` 调整。
|
|
104
|
+
|
|
105
|
+
### 右键菜单(图片 / 文件 / 音视频通用)
|
|
85
106
|
|
|
86
107
|
在任意卡片上**右键**:
|
|
87
108
|
|
|
@@ -96,7 +117,7 @@
|
|
|
96
117
|
|
|
97
118
|
### 分页
|
|
98
119
|
|
|
99
|
-
|
|
120
|
+
三个画廊都是**每页 60 条**,网格下方**常驻页码条**:
|
|
100
121
|
|
|
101
122
|
```
|
|
102
123
|
第 1–60 条 · 共 114 条 还有 54 张
|
package/client.js
CHANGED
|
@@ -19,8 +19,7 @@ window.__ModuleLoader__.load({
|
|
|
19
19
|
const IMAGE_EXTS = ['.png', '.jpg', '.jpeg', '.webp', '.gif', '.bmp']
|
|
20
20
|
/** 视频扩展名(客户端判断 mediaType 兜底用,与 Host 的 VIDEO_EXTS 保持一致)。 */
|
|
21
21
|
const VIDEO_EXTS_CLIENT = new Set(['.mp4', '.webm', '.mov', '.m4v', '.mkv', '.avi', '.ogv'])
|
|
22
|
-
|
|
23
|
-
const BLOB_MAX_BYTES = 60 * 1024 * 1024
|
|
22
|
+
// v0.11.0:媒体走真 Range,不再需要 blob 上限
|
|
24
23
|
/** 判断某条目是否是图片(大小写不敏感)。 */
|
|
25
24
|
function isImageItem(it) {
|
|
26
25
|
const ext = String(it?.extension ?? '').toLowerCase()
|
|
@@ -1882,53 +1881,25 @@ window.__ModuleLoader__.load({
|
|
|
1882
1881
|
*
|
|
1883
1882
|
* 这样「能播 + 能拖」在常规大小的产出上都成立,超大文件也不至于把面板搞崩。
|
|
1884
1883
|
*/
|
|
1884
|
+
/**
|
|
1885
|
+
* 面板内媒体播放器(v0.11.0:真 Range)。
|
|
1886
|
+
*
|
|
1887
|
+
* Host 侧现在用 ctx.webServer.register 注册了支持 206 的路由,
|
|
1888
|
+
* 所以 <video src=URL> 直接就能:
|
|
1889
|
+
* - 拖进度条(浏览器发 Range,宿主按 206 分片回)
|
|
1890
|
+
* - 边下边播(不预先载入整个文件)
|
|
1891
|
+
* - 内存占用恒定(流式,不占文件大小的内存)
|
|
1892
|
+
*
|
|
1893
|
+
* 因此不再需要 blob 方案,也不再需要 60MB 分档 —— 任意大小都能播。
|
|
1894
|
+
*/
|
|
1885
1895
|
function MediaPlayer({ item, t, onClose }) {
|
|
1886
1896
|
const isVideo = item.mediaType === 'video'
|
|
1887
|
-
const
|
|
1888
|
-
// blob 状态:loading / ready / failed
|
|
1889
|
-
const [blobState, setBlobState] = React.useState({ status: tooBig ? 'too-big' : 'loading' })
|
|
1897
|
+
const videoRef = React.useRef(null)
|
|
1890
1898
|
const [failed, setFailed] = React.useState(false)
|
|
1891
1899
|
const [dims, setDims] = React.useState(null)
|
|
1892
|
-
|
|
1893
|
-
const videoRef = React.useRef(null)
|
|
1894
|
-
// 截帧结果提示(成功/失败),2 秒后自动消失
|
|
1900
|
+
// 截帧结果提示(成功/失败),2.5 秒自动消失
|
|
1895
1901
|
const [grabNotice, setGrabNotice] = React.useState(null)
|
|
1896
|
-
|
|
1897
|
-
// 加载完整文件成 blob(≤ 60MB 才做)
|
|
1898
|
-
React.useEffect(() => {
|
|
1899
|
-
if (tooBig) return undefined
|
|
1900
|
-
let alive = true
|
|
1901
|
-
const controller = new AbortController()
|
|
1902
|
-
|
|
1903
|
-
fetchRaw(item.relPath, controller.signal, (loaded, total) => {
|
|
1904
|
-
if (!alive || tooBig) return
|
|
1905
|
-
const pct = total > 0 ? Math.round((loaded / total) * 100) : -1
|
|
1906
|
-
setBlobState((cur) => (cur.status === 'loading' ? { status: 'loading', pct } : cur))
|
|
1907
|
-
})
|
|
1908
|
-
.then((blob) => {
|
|
1909
|
-
if (!alive) return
|
|
1910
|
-
const url = URL.createObjectURL(blob)
|
|
1911
|
-
blobUrlRef.current = url
|
|
1912
|
-
setBlobState({ status: 'ready', url, bytes: blob.size })
|
|
1913
|
-
})
|
|
1914
|
-
.catch((error) => {
|
|
1915
|
-
if (!alive || controller.signal.aborted) return
|
|
1916
|
-
setBlobState({ status: 'failed', message: String(error?.message ?? error) })
|
|
1917
|
-
})
|
|
1918
|
-
|
|
1919
|
-
return () => {
|
|
1920
|
-
alive = false
|
|
1921
|
-
controller.abort()
|
|
1922
|
-
}
|
|
1923
|
-
}, [item.relPath, tooBig])
|
|
1924
|
-
|
|
1925
|
-
// 卸载时释放 blob URL(不释放会一直占内存)
|
|
1926
|
-
React.useEffect(() => () => {
|
|
1927
|
-
if (blobUrlRef.current !== null) {
|
|
1928
|
-
URL.revokeObjectURL(blobUrlRef.current)
|
|
1929
|
-
blobUrlRef.current = null
|
|
1930
|
-
}
|
|
1931
|
-
}, [])
|
|
1902
|
+
const url = mediaUrlOf(item.relPath, item.mtime)
|
|
1932
1903
|
|
|
1933
1904
|
React.useEffect(() => {
|
|
1934
1905
|
const onKey = (event) => {
|
|
@@ -1941,25 +1912,14 @@ window.__ModuleLoader__.load({
|
|
|
1941
1912
|
return () => window.removeEventListener('keydown', onKey)
|
|
1942
1913
|
}, [onClose])
|
|
1943
1914
|
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
* play → cmd start,用文件关联的默认程序打开(媒体文件能直接播)
|
|
1948
|
-
* select → explorer /select,在资源管理器里选中该文件
|
|
1949
|
-
*
|
|
1950
|
-
* 关键:以前是 .catch(e => console.error(...)) 静默吞错,
|
|
1951
|
-
* 用户只看到按钮有动画、什么都没发生。现在把失败原因显示出来。
|
|
1952
|
-
*/
|
|
1953
|
-
const runReveal = React.useCallback((mode) => {
|
|
1954
|
-
setGrabNotice({ kind: 'pending', text: mode === 'play' ? '正在打开…' : '正在定位…' })
|
|
1955
|
-
void callHost('reveal', { path: item.relPath, mode }).then((resp) => {
|
|
1915
|
+
const openExternal = React.useCallback(() => {
|
|
1916
|
+
setGrabNotice({ kind: 'pending', text: '正在打开…' })
|
|
1917
|
+
void callHost('reveal', { path: item.relPath, mode: 'play' }).then((resp) => {
|
|
1956
1918
|
if (resp !== null && resp.ok === false) {
|
|
1957
|
-
const msg = resp.error?.message ?? 'unknown'
|
|
1958
1919
|
setGrabNotice({
|
|
1959
1920
|
kind: 'failed',
|
|
1960
|
-
text: format(t('mediaOpenFailed'), { message:
|
|
1921
|
+
text: format(t('mediaOpenFailed'), { message: resp.error?.code ?? 'unknown' }),
|
|
1961
1922
|
})
|
|
1962
|
-
console.warn('dsh-gallery: reveal 失败', resp)
|
|
1963
1923
|
return
|
|
1964
1924
|
}
|
|
1965
1925
|
setGrabNotice({ kind: 'ok', text: t('mediaOpenOk') })
|
|
@@ -1968,17 +1928,32 @@ window.__ModuleLoader__.load({
|
|
|
1968
1928
|
kind: 'failed',
|
|
1969
1929
|
text: format(t('mediaOpenFailed'), { message: String(error?.message ?? error) }),
|
|
1970
1930
|
})
|
|
1971
|
-
console.error('dsh-gallery: reveal 请求失败', error)
|
|
1972
1931
|
})
|
|
1973
1932
|
}, [item.relPath, t])
|
|
1974
1933
|
|
|
1975
|
-
const
|
|
1976
|
-
|
|
1934
|
+
const openFolder = React.useCallback(() => {
|
|
1935
|
+
setGrabNotice({ kind: 'pending', text: '正在定位…' })
|
|
1936
|
+
void callHost('reveal', { path: item.relPath, mode: 'select' }).then((resp) => {
|
|
1937
|
+
if (resp !== null && resp.ok === false) {
|
|
1938
|
+
setGrabNotice({
|
|
1939
|
+
kind: 'failed',
|
|
1940
|
+
text: format(t('mediaOpenFailed'), { message: resp.error?.code ?? 'unknown' }),
|
|
1941
|
+
})
|
|
1942
|
+
return
|
|
1943
|
+
}
|
|
1944
|
+
setGrabNotice({ kind: 'ok', text: t('mediaOpenOk') })
|
|
1945
|
+
}).catch((error) => {
|
|
1946
|
+
setGrabNotice({
|
|
1947
|
+
kind: 'failed',
|
|
1948
|
+
text: format(t('mediaOpenFailed'), { message: String(error?.message ?? error) }),
|
|
1949
|
+
})
|
|
1950
|
+
})
|
|
1951
|
+
}, [item.relPath, t])
|
|
1977
1952
|
|
|
1978
1953
|
/**
|
|
1979
1954
|
* 截取当前帧存成 PNG。
|
|
1980
|
-
*
|
|
1981
|
-
*
|
|
1955
|
+
* 同一来源(同协议同端口)才能 canvas toBlob,否则 canvas 被 taint。
|
|
1956
|
+
* 我们的媒体路由与页面同源,所以可用。
|
|
1982
1957
|
*/
|
|
1983
1958
|
const grabFrame = React.useCallback(() => {
|
|
1984
1959
|
const v = videoRef.current
|
|
@@ -1997,7 +1972,6 @@ window.__ModuleLoader__.load({
|
|
|
1997
1972
|
if (c2d === null) throw new Error('no 2d context')
|
|
1998
1973
|
c2d.drawImage(v, 0, 0, w, h)
|
|
1999
1974
|
|
|
2000
|
-
// 时间码:00-12-34
|
|
2001
1975
|
const sec = Math.floor(v.currentTime || 0)
|
|
2002
1976
|
const hh = String(Math.floor(sec / 3600)).padStart(2, '0')
|
|
2003
1977
|
const mm = String(Math.floor((sec % 3600) / 60)).padStart(2, '0')
|
|
@@ -2007,18 +1981,17 @@ window.__ModuleLoader__.load({
|
|
|
2007
1981
|
|
|
2008
1982
|
canvas.toBlob((blob) => {
|
|
2009
1983
|
if (blob === null) {
|
|
2010
|
-
setGrabNotice({ kind: 'failed', text: format(t('mediaGrabFrameFailed'), { message: 'toBlob
|
|
1984
|
+
setGrabNotice({ kind: 'failed', text: format(t('mediaGrabFrameFailed'), { message: 'toBlob null' }) })
|
|
2011
1985
|
return
|
|
2012
1986
|
}
|
|
2013
|
-
const
|
|
1987
|
+
const u = URL.createObjectURL(blob)
|
|
2014
1988
|
const a = document.createElement('a')
|
|
2015
|
-
a.href =
|
|
1989
|
+
a.href = u
|
|
2016
1990
|
a.download = fname
|
|
2017
1991
|
document.body.appendChild(a)
|
|
2018
1992
|
a.click()
|
|
2019
1993
|
document.body.removeChild(a)
|
|
2020
|
-
|
|
2021
|
-
setTimeout(() => URL.revokeObjectURL(url), 1000)
|
|
1994
|
+
setTimeout(() => URL.revokeObjectURL(u), 1000)
|
|
2022
1995
|
setGrabNotice({ kind: 'ok', text: format(t('mediaGrabFrameOk'), { name: fname }) })
|
|
2023
1996
|
}, 'image/png')
|
|
2024
1997
|
} catch (error) {
|
|
@@ -2026,15 +1999,12 @@ window.__ModuleLoader__.load({
|
|
|
2026
1999
|
}
|
|
2027
2000
|
}, [item.name, t])
|
|
2028
2001
|
|
|
2029
|
-
// 提示 2.5 秒后自动消失
|
|
2030
2002
|
React.useEffect(() => {
|
|
2031
2003
|
if (grabNotice === null) return undefined
|
|
2032
2004
|
const timer = setTimeout(() => setGrabNotice(null), 2500)
|
|
2033
2005
|
return () => clearTimeout(timer)
|
|
2034
2006
|
}, [grabNotice])
|
|
2035
2007
|
|
|
2036
|
-
const ready = blobState.status === 'ready'
|
|
2037
|
-
|
|
2038
2008
|
return h('div', {
|
|
2039
2009
|
className: 'dg-mediaLayer',
|
|
2040
2010
|
key: 'mediaLayer',
|
|
@@ -2047,8 +2017,7 @@ window.__ModuleLoader__.load({
|
|
|
2047
2017
|
}, [
|
|
2048
2018
|
h('div', { className: 'dg-mediaBar', key: 'bar' }, [
|
|
2049
2019
|
h('span', { className: 'dg-mediaPTitle', key: 'title', title: item.relPath }, item.name),
|
|
2050
|
-
|
|
2051
|
-
isVideo && ready
|
|
2020
|
+
isVideo && !failed
|
|
2052
2021
|
? h('button', {
|
|
2053
2022
|
type: 'button',
|
|
2054
2023
|
className: 'dg-btn dg-mediaGrabBtn',
|
|
@@ -2067,97 +2036,55 @@ window.__ModuleLoader__.load({
|
|
|
2067
2036
|
]),
|
|
2068
2037
|
h('div', { className: 'dg-mediaStage', key: 'stage' }, (
|
|
2069
2038
|
failed
|
|
2070
|
-
? h('div', { className: 'dg-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
h('
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
h('div', { className: 'dg-mediaTooBigIco', key: 'ico' }, '⚠'),
|
|
2112
|
-
h('div', { className: 'dg-mediaTooBigTitle', key: 't1' }, t('mediaLoadFailed')),
|
|
2113
|
-
h('div', { className: 'dg-mediaTooBigHint', key: 't2' }, blobState.message ?? ''),
|
|
2114
|
-
h('div', { className: 'dg-mediaActionRow', key: 'actions' }, [
|
|
2115
|
-
h('button', {
|
|
2116
|
-
type: 'button', className: 'dg-mediaActBtn dg-mediaActPrimary', key: 'ext',
|
|
2117
|
-
'data-gallery-open-external': item.relPath,
|
|
2118
|
-
onClick: (event) => { event.stopPropagation(); openExternal() },
|
|
2119
|
-
}, ['▶ ', t('mediaOpenExternal')]),
|
|
2120
|
-
h('button', {
|
|
2121
|
-
type: 'button', className: 'dg-mediaActBtn', key: 'folder',
|
|
2122
|
-
'data-gallery-open-folder': item.relPath,
|
|
2123
|
-
onClick: (event) => { event.stopPropagation(); openFolder() },
|
|
2124
|
-
}, ['📂 ', t('mediaOpenFolder')]),
|
|
2125
|
-
]),
|
|
2126
|
-
])
|
|
2127
|
-
: isVideo
|
|
2128
|
-
? h('video', {
|
|
2129
|
-
ref: videoRef,
|
|
2130
|
-
src: blobState.url,
|
|
2131
|
-
controls: true,
|
|
2132
|
-
autoPlay: true,
|
|
2133
|
-
preload: 'auto',
|
|
2134
|
-
key: 'v',
|
|
2135
|
-
'data-gallery-video': item.relPath,
|
|
2136
|
-
onError: () => setFailed(true),
|
|
2137
|
-
onLoadedMetadata: (event) => {
|
|
2138
|
-
const v = event.currentTarget
|
|
2139
|
-
if (v.videoWidth > 0) setDims({ w: v.videoWidth, h: v.videoHeight })
|
|
2140
|
-
},
|
|
2141
|
-
})
|
|
2142
|
-
: h('audio', {
|
|
2143
|
-
src: blobState.url,
|
|
2144
|
-
controls: true,
|
|
2145
|
-
autoPlay: true,
|
|
2146
|
-
preload: 'auto',
|
|
2147
|
-
key: 'a',
|
|
2148
|
-
'data-gallery-audio': item.relPath,
|
|
2149
|
-
onError: () => setFailed(true),
|
|
2150
|
-
})
|
|
2039
|
+
? h('div', { className: 'dg-mediaTooBig', key: 'fail' }, [
|
|
2040
|
+
h('div', { className: 'dg-mediaTooBigIco', key: 'ico' }, '⚠'),
|
|
2041
|
+
h('div', { className: 'dg-mediaTooBigTitle', key: 't1' }, t('mediaNoPreview')),
|
|
2042
|
+
h('div', { className: 'dg-mediaTooBigHint', key: 't2' }, t('mediaBinaryHint')),
|
|
2043
|
+
h('div', { className: 'dg-mediaActionRow', key: 'actions' }, [
|
|
2044
|
+
h('button', {
|
|
2045
|
+
type: 'button', className: 'dg-mediaActBtn dg-mediaActPrimary', key: 'ext',
|
|
2046
|
+
'data-gallery-open-external': item.relPath,
|
|
2047
|
+
onClick: (event) => { event.stopPropagation(); openExternal() },
|
|
2048
|
+
}, ['▶ ', t('mediaOpenExternal')]),
|
|
2049
|
+
h('button', {
|
|
2050
|
+
type: 'button', className: 'dg-mediaActBtn', key: 'folder',
|
|
2051
|
+
'data-gallery-open-folder': item.relPath,
|
|
2052
|
+
onClick: (event) => { event.stopPropagation(); openFolder() },
|
|
2053
|
+
}, ['📂 ', t('mediaOpenFolder')]),
|
|
2054
|
+
]),
|
|
2055
|
+
])
|
|
2056
|
+
: isVideo
|
|
2057
|
+
? h('video', {
|
|
2058
|
+
ref: videoRef,
|
|
2059
|
+
src: url,
|
|
2060
|
+
controls: true,
|
|
2061
|
+
autoPlay: true,
|
|
2062
|
+
preload: 'metadata',
|
|
2063
|
+
key: 'v',
|
|
2064
|
+
'data-gallery-video': item.relPath,
|
|
2065
|
+
onError: () => setFailed(true),
|
|
2066
|
+
onLoadedMetadata: (event) => {
|
|
2067
|
+
const v = event.currentTarget
|
|
2068
|
+
if (v.videoWidth > 0) setDims({ w: v.videoWidth, h: v.videoHeight })
|
|
2069
|
+
},
|
|
2070
|
+
})
|
|
2071
|
+
: h('audio', {
|
|
2072
|
+
src: url,
|
|
2073
|
+
controls: true,
|
|
2074
|
+
autoPlay: true,
|
|
2075
|
+
preload: 'metadata',
|
|
2076
|
+
key: 'a',
|
|
2077
|
+
'data-gallery-audio': item.relPath,
|
|
2078
|
+
onError: () => setFailed(true),
|
|
2079
|
+
})
|
|
2151
2080
|
)),
|
|
2152
|
-
// 底栏:文件名 + 大小 + 时间(+ 视频尺寸)
|
|
2153
2081
|
h('div', { className: 'dg-mediaFoot', key: 'foot' }, [
|
|
2154
2082
|
h('span', { className: 'dg-mediaFootName', key: 'name', title: item.relPath }, item.name),
|
|
2155
2083
|
h('span', { className: 'dg-mediaFootMeta', key: 'meta' },
|
|
2156
2084
|
`${formatBytes(item.size)} · ${formatTime(item.mtime)}`
|
|
2157
2085
|
+ (dims !== null ? ` · ${dims.w} × ${dims.h}` : '')
|
|
2158
|
-
+
|
|
2086
|
+
+ ' · 可拖动进度条'),
|
|
2159
2087
|
]),
|
|
2160
|
-
// 截帧结果提示(成功绿、失败红),2.5 秒自动消失
|
|
2161
2088
|
grabNotice === null
|
|
2162
2089
|
? null
|
|
2163
2090
|
: h('div', {
|
package/index.js
CHANGED
|
@@ -1327,6 +1327,74 @@ async function resolveReadable(roots, relPath, opts, byteCap) {
|
|
|
1327
1327
|
return null
|
|
1328
1328
|
}
|
|
1329
1329
|
|
|
1330
|
+
/**
|
|
1331
|
+
* 解析 `Range: bytes=...` 头。
|
|
1332
|
+
* 支持:常规 (0-99)、开放 (100-)、后缀 (-50)、不可满足 (416)。
|
|
1333
|
+
* 多区间取第一个(HTTP 规范允许)。
|
|
1334
|
+
*/
|
|
1335
|
+
function parseMediaRange(raw, size) {
|
|
1336
|
+
if (raw === undefined) return null
|
|
1337
|
+
const m = /^bytes=(.+)$/i.exec(String(raw).trim())
|
|
1338
|
+
if (!m) return null
|
|
1339
|
+
const spec = m[1].split(',')[0].trim()
|
|
1340
|
+
if (spec === '') return null
|
|
1341
|
+
if (spec.startsWith('-')) {
|
|
1342
|
+
const suffix = Number(spec.slice(1))
|
|
1343
|
+
if (!Number.isFinite(suffix) || suffix <= 0) return null
|
|
1344
|
+
if (suffix >= size) return { start: 0, end: size - 1 }
|
|
1345
|
+
return { start: size - suffix, end: size - 1 }
|
|
1346
|
+
}
|
|
1347
|
+
const dash = spec.indexOf('-')
|
|
1348
|
+
if (dash === -1) return null
|
|
1349
|
+
const startText = spec.slice(0, dash)
|
|
1350
|
+
const endText = spec.slice(dash + 1)
|
|
1351
|
+
const start = startText === '' ? 0 : Number(startText)
|
|
1352
|
+
const end = endText === '' ? size - 1 : Number(endText)
|
|
1353
|
+
if (!Number.isInteger(start) || start < 0 || !Number.isInteger(end)) return null
|
|
1354
|
+
if (start >= size) return { unsatisfiable: true }
|
|
1355
|
+
return { start, end: Math.min(end, size - 1) }
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
/**
|
|
1359
|
+
* 用 Node 原生 res 输出一个媒体文件,支持 HTTP Range。
|
|
1360
|
+
* 这是 206 能工作的关键:req/res 直写,不经过 DSH 的 fetch 网关。
|
|
1361
|
+
*/
|
|
1362
|
+
function serveMedia(req, res, filePath, size, type) {
|
|
1363
|
+
const headers = {
|
|
1364
|
+
'content-type': type,
|
|
1365
|
+
'accept-ranges': 'bytes',
|
|
1366
|
+
'cache-control': 'no-cache',
|
|
1367
|
+
'x-content-type-options': 'nosniff',
|
|
1368
|
+
}
|
|
1369
|
+
const range = parseMediaRange(req.headers.range, size)
|
|
1370
|
+
|
|
1371
|
+
if (range !== null && range.unsatisfiable === true) {
|
|
1372
|
+
res.writeHead(416, { ...headers, 'content-range': `bytes */${size}` })
|
|
1373
|
+
res.end()
|
|
1374
|
+
return
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
if (range !== null) {
|
|
1378
|
+
const { start, end } = range
|
|
1379
|
+
res.writeHead(206, {
|
|
1380
|
+
...headers,
|
|
1381
|
+
'content-range': `bytes ${start}-${end}/${size}`,
|
|
1382
|
+
'content-length': String(end - start + 1),
|
|
1383
|
+
})
|
|
1384
|
+
if (req.method === 'HEAD') { res.end(); return }
|
|
1385
|
+
const stream = createReadStream(filePath, { start, end })
|
|
1386
|
+
stream.on('error', () => res.destroy())
|
|
1387
|
+
stream.pipe(res)
|
|
1388
|
+
return
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
res.writeHead(200, { ...headers, 'content-length': String(size) })
|
|
1392
|
+
if (req.method === 'HEAD') { res.end(); return }
|
|
1393
|
+
const stream = createReadStream(filePath)
|
|
1394
|
+
stream.on('error', () => res.destroy())
|
|
1395
|
+
stream.pipe(res)
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1330
1398
|
function contentTypeFor(ext) {
|
|
1331
1399
|
if (ext === '.png') return 'image/png'
|
|
1332
1400
|
if (ext === '.jpg' || ext === '.jpeg') return 'image/jpeg'
|
|
@@ -1359,7 +1427,7 @@ function json(body, status) {
|
|
|
1359
1427
|
/**
|
|
1360
1428
|
* Host 插件入口。仅依赖 connection(exact Fetch 路由);缺失时插件不激活而不是抛错。
|
|
1361
1429
|
*/
|
|
1362
|
-
export const inject = ['connection']
|
|
1430
|
+
export const inject = ['connection', 'webServer']
|
|
1363
1431
|
|
|
1364
1432
|
export function apply(ctx, config) {
|
|
1365
1433
|
/**
|
|
@@ -1368,69 +1436,87 @@ export function apply(ctx, config) {
|
|
|
1368
1436
|
* POST 路由不行(媒体元素不会发 POST),所以这里单独注册一个 GET 路径。
|
|
1369
1437
|
* 支持 Range,浏览器才能拖进度条、边播边下。
|
|
1370
1438
|
*/
|
|
1439
|
+
/**
|
|
1440
|
+
* 媒体直链(v0.11.0):用 ctx.webServer.register 注册 Node 原生路由。
|
|
1441
|
+
*
|
|
1442
|
+
* 为什么从 connection.fetch 换成 webServer?
|
|
1443
|
+
* - fetch 那套是 Web Fetch API(Request/Response),DSH 的网关层不透传 206,
|
|
1444
|
+
* <video src> 拿不到 Range,进度条拖不动(实测确认)。
|
|
1445
|
+
* - webServer 给的是 Node 原生 (req, res),可以 res.writeHead(206) + createReadStream,
|
|
1446
|
+
* 真正的分片流式下发。探针已实证:HEAD 200 / Range 206 / 中段 206 / 后缀 206 全部通过。
|
|
1447
|
+
*
|
|
1448
|
+
* 安全(三道防护,缺一不可):
|
|
1449
|
+
* 1. 路径必须落在扫描 roots 白名单内(isInside)—— 否则能读任意文件
|
|
1450
|
+
* 2. 跨站请求拒绝(sec-fetch-site / origin)
|
|
1451
|
+
* 3. 只允许 GET / HEAD
|
|
1452
|
+
*/
|
|
1371
1453
|
ctx.effect(
|
|
1372
|
-
() =>
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
//
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
relPath = ''
|
|
1454
|
+
() => ctx.webServer.register({
|
|
1455
|
+
kind: 'prefix',
|
|
1456
|
+
path: MEDIA_ROUTE,
|
|
1457
|
+
handler: async (req, res) => {
|
|
1458
|
+
// ---- 防护 3:只读 ----
|
|
1459
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
1460
|
+
res.writeHead(405, { 'content-type': 'text/plain; charset=utf-8' })
|
|
1461
|
+
res.end('method not allowed')
|
|
1462
|
+
return
|
|
1463
|
+
}
|
|
1464
|
+
// ---- 防护 2:拒绝跨站 ----
|
|
1465
|
+
const site = req.headers['sec-fetch-site']
|
|
1466
|
+
if (typeof site === 'string' && site === 'cross-site') {
|
|
1467
|
+
res.writeHead(403, { 'content-type': 'text/plain; charset=utf-8' })
|
|
1468
|
+
res.end('cross-site request refused')
|
|
1469
|
+
return
|
|
1470
|
+
}
|
|
1471
|
+
const origin = req.headers.origin
|
|
1472
|
+
if (typeof origin === 'string' && origin !== '') {
|
|
1473
|
+
let originHost = ''
|
|
1474
|
+
try { originHost = new URL(origin).host } catch { originHost = '' }
|
|
1475
|
+
const host = req.headers.host
|
|
1476
|
+
if (originHost !== '' && typeof host === 'string' && originHost !== host) {
|
|
1477
|
+
res.writeHead(403, { 'content-type': 'text/plain; charset=utf-8' })
|
|
1478
|
+
res.end('origin mismatch')
|
|
1479
|
+
return
|
|
1399
1480
|
}
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
try {
|
|
1484
|
+
const url = new URL(req.url ?? '/', 'http://dsh.internal')
|
|
1485
|
+
const relPath = url.searchParams.get('path') ?? ''
|
|
1400
1486
|
if (relPath === '') {
|
|
1401
|
-
|
|
1487
|
+
res.writeHead(400, { 'content-type': 'text/plain; charset=utf-8' })
|
|
1488
|
+
res.end('missing path')
|
|
1489
|
+
return
|
|
1402
1490
|
}
|
|
1403
|
-
|
|
1491
|
+
const resolved = resolveOptions(config)
|
|
1492
|
+
// ---- 防护 1:路径白名单 ----
|
|
1404
1493
|
const found = await resolveReadable(resolved.roots, relPath, resolved, resolved.maxMediaBytes)
|
|
1405
1494
|
if (found === null) {
|
|
1406
|
-
|
|
1495
|
+
res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' })
|
|
1496
|
+
res.end('not found')
|
|
1497
|
+
return
|
|
1407
1498
|
}
|
|
1408
1499
|
let stat
|
|
1409
1500
|
try {
|
|
1410
1501
|
stat = await fsp.stat(found.absolute)
|
|
1411
1502
|
} catch (error) {
|
|
1412
|
-
|
|
1503
|
+
res.writeHead(500, { 'content-type': 'text/plain; charset=utf-8' })
|
|
1504
|
+
res.end(String(error?.message ?? error))
|
|
1505
|
+
return
|
|
1413
1506
|
}
|
|
1414
1507
|
const type = contentTypeFor(path.extname(found.absolute).toLowerCase())
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
'content-type':
|
|
1419
|
-
|
|
1420
|
-
}
|
|
1421
|
-
|
|
1422
|
-
return new Response(null, { status: 200, headers })
|
|
1423
|
-
}
|
|
1424
|
-
// 流式返回:createReadStream → Readable.toWeb,内存占用与文件大小无关
|
|
1425
|
-
try {
|
|
1426
|
-
const stream = createReadStream(found.absolute)
|
|
1427
|
-
return new Response(Readable.toWeb(stream), { status: 200, headers })
|
|
1428
|
-
} catch (error) {
|
|
1429
|
-
return new Response(String(error?.message ?? error), { status: 500, headers: baseHeaders })
|
|
1508
|
+
serveMedia(req, res, found.absolute, stat.size, type)
|
|
1509
|
+
} catch (error) {
|
|
1510
|
+
if (!res.headersSent) {
|
|
1511
|
+
res.writeHead(500, { 'content-type': 'text/plain; charset=utf-8' })
|
|
1512
|
+
res.end(String(error?.message ?? error))
|
|
1513
|
+
} else {
|
|
1514
|
+
res.destroy()
|
|
1430
1515
|
}
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
|
|
1516
|
+
}
|
|
1517
|
+
},
|
|
1518
|
+
}),
|
|
1519
|
+
'dsh-gallery: media range route',
|
|
1434
1520
|
)
|
|
1435
1521
|
|
|
1436
1522
|
ctx.effect(
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
2
|
-
"meta": {
|
|
3
|
-
"title": "Output Gallery",
|
|
4
|
-
"description": "Fixes DSH reporting produced files only after a task ends: watches your output folders live
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Output Gallery",
|
|
4
|
+
"description": "Fixes DSH reporting produced files only after a task ends: watches your output folders live with auto-refreshing image thumbnails, native file preview, and in-panel video/audio playback over HTTP Range (seeking works at any file size), plus one-click frame capture, so you can verify and intervene mid-task."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
2
|
-
"meta": {
|
|
3
|
-
"title": "产出画廊",
|
|
4
|
-
"description": "解决 DSH
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "产出画廊",
|
|
4
|
+
"description": "解决 DSH 只在任务结尾才列出产出、过程不可见的问题:实时监控产出目录,图片自动刷新、文件原生预览、音视频面板内直接播放(支持 HTTP Range,任意大小都能拖进度条),还能一键截取视频当前帧,任务进行中就能校验纠正。"
|
|
5
|
+
}
|
|
6
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-gallery",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "产出画廊:解决 DSH
|
|
5
|
+
"description": "产出画廊:解决 DSH 只在任务结尾才列出产出、过程不可见的问题。实时监控产出目录,图片自动刷新、文件原生预览、音视频面板内直接播放(支持 HTTP Range,任意大小都能拖进度条),还能一键截取视频当前帧,任务进行中即可校验纠正。",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/Hope2023Dcr/dsh-gallery.git"
|
|
@@ -53,7 +53,11 @@
|
|
|
53
53
|
"image-gallery",
|
|
54
54
|
"file-preview",
|
|
55
55
|
"sidebar-plugin",
|
|
56
|
-
"agent-tools"
|
|
56
|
+
"agent-tools",
|
|
57
|
+
"media-gallery",
|
|
58
|
+
"video-preview",
|
|
59
|
+
"audio-preview",
|
|
60
|
+
"range-seek"
|
|
57
61
|
],
|
|
58
62
|
"publishConfig": {
|
|
59
63
|
"access": "public",
|