dsh-gallery 0.11.2 → 0.12.1
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 +233 -0
- package/README.md +43 -10
- package/client.js +179 -52
- package/host/classify.js +70 -0
- package/host/constants.js +133 -0
- package/host/fsutil.js +136 -0
- package/host/groups.js +92 -0
- package/host/http.js +785 -0
- package/host/media.js +122 -0
- package/host/protocol.js +25 -0
- package/host/scan.js +531 -0
- package/host/session-index.js +187 -0
- package/host/session.js +192 -0
- package/host/settings.js +232 -0
- package/index.js +23 -1813
- package/package.json +8 -2
- package/session-index.js +7 -187
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-gallery",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "产出画廊:解决 DSH
|
|
5
|
+
"description": "产出画廊:解决 DSH 只在任务结尾才列出产出、过程不可见的问题。实时监控产出目录,图片自动刷新、文件原生预览、音视频面板内直接播放(blob 播放,任意大小都能拖进度条),还能一键截取视频当前帧,任务进行中即可校验纠正。",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/Hope2023Dcr/dsh-gallery.git"
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"index.js",
|
|
22
22
|
"client.js",
|
|
23
23
|
"session-index.js",
|
|
24
|
+
"host/*.js",
|
|
24
25
|
"cordis.patch.yml",
|
|
25
26
|
"locale/*.json",
|
|
26
27
|
"icon.svg",
|
|
@@ -65,5 +66,10 @@
|
|
|
65
66
|
},
|
|
66
67
|
"engines": {
|
|
67
68
|
"node": ">=20"
|
|
69
|
+
},
|
|
70
|
+
"scripts": {
|
|
71
|
+
"build": "node scripts/build.mjs",
|
|
72
|
+
"check": "node scripts/check.mjs",
|
|
73
|
+
"test": "node --test tests/contract/install-whitelist.test.mjs"
|
|
68
74
|
}
|
|
69
75
|
}
|
package/session-index.js
CHANGED
|
@@ -1,187 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* 而画廊每 5 秒刷新一次 → 不可能每次都全量解压。
|
|
9
|
-
* 用「目录 mtime + 会话数」做键,没事就不重扫。
|
|
10
|
-
*
|
|
11
|
-
* 为什么用目录 mtime 而不是逐个文件:
|
|
12
|
-
* 108 个文件各 stat 一次也有开销;会话目录增多或日志追加时,
|
|
13
|
-
* 目录 mtime 会变,足够触发重扫。
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { promises as fsp } from 'node:fs'
|
|
17
|
-
import path from 'node:path'
|
|
18
|
-
|
|
19
|
-
/** 会话索引缓存:键是 sessionsDir,值是 { key, index }。 */
|
|
20
|
-
const sessionIndexCache = new Map()
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 扫出一个会话目录里的全部会话(含子会话)。
|
|
24
|
-
* @param sessionsDir - 会话根目录。
|
|
25
|
-
* @returns 会话目录信息数组。
|
|
26
|
-
*/
|
|
27
|
-
async function listSessionDirs(sessionsDir) {
|
|
28
|
-
const dirs = []
|
|
29
|
-
let groups
|
|
30
|
-
try {
|
|
31
|
-
groups = await fsp.readdir(sessionsDir, { withFileTypes: true })
|
|
32
|
-
} catch {
|
|
33
|
-
return dirs
|
|
34
|
-
}
|
|
35
|
-
for (const group of groups) {
|
|
36
|
-
if (!group.isDirectory()) continue
|
|
37
|
-
const gdir = path.join(sessionsDir, String(group.name))
|
|
38
|
-
let sessions
|
|
39
|
-
try {
|
|
40
|
-
sessions = await fsp.readdir(gdir, { withFileTypes: true })
|
|
41
|
-
} catch {
|
|
42
|
-
continue
|
|
43
|
-
}
|
|
44
|
-
for (const s of sessions) {
|
|
45
|
-
if (!s.isDirectory()) continue
|
|
46
|
-
const sdir = path.join(gdir, String(s.name))
|
|
47
|
-
const logPath = path.join(sdir, 'session.v4.jsonl.zstd')
|
|
48
|
-
try {
|
|
49
|
-
const st = await fsp.stat(logPath)
|
|
50
|
-
if (!st.isFile()) continue
|
|
51
|
-
dirs.push({
|
|
52
|
-
sessionId: String(s.name),
|
|
53
|
-
group: String(group.name),
|
|
54
|
-
sessionDir: sdir,
|
|
55
|
-
logPath,
|
|
56
|
-
logMtime: st.mtimeMs,
|
|
57
|
-
logSize: st.size,
|
|
58
|
-
})
|
|
59
|
-
} catch {
|
|
60
|
-
// 没有日志就跳过
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return dirs
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 从会话日志里提取标题。DSH 会写 `session/title` 事件。
|
|
69
|
-
* @param logText - 解压后的日志文本。
|
|
70
|
-
* @returns 标题字符串;没有则空串。
|
|
71
|
-
*/
|
|
72
|
-
function extractSessionTitle(logText) {
|
|
73
|
-
if (typeof logText !== 'string' || logText === '') return ''
|
|
74
|
-
// 取最后一个 title(用户可能改过标题)
|
|
75
|
-
let title = ''
|
|
76
|
-
for (const line of logText.split('\n')) {
|
|
77
|
-
if (!line.includes('session/title')) continue
|
|
78
|
-
let o
|
|
79
|
-
try { o = JSON.parse(line) } catch { continue }
|
|
80
|
-
if (o?.type !== 'session/title') continue
|
|
81
|
-
const t = o?.data?.title
|
|
82
|
-
if (typeof t === 'string' && t.trim() !== '') title = t.trim()
|
|
83
|
-
}
|
|
84
|
-
return title
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* 从会话日志首行读元信息(创建时间、cwd、父会话)。
|
|
89
|
-
* @param logText - 解压后的日志文本。
|
|
90
|
-
* @returns { createdAt, cwd, parentSession }
|
|
91
|
-
*/
|
|
92
|
-
function extractSessionMeta(logText) {
|
|
93
|
-
const fallback = { createdAt: 0, cwd: '', parentSession: '' }
|
|
94
|
-
if (typeof logText !== 'string' || logText === '') return fallback
|
|
95
|
-
const firstLine = logText.split('\n')[0]
|
|
96
|
-
let o
|
|
97
|
-
try { o = JSON.parse(firstLine) } catch { return fallback }
|
|
98
|
-
return {
|
|
99
|
-
createdAt: typeof o?.createdAt === 'number' ? o.createdAt : 0,
|
|
100
|
-
cwd: typeof o?.cwd === 'string' ? o.cwd : '',
|
|
101
|
-
parentSession: typeof o?.parentSession === 'string' ? o.parentSession : '',
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* 建立(或复用)会话索引。
|
|
107
|
-
*
|
|
108
|
-
* @param sessionsDir - 会话根目录。
|
|
109
|
-
* @param opts - resolveOptions 的结果(要用到 roots / readSessionLogText / extractAssetInfo)。
|
|
110
|
-
* @param deps - 依赖注入 { readSessionLogText, extractAssetInfo }。
|
|
111
|
-
* @returns Map<sessionId, { sessionId, title, createdAt, cwd, parentSession, files: Map<abs, category>, maxMtime }>
|
|
112
|
-
*/
|
|
113
|
-
export async function buildSessionIndex(sessionsDir, opts, deps) {
|
|
114
|
-
const { readSessionLogText, extractAssetInfo } = deps
|
|
115
|
-
|
|
116
|
-
// 缓存键:会话目录的 mtime + 当前会话数
|
|
117
|
-
let dirKey
|
|
118
|
-
try {
|
|
119
|
-
const allDirs = await listSessionDirs(sessionsDir)
|
|
120
|
-
dirKey = `${allDirs.length}|${allDirs.reduce((a, d) => Math.max(a, d.logMtime), 0)}`
|
|
121
|
-
const cached = sessionIndexCache.get(sessionsDir)
|
|
122
|
-
if (cached !== undefined && cached.key === dirKey) return cached.index
|
|
123
|
-
|
|
124
|
-
const index = new Map()
|
|
125
|
-
|
|
126
|
-
for (const d of allDirs) {
|
|
127
|
-
const logText = await readSessionLogText(d.logPath)
|
|
128
|
-
if (logText === '') continue
|
|
129
|
-
|
|
130
|
-
const meta = extractSessionMeta(logText)
|
|
131
|
-
const title = extractSessionTitle(logText)
|
|
132
|
-
// 传会话开始时间:用于区分「用户素材」和「会话期间产出」的分类
|
|
133
|
-
const assets = extractAssetInfo(logText, meta.createdAt)
|
|
134
|
-
|
|
135
|
-
// 只看落在扫描目录内的路径
|
|
136
|
-
const files = new Map()
|
|
137
|
-
let maxMtime = meta.createdAt
|
|
138
|
-
for (const [abs, info] of assets) {
|
|
139
|
-
let ownerRoot = null
|
|
140
|
-
for (const r of opts.roots) {
|
|
141
|
-
if (isInsidePath(r, abs)) { ownerRoot = r; break }
|
|
142
|
-
}
|
|
143
|
-
if (ownerRoot === null) continue
|
|
144
|
-
files.set(abs, info.category)
|
|
145
|
-
try {
|
|
146
|
-
const st = await fsp.stat(abs)
|
|
147
|
-
if (st.mtimeMs > maxMtime) maxMtime = st.mtimeMs
|
|
148
|
-
} catch {
|
|
149
|
-
// 文件已删除就跳过
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (files.size === 0) continue
|
|
154
|
-
|
|
155
|
-
index.set(d.sessionId, {
|
|
156
|
-
sessionId: d.sessionId,
|
|
157
|
-
title,
|
|
158
|
-
createdAt: meta.createdAt,
|
|
159
|
-
cwd: meta.cwd,
|
|
160
|
-
parentSession: meta.parentSession,
|
|
161
|
-
files,
|
|
162
|
-
maxMtime,
|
|
163
|
-
logMtime: d.logMtime,
|
|
164
|
-
})
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
sessionIndexCache.set(sessionsDir, { key: dirKey, index })
|
|
168
|
-
return index
|
|
169
|
-
} catch {
|
|
170
|
-
return new Map()
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/** 路径是否在 root 内(避免循环依赖,这里内联一份最小实现)。 */
|
|
175
|
-
function isInsidePath(root, abs) {
|
|
176
|
-
const r = path.resolve(root)
|
|
177
|
-
const a = path.resolve(abs)
|
|
178
|
-
if (a === r) return true
|
|
179
|
-
return a.startsWith(r + path.sep)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* 清空会话索引缓存(配置变化时调用)。
|
|
184
|
-
*/
|
|
185
|
-
export function clearSessionIndexCache() {
|
|
186
|
-
sessionIndexCache.clear()
|
|
187
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* session-index 的根级转出(S1 拆分后实际实现在 host/session-index.js)。
|
|
3
|
+
*
|
|
4
|
+
* 保留本文件是为了让外部 `import './session-index.js'` 仍然可用。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export { buildSessionIndex, clearSessionIndexCache } from './host/session-index.js'
|