dsh-gallery 1.4.1 → 1.4.2

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/host/groups.js CHANGED
@@ -37,6 +37,9 @@ export function buildGroups(summary, maxPerGroup = 120, currentSessionId = '', s
37
37
  ...(item.mediaType !== undefined ? { mediaType: item.mediaType } : {}),
38
38
  // 截帧来源(v0.14.3):反馈篮据此显示「取自《视频》00-01-00-500 帧」
39
39
  ...(item.frameOf !== undefined ? { frameOf: item.frameOf } : {}),
40
+ // 2026-11-25:继承 / 共享来源标记透传给卡片(资产台只看全局分组)
41
+ ...(item.inherited ? { inherited: true } : {}),
42
+ ...(item.shared ? { shared: true } : {}),
40
43
  // 阶段 2:与双击写进输入框同一套信息,别让 Agent 拿到少一截
41
44
  ...(item.maskOf !== undefined ? { maskOf: item.maskOf } : {}),
42
45
  categoryManual: item.categoryManual === true,
package/host/http.js CHANGED
@@ -683,8 +683,86 @@ export function registerOpsRoute(ctx, config) {
683
683
 
684
684
 
685
685
 
686
- // 全局分组:点「再显示 60 张」时取下一批明细。
687
- // 全量明细留在服务端内存,不重扫盘、不再传 2 MB 大包。
686
+ // ---------- 按分类取全部路径(2026-11-25)----------
687
+
688
+ // 「按标签选择」需要该分类下的**全部**文件:列表接口在「当前对话」视图
689
+ // 是分页的(每页 60),带 category 过滤也只是过滤当前页 —— 只在已加载
690
+ // 的条目里挑,点了「选」却只选中 60 张,等于又一次「批量没生效」。
691
+ // 这里单独给一个纯读接口,只回 relPath 数组。
692
+ //
693
+ // 速度:全局视图复用 groupsFullCache(老板刚看过列表就是热数据);
694
+ // 当前对话视图把 maxItems 抬到 5000 一次拿全,不按页重扫。
695
+ if (op === 'categoryPaths') {
696
+
697
+ try {
698
+
699
+ const kind = body?.kind === 'file' ? 'file'
700
+ : body?.kind === 'media' ? 'media'
701
+ : 'image'
702
+ const scope = body?.scope === 'session' ? 'session' : 'global'
703
+ const sessionId = typeof body?.sessionId === 'string' ? body.sessionId : ''
704
+ const wanted = String(body?.category ?? '')
705
+ if (!['final', 'input', 'intermediate', 'unknown'].includes(wanted)) {
706
+ return json({ ok: false, error: { code: 'invalid-category', message: '分类只能是 final / input / intermediate / unknown' } }, 400)
707
+ }
708
+
709
+ const optsResolved = resolveOptions(config)
710
+ let settingsStamp = 0
711
+ try { settingsStamp = (await fsp.stat(optsResolved.settingsFile)).mtimeMs } catch { /* 文件还不存在 */ }
712
+ const derived = await derivedStamp(optsResolved)
713
+
714
+ const entries = []
715
+ let truncated = false
716
+
717
+ if (scope === 'global') {
718
+ const gKey = groupsCacheKey(kind, scope, sessionId, optsResolved, settingsStamp, derived)
719
+ const hit = groupsFullCache.get(gKey)
720
+ if (hit !== undefined && Date.now() - hit.at < GROUPS_FULL_CACHE_MS) {
721
+ for (const g of hit.groups) {
722
+ for (const f of (Array.isArray(g?.files) ? g.files : [])) entries.push(f)
723
+ }
724
+ } else {
725
+ const fresh = await scanGallery(config, kind, scope, sessionId, 1)
726
+ const groups = Array.isArray(fresh?.groups) ? fresh.groups : []
727
+ groupsFullCache.set(gKey, { at: Date.now(), groups })
728
+ pruneGroupsFullCache(Date.now())
729
+ for (const g of groups) {
730
+ for (const f of (Array.isArray(g?.files) ? g.files : [])) entries.push(f)
731
+ }
732
+ for (const f of (Array.isArray(fresh?.items) ? fresh.items : [])) entries.push(f)
733
+ }
734
+ } else {
735
+ // 5000 是这一路的上限:单个对话的产出远到不了这个量
736
+ const full = await scanGallery(config, kind, scope, sessionId, 1, { maxItems: 5000 })
737
+ const got = Array.isArray(full?.items) ? full.items : []
738
+ for (const f of got) entries.push(f)
739
+ for (const g of (Array.isArray(full?.groups) ? full.groups : [])) {
740
+ for (const f of (Array.isArray(g?.files) ? g.files : [])) entries.push(f)
741
+ }
742
+ if (got.length >= 5000) truncated = true
743
+ }
744
+
745
+ const paths = []
746
+ const seen = new Set()
747
+ for (const f of entries) {
748
+ const rp = typeof f?.relPath === 'string' ? f.relPath : ''
749
+ if (rp === '' || seen.has(rp)) continue
750
+ const cat = typeof f?.category === 'string' && f.category !== '' ? f.category : 'unknown'
751
+ if (cat !== wanted) continue
752
+ seen.add(rp)
753
+ paths.push(rp)
754
+ }
755
+
756
+ return json({ ok: true, category: wanted, count: paths.length, truncated, paths })
757
+
758
+ } catch (error) {
759
+
760
+ return json({ ok: false, error: { code: 'scan-failed', message: String(error?.message ?? error) } }, 500)
761
+
762
+ }
763
+
764
+ }
765
+
688
766
  if (op === 'groupMore') {
689
767
  try {
690
768
  const kind = body?.kind === 'file' ? 'file'
@@ -1852,54 +1930,48 @@ export function registerOpsRoute(ctx, config) {
1852
1930
 
1853
1931
  if (op === 'hide' || op === 'unhide') {
1854
1932
 
1855
- const rel = body?.path
1856
-
1857
- if (typeof rel !== 'string' || rel === '') {
1858
-
1859
- return json({ ok: false, error: { code: 'invalid-path', message: '缺少文件路径' } }, 400)
1860
-
1933
+ // 2026-11-25:支持批量。前端批量隐藏时传 paths 数组,单条仍可传 path;
1934
+ // 非法项跳过并如实回报,不让一条坏路径把整批挡住。
1935
+ const rawHideList = Array.isArray(body?.paths)
1936
+ ? body.paths
1937
+ : (typeof body?.path === 'string' ? [body.path] : [])
1938
+ const hideRels = []
1939
+ const invalid = []
1940
+ const seenHide = new Set()
1941
+ for (const rawRel of rawHideList) {
1942
+ if (typeof rawRel !== 'string') { invalid.push(String(rawRel ?? '')); continue }
1943
+ const normalized = rawRel.replace(/\\/g, '/')
1944
+ if (normalized === '' || normalized.split('/').some((seg) => seg === '..' || seg === '')) {
1945
+ invalid.push(rawRel)
1946
+ continue
1947
+ }
1948
+ if (seenHide.has(normalized)) continue
1949
+ seenHide.add(normalized)
1950
+ hideRels.push(normalized)
1861
1951
  }
1862
-
1863
- const normalized = rel.replace(/\\/g, '/')
1864
-
1865
- if (normalized.split('/').some((s) => s === '..' || s === '')) {
1866
-
1867
- return json({ ok: false, error: { code: 'invalid-path', message: '路径非法' } }, 400)
1868
-
1952
+ if (hideRels.length === 0) {
1953
+ return json({ ok: false, error: { code: 'invalid-path', message: '缺少文件路径或路径非法' } }, 400)
1869
1954
  }
1870
1955
 
1871
1956
  try {
1872
-
1873
1957
  const opts = resolveOptions(config)
1874
-
1875
1958
  const hidden = new Set(await readHiddenList(opts.settingsFile))
1876
-
1877
- if (op === 'hide') hidden.add(normalized)
1878
-
1879
- else hidden.delete(normalized)
1880
-
1959
+ for (const normalized of hideRels) {
1960
+ if (op === 'hide') hidden.add(normalized)
1961
+ else hidden.delete(normalized)
1962
+ }
1881
1963
  await fsp.mkdir(path.dirname(opts.settingsFile), { recursive: true })
1882
-
1883
1964
  // 只改 hidden 字段,其余设置保留
1884
-
1885
1965
  const current = readSettingsFile(opts.settingsFile)
1886
-
1887
1966
  const next = { ...current, hidden: [...hidden] }
1888
-
1889
1967
  await fsp.writeFile(opts.settingsFile, JSON.stringify(next, null, 2), 'utf8')
1890
-
1891
- return json({ ok: true, hidden: hidden.size })
1892
-
1968
+ return json({ ok: true, hidden: hidden.size, changed: hideRels.length, invalid })
1893
1969
  } catch (error) {
1894
-
1895
1970
  return json({ ok: false, error: { code: 'hide-failed', message: String(error?.message ?? error) } }, 500)
1896
-
1897
1971
  }
1898
1972
 
1899
1973
  }
1900
1974
 
1901
-
1902
-
1903
1975
  // ---------- 全部恢复(清空隐藏列表)----------
1904
1976
 
1905
1977
  if (op === 'clearHidden') {
@@ -1940,55 +2012,101 @@ export function registerOpsRoute(ctx, config) {
1940
2012
 
1941
2013
  if (op === 'delete') {
1942
2014
 
1943
- const found = await resolveReadable(resolved.roots, body?.path, resolved)
1944
-
1945
- if (found === null) return json({ ok: false, error: { code: 'not-readable', message: '文件不存在或不可读' } }, 404)
1946
-
1947
- // 双保险:前端未明确确认则拒绝执行
1948
-
2015
+ // 2026-11-25:支持单条与批量。前端批量删除时传 paths 数组,
2016
+ // 旧调用仍可传 path 单条;两条通道走同一套清理逻辑。
1949
2017
  if (body?.confirm !== true) {
1950
-
1951
2018
  return json({ ok: false, error: { code: 'need-confirm', message: '需要确认后才能删除' } }, 400)
1952
-
1953
2019
  }
1954
2020
 
1955
- try {
2021
+ const rawList = Array.isArray(body?.paths)
2022
+ ? body.paths
2023
+ : (typeof body?.path === 'string' ? [body.path] : [])
2024
+ const reqPaths = []
2025
+ const seen = new Set()
2026
+ for (const rawPath of rawList) {
2027
+ if (typeof rawPath !== 'string') continue
2028
+ const p = rawPath.trim()
2029
+ if (p === '') continue
2030
+ const key = p.replace(/\\/g, '/').toLowerCase()
2031
+ if (seen.has(key)) continue
2032
+ seen.add(key)
2033
+ reqPaths.push(p)
2034
+ }
2035
+ if (reqPaths.length === 0) {
2036
+ return json({ ok: false, error: { code: 'invalid-path', message: '缺少要删除的文件路径' } }, 400)
2037
+ }
1956
2038
 
1957
- await fsp.rm(found.absolute, { force: true })
2039
+ const opts = resolveOptions(config)
2040
+ const deletedAbs = []
2041
+ const deletedRels = []
2042
+ const failed = []
2043
+ const notFound = []
1958
2044
 
1959
- // 删除后从隐藏列表里清掉,避免残留
2045
+ // 逐个删:单个失败不影响其余,最后如实回报
2046
+ for (const p of reqPaths) {
2047
+ const relKey = p.replace(/\\/g, '/')
2048
+ try {
2049
+ const found = await resolveReadable(resolved.roots, p, resolved)
2050
+ if (found === null) {
2051
+ notFound.push(relKey)
2052
+ continue
2053
+ }
2054
+ await fsp.rm(found.absolute, { force: true })
2055
+ deletedAbs.push(found.absolute)
2056
+ deletedRels.push(relKey)
2057
+ } catch (error) {
2058
+ failed.push({ path: relKey, reason: String(error?.message ?? error) })
2059
+ }
2060
+ }
1960
2061
 
1961
- const opts = resolveOptions(config)
2062
+ if (deletedRels.length === 0) {
2063
+ return json({
2064
+ ok: false,
2065
+ error: {
2066
+ code: notFound.length > 0 ? 'not-readable' : 'delete-failed',
2067
+ message: notFound.length > 0 ? '文件不存在或不可读' : '删除失败',
2068
+ },
2069
+ failed,
2070
+ notFound,
2071
+ }, notFound.length > 0 ? 404 : 500)
2072
+ }
1962
2073
 
2074
+ // 删除后从隐藏列表里清掉,避免残留(批量时一次写盘)
2075
+ try {
1963
2076
  const hidden = new Set(await readHiddenList(opts.settingsFile))
1964
-
1965
- const rel = body?.path.replace(/\\/g, '/')
1966
-
1967
- if (hidden.has(rel)) {
1968
-
1969
- hidden.delete(rel)
1970
-
2077
+ let hiddenChanged = false
2078
+ for (const rel of deletedRels) {
2079
+ if (hidden.delete(rel)) hiddenChanged = true
2080
+ }
2081
+ if (hiddenChanged) {
1971
2082
  const current = readSettingsFile(opts.settingsFile)
1972
-
1973
2083
  await fsp.writeFile(opts.settingsFile, JSON.stringify({ ...current, hidden: [...hidden] }, null, 2), 'utf8')
1974
-
1975
2084
  }
2085
+ } catch { /* 忽略:隐藏列表清理失败不影响删除结果 */ }
1976
2086
 
1977
- // 单文件删除:同步清掉截帧登记,避免残留孤儿记录
1978
- try { await deleteFrames(opts.settingsFile, [rel]) } catch { /* 忽略 */ }
1979
-
1980
- return json({ ok: true, deleted: found.absolute })
1981
-
1982
- } catch (error) {
1983
-
1984
- return json({ ok: false, error: { code: 'delete-failed', message: String(error?.message ?? error) } }, 500)
2087
+ // 标记 / 手动标签 / 截帧登记一并清掉,避免残留孤儿记录(失败不影响删除结果)
2088
+ let marksLeft = {}
2089
+ try {
2090
+ const cur = await readMarks(opts.settingsFile)
2091
+ const next = { ...cur.marks }
2092
+ for (const rel of deletedRels) delete next[rel]
2093
+ await writeMarks(opts.settingsFile, next)
2094
+ marksLeft = next
2095
+ } catch { /* 忽略 */ }
2096
+ try { await deleteLabels(opts.settingsFile, deletedRels) } catch { /* 忽略 */ }
2097
+ try { await deleteFrames(opts.settingsFile, deletedRels) } catch { /* 忽略 */ }
1985
2098
 
1986
- }
2099
+ return json({
2100
+ ok: failed.length === 0 && notFound.length === 0,
2101
+ deleted: deletedAbs,
2102
+ deletedPaths: deletedRels,
2103
+ failed,
2104
+ notFound,
2105
+ marks: marksLeft,
2106
+ })
1987
2107
 
1988
2108
  }
1989
2109
 
1990
-
1991
-
1992
2110
  // ---- v0.16.0 粘贴 / 裁剪:把外部素材或派生资产落进当前对话目录 ----
1993
2111
 
1994
2112
  /**