dsh-recycle-center 0.4.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 +66 -0
- package/LICENSE +21 -0
- package/README.md +295 -0
- package/SECURITY.md +41 -0
- package/client.js +740 -0
- package/cordis.patch.yml +5 -0
- package/docs/screenshot.jpg +0 -0
- package/docs//350/257/257/345/210/244/346/212/245/345/221/212.md +321 -0
- package/index.js +1861 -0
- package/lib/bin.js +295 -0
- package/lib/logtext.js +210 -0
- package/lib/safety.js +56 -0
- package/package.json +53 -0
package/client.js
ADDED
|
@@ -0,0 +1,740 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-recyclebin —— 浏览器半。
|
|
3
|
+
*
|
|
4
|
+
* 手写的模块加载器 bundle,没有构建步骤:执行它只登记一个工厂,
|
|
5
|
+
* 真正的代码在模块物化时才跑。它贡献三处界面:
|
|
6
|
+
*
|
|
7
|
+
* · sidebar.panellist —— 左侧边栏里的一项(图标 + 标题),和「插件」「自动化任务」同级
|
|
8
|
+
* · main —— 点开那一项后显示的一整页:7 天内删除的会话 + 图片缓存
|
|
9
|
+
* · sidebar.workspaces.session.menu.item —— 会话「⋯」菜单里的「删除对话」
|
|
10
|
+
* · shell.overlay —— 删除前的确认框
|
|
11
|
+
*
|
|
12
|
+
* 界面上不做任何判断:能不能删、能不能恢复、缓存有多大,全部由宿主半回答。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
window.__ModuleLoader__.load({
|
|
16
|
+
// 必须等于 package.json 的包名:宿主按包名注册客户端模块,
|
|
17
|
+
// id 不一致时 factory 永远不会被 materialize,界面就"消失"了。
|
|
18
|
+
id: 'dsh-recycle-center',
|
|
19
|
+
factory: (require) => {
|
|
20
|
+
const React = require('react')
|
|
21
|
+
|
|
22
|
+
// 宿主提供的原语。取不到就退回自绘,不让整个插件挂掉。
|
|
23
|
+
let primitives = null
|
|
24
|
+
try {
|
|
25
|
+
primitives = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
26
|
+
} catch {
|
|
27
|
+
primitives = null
|
|
28
|
+
}
|
|
29
|
+
const MenuItemButton = primitives && primitives.MenuItemButton ? primitives.MenuItemButton : null
|
|
30
|
+
const PanelIcon = primitives && primitives.IconTrashOutlineRegular ? primitives.IconTrashOutlineRegular : null
|
|
31
|
+
// 弹层优先用宿主自带的 Modal:尺寸、留白、右上角关闭按钮都跟 DSH 主界面一致。
|
|
32
|
+
const NativeModal = primitives && primitives.Modal ? primitives.Modal : null
|
|
33
|
+
|
|
34
|
+
const h = React.createElement
|
|
35
|
+
const API = '/dsh-recyclebin'
|
|
36
|
+
const NS = 'dsh-recycle-center'
|
|
37
|
+
const PANEL_ID = 'recyclebin'
|
|
38
|
+
|
|
39
|
+
/* ── 与宿主通信 ─────────────────────────────────────────────────── */
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 调一次宿主接口。所有请求都带标记头——宿主用它在跨站请求上把关。
|
|
43
|
+
* @param {string} path
|
|
44
|
+
* @param {Record<string, any> | null} body
|
|
45
|
+
*/
|
|
46
|
+
async function callHost(path, body) {
|
|
47
|
+
const init = {
|
|
48
|
+
method: body === null ? 'GET' : 'POST',
|
|
49
|
+
credentials: 'same-origin',
|
|
50
|
+
headers: { 'x-dsh-recyclebin': '1' },
|
|
51
|
+
}
|
|
52
|
+
if (body !== null) {
|
|
53
|
+
init.headers['content-type'] = 'application/json'
|
|
54
|
+
init.body = JSON.stringify(body)
|
|
55
|
+
}
|
|
56
|
+
const response = await fetch(API + path, init)
|
|
57
|
+
let payload = null
|
|
58
|
+
try {
|
|
59
|
+
payload = await response.json()
|
|
60
|
+
} catch {
|
|
61
|
+
payload = null
|
|
62
|
+
}
|
|
63
|
+
if (!response.ok || payload === null || payload.ok !== true) {
|
|
64
|
+
const reason = (payload && payload.error) || response.status + ' ' + response.statusText
|
|
65
|
+
const error = new Error(String(reason))
|
|
66
|
+
error.payload = payload
|
|
67
|
+
throw error
|
|
68
|
+
}
|
|
69
|
+
return payload
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* ── 一个极小的外部 store ──────────────────────────────────────── */
|
|
73
|
+
|
|
74
|
+
function createStore() {
|
|
75
|
+
let value = null
|
|
76
|
+
const listeners = new Set()
|
|
77
|
+
return {
|
|
78
|
+
getSnapshot: () => value,
|
|
79
|
+
subscribe(listener) {
|
|
80
|
+
listeners.add(listener)
|
|
81
|
+
return () => { listeners.delete(listener) }
|
|
82
|
+
},
|
|
83
|
+
open(request) {
|
|
84
|
+
value = request
|
|
85
|
+
for (const listener of [...listeners]) listener()
|
|
86
|
+
},
|
|
87
|
+
close() {
|
|
88
|
+
value = null
|
|
89
|
+
for (const listener of [...listeners]) listener()
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* ── 样式 ───────────────────────────────────────────────────────── */
|
|
95
|
+
|
|
96
|
+
const CSS = [
|
|
97
|
+
'.dsb-overlay{position:fixed;inset:0;z-index:1200;display:flex;align-items:center;justify-content:center;padding:24px;background:rgba(0,0,0,.36)}',
|
|
98
|
+
'.dsb-card{width:min(520px,100%);max-height:calc(100vh - 60px);overflow:auto;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);border:1px solid var(--dsw-alias-border-l1);border-radius:14px;box-shadow:0 18px 50px rgba(0,0,0,.32);padding:18px 20px 14px;font-size:13px;line-height:1.6}',
|
|
99
|
+
'.dsb-title{margin:0 0 2px;font-size:15px;font-weight:600}',
|
|
100
|
+
'.dsb-sub{margin:0 0 12px;font-size:12px;color:var(--dsw-alias-label-tertiary)}',
|
|
101
|
+
'.dsb-row{display:flex;gap:8px;margin:6px 0;align-items:flex-start}',
|
|
102
|
+
'.dsb-k{flex:none;width:72px;color:var(--dsw-alias-label-tertiary)}',
|
|
103
|
+
'.dsb-v{flex:1;min-width:0;word-break:break-all}',
|
|
104
|
+
'.dsb-verdict{margin:10px 0;padding:9px 12px;border-radius:9px;font-size:12.5px}',
|
|
105
|
+
'.dsb-verdict.ok{background:rgba(60,160,110,.14);color:var(--dsw-alias-label-primary)}',
|
|
106
|
+
'.dsb-verdict.warn{background:rgba(200,150,40,.16);color:var(--dsw-alias-label-primary)}',
|
|
107
|
+
'.dsb-verdict.bad{background:rgba(214,72,60,.14);color:var(--dsw-alias-state-error-primary)}',
|
|
108
|
+
'.dsb-ack{display:flex;gap:8px;align-items:flex-start;margin-top:12px;font-size:12.5px;cursor:pointer}',
|
|
109
|
+
'.dsb-foot{display:flex;justify-content:flex-end;gap:8px;margin-top:16px}',
|
|
110
|
+
'.dsb-btn{height:30px;padding:0 14px;border-radius:8px;border:1px solid var(--dsw-alias-border-l1);background:transparent;color:inherit;font:inherit;cursor:pointer}',
|
|
111
|
+
'.dsb-btn:disabled{opacity:.45;cursor:not-allowed}',
|
|
112
|
+
'.dsb-btn.danger{background:var(--dsw-alias-state-error-primary);color:#fff;border-color:transparent}',
|
|
113
|
+
'.dsb-menu{display:flex;align-items:center;gap:8px;width:100%;padding:7px 10px;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-state-error-primary);font:inherit;font-size:13px;text-align:left;cursor:pointer}',
|
|
114
|
+
'.dsb-menu:hover{background:var(--dsw-alias-bg-layer-2)}',
|
|
115
|
+
'.dsb-page{max-width:820px;padding:24px 28px 40px;color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.6;overflow:auto;height:100%;box-sizing:border-box}',
|
|
116
|
+
'.dsb-page h1{margin:0 0 6px;font-size:20px;font-weight:600}',
|
|
117
|
+
'.dsb-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:0 0 6px}',
|
|
118
|
+
'.dsb-head h1{margin:0;font-size:20px;font-weight:600}',
|
|
119
|
+
'.dsb-page h2{margin:0 0 6px;font-size:15px;font-weight:600}',
|
|
120
|
+
'.dsb-page p.intro{margin:0;color:var(--dsw-alias-label-tertiary);font-size:13px}',
|
|
121
|
+
'.dsb-count{color:var(--dsw-alias-label-tertiary);font-size:12px;margin:10px 0 0}',
|
|
122
|
+
'.dsb-list{display:flex;flex-direction:column;gap:8px;margin-top:12px}',
|
|
123
|
+
'.dsb-item{border:1px solid var(--dsw-alias-border-l1);border-radius:10px;padding:10px 12px;display:flex;gap:12px;align-items:center}',
|
|
124
|
+
'.dsb-item-main{flex:1;min-width:0}',
|
|
125
|
+
'.dsb-item-actions{display:flex;gap:8px;flex:none}',
|
|
126
|
+
'.dsb-btn.dangeroutline{color:var(--dsw-alias-state-error-primary);border-color:var(--dsw-alias-state-error-primary)}',
|
|
127
|
+
'.dsb-item-title{font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}',
|
|
128
|
+
'.dsb-item-meta{font-size:11.5px;color:var(--dsw-alias-label-tertiary);margin-top:2px}',
|
|
129
|
+
'.dsb-empty{color:var(--dsw-alias-label-tertiary);font-size:12.5px;margin-top:10px}',
|
|
130
|
+
'.dsb-footrow{display:flex;justify-content:flex-end;align-items:center;gap:10px;margin-top:26px;padding-top:14px;border-top:1px solid var(--dsw-alias-border-l1)}',
|
|
131
|
+
'.dsb-cache-label{font-size:12px;color:var(--dsw-alias-label-tertiary);white-space:nowrap}',
|
|
132
|
+
'.dsb-cache-label.bad{color:var(--dsw-alias-state-error-primary)}',
|
|
133
|
+
'.dsb-cache-note{text-align:right;font-size:12px;margin-top:16px;color:var(--dsw-alias-label-tertiary)}',
|
|
134
|
+
'.dsb-cache-note.bad{color:var(--dsw-alias-state-error-primary)}',
|
|
135
|
+
'.dsb-btn.small{height:26px;padding:0 10px;font-size:12px}',
|
|
136
|
+
'.dsb-card.wide{width:min(880px,100%)}',
|
|
137
|
+
'.dsb-att-modal{width:min(880px,92vw)!important;max-width:min(880px,92vw)!important}',
|
|
138
|
+
'.dsb-card{position:relative}',
|
|
139
|
+
'.dsb-dlg-x{position:absolute;top:10px;right:12px;width:26px;height:26px;padding:0;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary);font-size:18px;line-height:1;cursor:pointer}',
|
|
140
|
+
'.dsb-dlg-x:hover{background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary)}',
|
|
141
|
+
'.dsb-att-head{display:flex;gap:10px;align-items:flex-start;margin:0 0 8px;padding:0 10px}',
|
|
142
|
+
'.dsb-path{flex:1;min-width:0;padding-top:5px;font-size:11.5px;color:var(--dsw-alias-label-tertiary);word-break:break-all}',
|
|
143
|
+
'.dsb-att-head .dsb-btn{flex:none}',
|
|
144
|
+
'.dsb-att-sum{margin:0 0 10px;padding:0 10px;font-size:12.5px;color:var(--dsw-alias-label-secondary)}',
|
|
145
|
+
'.dsb-att-list{max-height:46vh;overflow:auto;border:1px solid var(--dsw-alias-border-l1);border-radius:10px}',
|
|
146
|
+
'.dsb-att-row{display:flex;gap:10px;align-items:baseline;padding:8px 10px;border-bottom:1px solid var(--dsw-alias-border-l1);font-size:12.5px}',
|
|
147
|
+
'.dsb-att-row:last-child{border-bottom:0}',
|
|
148
|
+
'.dsb-att-row.orphan{background:rgba(200,150,40,.10)}',
|
|
149
|
+
'.dsb-att-name{flex:1;min-width:0;word-break:break-all}',
|
|
150
|
+
'.dsb-att-meta{flex:1.2;min-width:0;color:var(--dsw-alias-label-tertiary);word-break:break-all}',
|
|
151
|
+
'.dsb-att-size{flex:0 0 84px;text-align:right;color:var(--dsw-alias-label-tertiary);white-space:nowrap;font-variant-numeric:tabular-nums}',
|
|
152
|
+
'.dsb-footrow.secondary{border-top:0;padding-top:0;margin-top:10px}',
|
|
153
|
+
].join('\n')
|
|
154
|
+
|
|
155
|
+
function ensureStyle() {
|
|
156
|
+
if (typeof document === 'undefined') return
|
|
157
|
+
if (document.querySelector('style[data-dsb]') !== null) return
|
|
158
|
+
const tag = document.createElement('style')
|
|
159
|
+
tag.dataset.dsb = '1'
|
|
160
|
+
tag.textContent = CSS
|
|
161
|
+
document.head.appendChild(tag)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function formatBytes(bytes) {
|
|
165
|
+
const value = Number(bytes)
|
|
166
|
+
if (!Number.isFinite(value) || value <= 0) return '0 B'
|
|
167
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
|
168
|
+
let size = value
|
|
169
|
+
let unit = 0
|
|
170
|
+
while (size >= 1024 && unit < units.length - 1) {
|
|
171
|
+
size /= 1024
|
|
172
|
+
unit += 1
|
|
173
|
+
}
|
|
174
|
+
return (size >= 10 || unit === 0 ? size.toFixed(0) : size.toFixed(1)) + ' ' + units[unit]
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** 把时间戳写成 2026-11-08 22:40 这样。 */
|
|
178
|
+
function formatTime(ms) {
|
|
179
|
+
const value = Number(ms)
|
|
180
|
+
if (!Number.isFinite(value) || value <= 0) return '—'
|
|
181
|
+
const d = new Date(value)
|
|
182
|
+
const p = (n) => String(n).padStart(2, '0')
|
|
183
|
+
return d.getFullYear() + '-' + p(d.getMonth() + 1) + '-' + p(d.getDate()) + ' ' + p(d.getHours()) + ':' + p(d.getMinutes())
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** 会话菜单里那一行的图标(自绘,尺寸跟随菜单)。 */
|
|
187
|
+
const trashGlyph = (size) => h('svg', {
|
|
188
|
+
width: size, height: size, viewBox: '0 0 16 16', fill: 'none',
|
|
189
|
+
stroke: 'currentColor', strokeWidth: 1.3, 'aria-hidden': 'true',
|
|
190
|
+
}, [
|
|
191
|
+
h('path', { key: 'lid', d: 'M2.6 4.2h10.8' }),
|
|
192
|
+
h('path', { key: 'body', d: 'M4.2 4.2l.7 9.1h6.2l.7-9.1' }),
|
|
193
|
+
h('path', { key: 'handle', d: 'M6.2 4.2V2.9h3.6v1.3' }),
|
|
194
|
+
])
|
|
195
|
+
|
|
196
|
+
/* ── 侧边栏面板图标 ────────────────────────────────────────────── */
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 面板图标。宿主自带的图标组件和「自动化任务」「插件」用的是同一套,
|
|
200
|
+
* 所以优先用它,尺寸/描边/颜色天然一致;取不到时退回自绘。
|
|
201
|
+
*/
|
|
202
|
+
function TrashPanelIcon({ size }) {
|
|
203
|
+
const pixels = typeof size === 'number' ? size : 18
|
|
204
|
+
if (PanelIcon) return h(PanelIcon, { size: pixels })
|
|
205
|
+
return trashGlyph(pixels)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/* ── 会话菜单里的一行 ──────────────────────────────────────────── */
|
|
209
|
+
|
|
210
|
+
function DeleteSessionMenuItem({ sessionId, displayTitle, useMenuOpenState, purgeStore }) {
|
|
211
|
+
// 宿主把菜单的开关状态作为 hook 发布;拿不到就退化成不自动收起。
|
|
212
|
+
const pair = typeof useMenuOpenState === 'function' ? useMenuOpenState() : null
|
|
213
|
+
const closeMenu = Array.isArray(pair) && typeof pair[1] === 'function' ? pair[1] : null
|
|
214
|
+
|
|
215
|
+
const onSelect = () => {
|
|
216
|
+
if (closeMenu) closeMenu(false)
|
|
217
|
+
purgeStore.open({ sessionId, title: String(displayTitle || sessionId) })
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// 文字和图标都用危险色。不依赖菜单组件是否支持 danger 属性,
|
|
221
|
+
// 直接把两个子元素包成红色,换一个菜单实现也不会失效。
|
|
222
|
+
const dangerStyle = { color: 'var(--dsw-alias-state-error-primary)' }
|
|
223
|
+
const label = h('span', { style: dangerStyle }, '删除会话')
|
|
224
|
+
const icon = h('span', { style: { ...dangerStyle, display: 'inline-flex' }, 'aria-hidden': 'true' }, trashGlyph(14))
|
|
225
|
+
|
|
226
|
+
if (MenuItemButton) {
|
|
227
|
+
return h(MenuItemButton, { icon, onSelect }, label)
|
|
228
|
+
}
|
|
229
|
+
return h('button', { type: 'button', className: 'dsb-menu', onClick: onSelect }, icon, label)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/* ── 删除确认框 ────────────────────────────────────────────────── */
|
|
233
|
+
|
|
234
|
+
function DeleteDialog({ purgeStore }) {
|
|
235
|
+
const request = React.useSyncExternalStore(purgeStore.subscribe, purgeStore.getSnapshot)
|
|
236
|
+
if (request === null) return null
|
|
237
|
+
return h(DialogBody, { key: request.sessionId, request, purgeStore })
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function DialogBody({ request, purgeStore }) {
|
|
241
|
+
const [info, setInfo] = React.useState(null)
|
|
242
|
+
const [error, setError] = React.useState(null)
|
|
243
|
+
const [acked, setAcked] = React.useState(false)
|
|
244
|
+
const [busy, setBusy] = React.useState(false)
|
|
245
|
+
const [done, setDone] = React.useState(null)
|
|
246
|
+
|
|
247
|
+
React.useEffect(() => {
|
|
248
|
+
let alive = true
|
|
249
|
+
callHost('/analyze', { sessionId: request.sessionId })
|
|
250
|
+
.then((payload) => { if (alive) setInfo(payload) })
|
|
251
|
+
.catch((reason) => { if (alive) setError(String(reason.message || reason)) })
|
|
252
|
+
return () => { alive = false }
|
|
253
|
+
}, [request.sessionId])
|
|
254
|
+
|
|
255
|
+
const close = () => { if (!busy) purgeStore.close() }
|
|
256
|
+
|
|
257
|
+
const confirm = () => {
|
|
258
|
+
setBusy(true)
|
|
259
|
+
setError(null)
|
|
260
|
+
callHost('/delete', { sessionId: request.sessionId, title: request.title, confirm: true })
|
|
261
|
+
.then((payload) => setDone(payload))
|
|
262
|
+
.catch((reason) => setError(String(reason.message || reason)))
|
|
263
|
+
.finally(() => setBusy(false))
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const body = []
|
|
267
|
+
if (done !== null) {
|
|
268
|
+
const movedIds = done.attachments ? done.attachments.movedIds : 0
|
|
269
|
+
const keptRows = done.attachments && Array.isArray(done.attachments.keptShared) ? done.attachments.keptShared : []
|
|
270
|
+
body.push(h('p', { key: 'ok' }, '已移入 Windows 回收站。'))
|
|
271
|
+
body.push(h('div', { key: 'v', className: 'dsb-verdict ok' },
|
|
272
|
+
'会话目录' + (movedIds > 0 ? '、它独占的 ' + movedIds + ' 个附件' : '')
|
|
273
|
+
+ '和索引文件都进回收站了。7 天内可以在侧边栏的「回收站」里一键恢复;满 7 天后,这条删除记录本身也会被移进回收站。'))
|
|
274
|
+
if (keptRows.length > 0) {
|
|
275
|
+
body.push(h('div', { key: 'shared', className: 'dsb-verdict warn' },
|
|
276
|
+
'有 ' + keptRows.length + ' 个附件仍被其他对话引用,已保留(未搬走)。'
|
|
277
|
+
+ '它们的摘要前 8 位:' + keptRows.map((row) => String(row.id).slice(0, 8)).join('、') + '。'))
|
|
278
|
+
}
|
|
279
|
+
if (done.movedAfterRelease > 0) {
|
|
280
|
+
body.push(h('div', { key: 'late', className: 'dsb-verdict ok' },
|
|
281
|
+
'另有 ' + done.movedAfterRelease + ' 个文件在删除后被重新写回,已补搬进回收站。'))
|
|
282
|
+
}
|
|
283
|
+
if (done.warning) body.push(h('div', { key: 'warn', className: 'dsb-verdict bad' }, done.warning))
|
|
284
|
+
if (done.wasLive && !done.released) {
|
|
285
|
+
body.push(h('div', { key: 'live-note', className: 'dsb-verdict warn', style: { marginTop: 8 } },
|
|
286
|
+
'这个会话删除时还挂在页面里,而且没能从宿主内存里释放。'
|
|
287
|
+
+ '如果侧栏冒出一个叫「未分组」的分组、它还在那里面:文件已经进回收站了,点下面的「刷新页面」或重启 DSH 即可。'))
|
|
288
|
+
}
|
|
289
|
+
body.push(h('p', { key: 'reload', className: 'dsb-sub', style: { marginTop: 10 } },
|
|
290
|
+
'如果侧栏里还看得到它,请点下面的「刷新页面」。'))
|
|
291
|
+
} else {
|
|
292
|
+
body.push(h('p', { key: 'title', className: 'dsb-title' }, '删除这个对话?'))
|
|
293
|
+
body.push(h('p', { key: 'sub', className: 'dsb-sub' }, request.title))
|
|
294
|
+
if (error !== null) body.push(h('div', { key: 'err', className: 'dsb-verdict bad' }, error))
|
|
295
|
+
if (info === null && error === null) body.push(h('p', { key: 'load', className: 'dsb-sub' }, '正在读取…'))
|
|
296
|
+
if (info !== null) {
|
|
297
|
+
body.push(h('div', { key: 'dir', className: 'dsb-row' },
|
|
298
|
+
h('span', { className: 'dsb-k' }, '目录'),
|
|
299
|
+
h('span', { className: 'dsb-v' }, info.dir || '')))
|
|
300
|
+
body.push(h('div', { key: 'size', className: 'dsb-row' },
|
|
301
|
+
h('span', { className: 'dsb-k' }, '大小'),
|
|
302
|
+
h('span', { className: 'dsb-v' }, formatBytes(info.bytes))))
|
|
303
|
+
body.push(h('div', { key: 'cache', className: 'dsb-row' },
|
|
304
|
+
h('span', { className: 'dsb-k' }, '索引文件'),
|
|
305
|
+
h('span', { className: 'dsb-v' }, info.cacheExists ? '有,会一起移进回收站' : '没有(这个会话还没生成索引)')))
|
|
306
|
+
if (info.attachmentCount > 0) {
|
|
307
|
+
const kept = Array.isArray(info.keptShared) ? info.keptShared : []
|
|
308
|
+
const exclusive = info.attachmentCount - kept.length
|
|
309
|
+
const text = kept.length === 0
|
|
310
|
+
? info.attachmentCount + ' 个,会一并移进回收站'
|
|
311
|
+
: exclusive + ' 个会移进回收站;' + kept.length + ' 个仍被其他对话引用,会保留'
|
|
312
|
+
+ '(' + kept.map((row) => String(row.id).slice(0, 8)).join('、') + ')'
|
|
313
|
+
body.push(h('div', { key: 'att', className: 'dsb-row' },
|
|
314
|
+
h('span', { className: 'dsb-k' }, '附件'),
|
|
315
|
+
h('span', { className: 'dsb-v' }, text)))
|
|
316
|
+
}
|
|
317
|
+
if (info.workspaceTitle) {
|
|
318
|
+
body.push(h('div', { key: 'ws', className: 'dsb-row' },
|
|
319
|
+
h('span', { className: 'dsb-k' }, '工作区'),
|
|
320
|
+
h('span', { className: 'dsb-v' }, info.workspaceTitle)))
|
|
321
|
+
}
|
|
322
|
+
body.push(h('div', { key: 'verdict', className: 'dsb-verdict ' + (info.deletable ? 'ok' : 'bad') },
|
|
323
|
+
(info.verdict && info.verdict.text) || ''))
|
|
324
|
+
if (info.deletable && info.open) {
|
|
325
|
+
body.push(h('div', { key: 'open', className: 'dsb-verdict warn' },
|
|
326
|
+
'这个会话仍被 DSH 加载在内存里(你打开过它),但当前没有执行中的任务,所以可以删。'
|
|
327
|
+
+ '如果想更稳妥,可以先切换到别的对话再回来删——那样它的内存实例会先被卸载。'))
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (info !== null && info.deletable) {
|
|
331
|
+
body.push(h('label', { key: 'ack', className: 'dsb-ack' },
|
|
332
|
+
h('input', { type: 'checkbox', checked: acked, onChange: (event) => setAcked(event.target.checked) }),
|
|
333
|
+
h('span', null, '我知道这个对话会从列表消失,会话目录、索引文件' + (info.attachmentCount > 0 ? '和它的附件' : '') + '会进 Windows 回收站;7 天后这条删除记录也会进去。')))
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const footer = done !== null
|
|
338
|
+
? [h('button', { key: 'reload', type: 'button', className: 'dsb-btn', onClick: () => window.location.reload() }, '刷新页面'),
|
|
339
|
+
h('button', { key: 'close', type: 'button', className: 'dsb-btn', onClick: close }, '关闭')]
|
|
340
|
+
: [h('button', { key: 'cancel', type: 'button', className: 'dsb-btn', disabled: busy, onClick: close }, '取消'),
|
|
341
|
+
h('button', {
|
|
342
|
+
key: 'confirm',
|
|
343
|
+
type: 'button',
|
|
344
|
+
className: 'dsb-btn danger',
|
|
345
|
+
disabled: busy || acked !== true || info === null || !info.deletable,
|
|
346
|
+
onClick: confirm,
|
|
347
|
+
}, busy ? '正在删除…' : '删除')]
|
|
348
|
+
|
|
349
|
+
return h('div', { className: 'dsb-overlay', onClick: (event) => { if (event.target === event.currentTarget) close() } },
|
|
350
|
+
h('div', { className: 'dsb-card', role: 'dialog', 'aria-modal': 'true' },
|
|
351
|
+
body,
|
|
352
|
+
h('div', { className: 'dsb-foot' }, footer)))
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/* ── 附件仓库盘点的子页面 ──────────────────────────────────────── */
|
|
356
|
+
|
|
357
|
+
/** 把过长的路径从中间省略,保留头尾。 */
|
|
358
|
+
function elideMiddle(text, max) {
|
|
359
|
+
const value = String(text || '')
|
|
360
|
+
const limit = typeof max === 'number' ? max : 72
|
|
361
|
+
if (value.length <= limit) return value
|
|
362
|
+
const head = Math.ceil((limit - 1) * 0.62)
|
|
363
|
+
const tail = limit - 1 - head
|
|
364
|
+
return value.slice(0, head) + '…' + value.slice(value.length - tail)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function AttachmentsDialog({ attachmentsStore }) {
|
|
368
|
+
const data = React.useSyncExternalStore(attachmentsStore.subscribe, attachmentsStore.getSnapshot)
|
|
369
|
+
if (data === null) return null
|
|
370
|
+
return h(AttachmentsBody, { key: String(data.total), data, attachmentsStore })
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function AttachmentsBody({ data, attachmentsStore }) {
|
|
374
|
+
const [meta, setMeta] = React.useState(data)
|
|
375
|
+
const [armed, setArmed] = React.useState(false)
|
|
376
|
+
const [busy, setBusy] = React.useState(false)
|
|
377
|
+
const [note, setNote] = React.useState(null)
|
|
378
|
+
|
|
379
|
+
React.useEffect(() => {
|
|
380
|
+
if (!armed) return undefined
|
|
381
|
+
const timer = setTimeout(() => setArmed(false), 6000)
|
|
382
|
+
return () => clearTimeout(timer)
|
|
383
|
+
}, [armed])
|
|
384
|
+
|
|
385
|
+
const close = () => { if (!busy) attachmentsStore.close() }
|
|
386
|
+
|
|
387
|
+
const openFolder = () => {
|
|
388
|
+
// 成功不提示:窗口真的起来了,用户自己看得到。
|
|
389
|
+
// 只有失败才说一句,否则就是「报了成功但什么都没发生」。
|
|
390
|
+
callHost('/attachments/open', {})
|
|
391
|
+
.catch((reason) => setNote({ tone: 'bad', text: '打不开资源管理器:' + String(reason.message || reason) }))
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const clear = () => {
|
|
395
|
+
if (!armed) {
|
|
396
|
+
setArmed(true)
|
|
397
|
+
setNote(null)
|
|
398
|
+
return
|
|
399
|
+
}
|
|
400
|
+
setArmed(false)
|
|
401
|
+
setBusy(true)
|
|
402
|
+
setNote(null)
|
|
403
|
+
callHost('/attachments/clear-orphans', { confirm: true })
|
|
404
|
+
.then((payload) => {
|
|
405
|
+
setNote({ tone: 'ok', text: payload.message || '已清理' })
|
|
406
|
+
return callHost('/attachments', null)
|
|
407
|
+
})
|
|
408
|
+
.then((fresh) => setMeta(fresh))
|
|
409
|
+
.catch((reason) => setNote({ tone: 'bad', text: '清理失败:' + String(reason.message || reason) }))
|
|
410
|
+
.finally(() => setBusy(false))
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const items = Array.isArray(meta.items) ? meta.items : []
|
|
414
|
+
const rows = items.map((item, index) => {
|
|
415
|
+
const label = item.names && item.names.length > 0
|
|
416
|
+
? item.names.join('、')
|
|
417
|
+
: String(item.id).slice(0, 16) + '…'
|
|
418
|
+
const owners = Array.isArray(item.sessions) && item.sessions.length > 0
|
|
419
|
+
? item.sessions.map((owner) => owner.title || owner.id).join('、')
|
|
420
|
+
: '孤儿 · 没有任何会话引用'
|
|
421
|
+
return h('div', {
|
|
422
|
+
key: String(item.id) + ':' + index,
|
|
423
|
+
className: 'dsb-att-row' + (item.orphan ? ' orphan' : ''),
|
|
424
|
+
},
|
|
425
|
+
h('div', { className: 'dsb-att-name', title: String(item.id) }, label),
|
|
426
|
+
h('div', { className: 'dsb-att-meta', title: owners }, elideMiddle(owners, 46)),
|
|
427
|
+
h('div', { className: 'dsb-att-size' }, formatBytes(item.bytes)))
|
|
428
|
+
})
|
|
429
|
+
|
|
430
|
+
const summary = '共 ' + meta.total + ' 个附件 · ' + formatBytes(meta.totalBytes)
|
|
431
|
+
+ (meta.orphanCount > 0
|
|
432
|
+
? ';其中 ' + meta.orphanCount + ' 个孤儿 · ' + formatBytes(meta.orphanBytes)
|
|
433
|
+
: ';没有孤儿')
|
|
434
|
+
|
|
435
|
+
const footer = []
|
|
436
|
+
if (meta.orphanCount > 0) {
|
|
437
|
+
footer.push(h('button', {
|
|
438
|
+
key: 'clear',
|
|
439
|
+
type: 'button',
|
|
440
|
+
className: 'dsb-btn' + (armed ? ' danger' : ' dangeroutline'),
|
|
441
|
+
disabled: busy,
|
|
442
|
+
onClick: clear,
|
|
443
|
+
}, busy ? '清理中…' : armed ? '确认清理 ' + meta.orphanCount + ' 个' : '清理孤儿'))
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const content = [
|
|
447
|
+
h('div', { key: 'head', className: 'dsb-att-head' },
|
|
448
|
+
h('span', { className: 'dsb-path', title: meta.store }, elideMiddle(meta.store, 86)),
|
|
449
|
+
h('button', { key: 'open', type: 'button', className: 'dsb-btn small', onClick: openFolder }, '打开文件夹')),
|
|
450
|
+
h('p', { key: 'sum', className: 'dsb-att-sum' }, summary),
|
|
451
|
+
note !== null
|
|
452
|
+
? h('div', { key: 'note', className: 'dsb-verdict ' + note.tone, style: { marginTop: 0, marginBottom: 10 } }, note.text)
|
|
453
|
+
: null,
|
|
454
|
+
h('div', { key: 'list', className: 'dsb-att-list' }, rows),
|
|
455
|
+
h('p', { key: 'hint', className: 'dsb-sub', style: { marginTop: 10, marginBottom: 0 } },
|
|
456
|
+
'「孤儿」= 没有任何现存会话的结构化引用。附件按内容去重、全局共享,所以一个附件可能被多个会话引用。'),
|
|
457
|
+
]
|
|
458
|
+
|
|
459
|
+
// 优先用宿主自带的 Modal:右上角自带关闭叉、留白和字号跟主界面一致。
|
|
460
|
+
if (NativeModal) {
|
|
461
|
+
return h(NativeModal, {
|
|
462
|
+
open: true,
|
|
463
|
+
title: '附件仓库',
|
|
464
|
+
closeLabel: '关闭',
|
|
465
|
+
onClose: close,
|
|
466
|
+
className: 'dsb-att-modal',
|
|
467
|
+
footer: footer.length > 0 ? footer : undefined,
|
|
468
|
+
}, content)
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// 退路:自绘弹层(同样把关闭放在右上角)。
|
|
472
|
+
return h('div', { className: 'dsb-overlay', onClick: (event) => { if (event.target === event.currentTarget) close() } },
|
|
473
|
+
h('div', { className: 'dsb-card wide', role: 'dialog', 'aria-modal': 'true' },
|
|
474
|
+
h('button', { type: 'button', className: 'dsb-dlg-x', 'aria-label': '关闭', onClick: close }, '×'),
|
|
475
|
+
content,
|
|
476
|
+
footer.length > 0 ? h('div', { className: 'dsb-foot' }, footer) : null))
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/* ── 侧边栏那一页:已删除的会话 + 图片缓存 + 附件仓库 ─────────── */
|
|
480
|
+
|
|
481
|
+
function BinPage({ attachmentsStore }) {
|
|
482
|
+
const [entries, setEntries] = React.useState(null)
|
|
483
|
+
const [listError, setListError] = React.useState(null)
|
|
484
|
+
const [busy, setBusy] = React.useState('')
|
|
485
|
+
const [note, setNote] = React.useState(null)
|
|
486
|
+
|
|
487
|
+
const [cache, setCache] = React.useState(null)
|
|
488
|
+
const [cacheError, setCacheError] = React.useState(null)
|
|
489
|
+
const [armed, setArmed] = React.useState(false)
|
|
490
|
+
const [cacheBusy, setCacheBusy] = React.useState(false)
|
|
491
|
+
const [cacheNote, setCacheNote] = React.useState(null)
|
|
492
|
+
|
|
493
|
+
// 「彻底删除」按行独立上膛,6 秒内不再点就自动取消。
|
|
494
|
+
const [forgetArmed, setForgetArmed] = React.useState('')
|
|
495
|
+
|
|
496
|
+
// 附件仓库盘点的结果摘要(详情在弹层里)
|
|
497
|
+
const [attachBusy, setAttachBusy] = React.useState(false)
|
|
498
|
+
const [attachSummary, setAttachSummary] = React.useState(null)
|
|
499
|
+
|
|
500
|
+
const loadList = React.useCallback(() => {
|
|
501
|
+
callHost('/list', null)
|
|
502
|
+
.then((payload) => { setEntries(payload.entries || []); setListError(null) })
|
|
503
|
+
.catch((reason) => { setListError(String(reason.message || reason)); setEntries([]) })
|
|
504
|
+
}, [])
|
|
505
|
+
|
|
506
|
+
const loadCache = React.useCallback(() => {
|
|
507
|
+
callHost('/cache', null)
|
|
508
|
+
.then((payload) => { setCache(payload); setCacheError(null) })
|
|
509
|
+
.catch((reason) => { setCacheError(String(reason.message || reason)); setCache(null) })
|
|
510
|
+
}, [])
|
|
511
|
+
|
|
512
|
+
React.useEffect(() => { loadList(); loadCache() }, [loadList, loadCache])
|
|
513
|
+
|
|
514
|
+
// 「清理」要点两下:第一下上膛,6 秒内不再点就自动取消。
|
|
515
|
+
React.useEffect(() => {
|
|
516
|
+
if (!armed) return undefined
|
|
517
|
+
const timer = setTimeout(() => setArmed(false), 6000)
|
|
518
|
+
return () => clearTimeout(timer)
|
|
519
|
+
}, [armed])
|
|
520
|
+
|
|
521
|
+
React.useEffect(() => {
|
|
522
|
+
if (forgetArmed === '') return undefined
|
|
523
|
+
const timer = setTimeout(() => setForgetArmed(''), 6000)
|
|
524
|
+
return () => clearTimeout(timer)
|
|
525
|
+
}, [forgetArmed])
|
|
526
|
+
|
|
527
|
+
const restore = (sid) => {
|
|
528
|
+
setBusy(sid)
|
|
529
|
+
setNote(null)
|
|
530
|
+
callHost('/restore', { sessionId: sid })
|
|
531
|
+
.then((payload) => {
|
|
532
|
+
if (payload.reattached) {
|
|
533
|
+
setNote({
|
|
534
|
+
tone: 'ok',
|
|
535
|
+
text: payload.positionRestored
|
|
536
|
+
? '已恢复到原来的工作区,位置也和删除前一致。刷新页面后就能看到它。'
|
|
537
|
+
: '已恢复到原来的工作区,但位置没能放回原处(它后面那个会话可能已经被删了)。',
|
|
538
|
+
reload: true,
|
|
539
|
+
})
|
|
540
|
+
} else {
|
|
541
|
+
setNote({
|
|
542
|
+
tone: 'bad',
|
|
543
|
+
text: '文件已经回到磁盘上的原位置,但没能挂回工作区' + (payload.attachError ? ':' + payload.attachError : '。'),
|
|
544
|
+
reload: false,
|
|
545
|
+
})
|
|
546
|
+
}
|
|
547
|
+
loadList()
|
|
548
|
+
})
|
|
549
|
+
.catch((reason) => setNote({ tone: 'bad', text: '恢复失败:' + String(reason.message || reason), reload: false }))
|
|
550
|
+
.finally(() => setBusy(''))
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
const clearCache = () => {
|
|
554
|
+
if (!armed) {
|
|
555
|
+
setArmed(true)
|
|
556
|
+
setCacheNote(null)
|
|
557
|
+
return
|
|
558
|
+
}
|
|
559
|
+
setArmed(false)
|
|
560
|
+
setCacheBusy(true)
|
|
561
|
+
setCacheNote(null)
|
|
562
|
+
callHost('/cache/clear', { confirm: true })
|
|
563
|
+
.then((payload) => {
|
|
564
|
+
setCacheNote({ tone: 'ok', text: payload.message || '已清理' })
|
|
565
|
+
loadCache()
|
|
566
|
+
})
|
|
567
|
+
.catch((reason) => setCacheNote({ tone: 'bad', text: '清理失败:' + String(reason.message || reason) }))
|
|
568
|
+
.finally(() => setCacheBusy(false))
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// 盘点附件仓库:结果直接交给弹层展示。
|
|
572
|
+
const checkAttachments = () => {
|
|
573
|
+
setAttachBusy(true)
|
|
574
|
+
callHost('/attachments', null)
|
|
575
|
+
.then((payload) => {
|
|
576
|
+
setAttachSummary(payload.orphanCount === 0
|
|
577
|
+
? '没有孤儿(共 ' + payload.total + ' 个)'
|
|
578
|
+
: payload.orphanCount + ' 个孤儿 · ' + formatBytes(payload.orphanBytes))
|
|
579
|
+
attachmentsStore.open(payload)
|
|
580
|
+
})
|
|
581
|
+
.catch((reason) => {
|
|
582
|
+
setAttachSummary('检查失败')
|
|
583
|
+
setNote({ tone: 'bad', text: '附件盘点失败:' + String(reason.message || reason), reload: false })
|
|
584
|
+
})
|
|
585
|
+
.finally(() => setAttachBusy(false))
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const forget = (sid) => {
|
|
589
|
+
if (forgetArmed !== sid) {
|
|
590
|
+
setForgetArmed(sid)
|
|
591
|
+
setNote(null)
|
|
592
|
+
return
|
|
593
|
+
}
|
|
594
|
+
setForgetArmed('')
|
|
595
|
+
setBusy(sid)
|
|
596
|
+
setNote(null)
|
|
597
|
+
callHost('/forget', { sessionId: sid, confirm: true })
|
|
598
|
+
.then((payload) => {
|
|
599
|
+
setNote({ tone: 'ok', text: payload.message || '删除记录已移进回收站。', reload: false })
|
|
600
|
+
loadList()
|
|
601
|
+
})
|
|
602
|
+
.catch((reason) => setNote({ tone: 'bad', text: '彻底删除失败:' + String(reason.message || reason), reload: false }))
|
|
603
|
+
.finally(() => setBusy(''))
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const rows = (entries || []).map((entry) => h('div', { key: entry.sid, className: 'dsb-item' },
|
|
607
|
+
h('div', { className: 'dsb-item-main' },
|
|
608
|
+
h('div', { className: 'dsb-item-title' }, entry.title || entry.sid),
|
|
609
|
+
h('div', { className: 'dsb-item-meta' },
|
|
610
|
+
'删除于 ' + formatTime(entry.deletedAt)
|
|
611
|
+
+ ' · ' + (entry.daysLeft > 0 ? '还有 ' + entry.daysLeft + ' 天可恢复' : '保留期已过')
|
|
612
|
+
+ ' · ' + (entry.inBin ? '文件在回收站里' : '文件已回到原位'))),
|
|
613
|
+
h('div', { className: 'dsb-item-actions' },
|
|
614
|
+
h('button', {
|
|
615
|
+
type: 'button',
|
|
616
|
+
className: 'dsb-btn',
|
|
617
|
+
disabled: busy !== '' || entry.daysLeft <= 0 || !entry.inBin,
|
|
618
|
+
onClick: () => restore(entry.sid),
|
|
619
|
+
}, busy === entry.sid ? '恢复中…' : '恢复'),
|
|
620
|
+
h('button', {
|
|
621
|
+
type: 'button',
|
|
622
|
+
className: 'dsb-btn' + (forgetArmed === entry.sid ? ' danger' : ' dangeroutline'),
|
|
623
|
+
disabled: busy !== '',
|
|
624
|
+
title: '把这条删除记录现在移进回收站:页面不再显示它,这个会话也就无法再从这里恢复',
|
|
625
|
+
onClick: () => forget(entry.sid),
|
|
626
|
+
}, forgetArmed === entry.sid ? '确认彻底删除' : '彻底删除'))))
|
|
627
|
+
|
|
628
|
+
const cacheSize = cache && cache.exists ? formatBytes(cache.bytes) : '空'
|
|
629
|
+
|
|
630
|
+
return h('div', { className: 'dsb-page' },
|
|
631
|
+
h('div', { className: 'dsb-head' },
|
|
632
|
+
h('h1', null, '回收站'),
|
|
633
|
+
h('button', {
|
|
634
|
+
type: 'button',
|
|
635
|
+
className: 'dsb-btn small',
|
|
636
|
+
title: '重新加载当前页面(DSH 桌面版没有绑定 F5 / Ctrl+R,这里是唯一的内置刷新入口)',
|
|
637
|
+
onClick: () => window.location.reload(),
|
|
638
|
+
}, '刷新页面')),
|
|
639
|
+
h('p', { className: 'intro' },
|
|
640
|
+
'这里列出本插件删除的对话。它们的会话目录、索引文件和相关附件都在 Windows 回收站里,7 天内点「恢复」就能放回原来的工作区和原位置;满 7 天后,这台机器上的删除记录本身也会被移进回收站,届时不再支持在这里恢复。'),
|
|
641
|
+
entries !== null ? h('p', { className: 'dsb-count' }, '共 ' + entries.length + ' 条') : null,
|
|
642
|
+
listError !== null ? h('div', { className: 'dsb-verdict bad', style: { marginTop: 10 } }, listError) : null,
|
|
643
|
+
note !== null ? h('div', { className: 'dsb-verdict ' + note.tone, style: { marginTop: 10 } },
|
|
644
|
+
note.text,
|
|
645
|
+
note.reload ? h('button', {
|
|
646
|
+
type: 'button',
|
|
647
|
+
className: 'dsb-btn',
|
|
648
|
+
style: { marginLeft: 10, height: 24 },
|
|
649
|
+
onClick: () => window.location.reload(),
|
|
650
|
+
}, '刷新页面') : null) : null,
|
|
651
|
+
entries === null ? h('p', { className: 'dsb-empty' }, '正在读取…') : null,
|
|
652
|
+
entries !== null && rows.length === 0 ? h('p', { className: 'dsb-empty' }, '目前没有已删除的对话。') : null,
|
|
653
|
+
h('div', { className: 'dsb-list' }, rows),
|
|
654
|
+
|
|
655
|
+
// 图片缓存:只占右下角一小块,不抢列表的位置。
|
|
656
|
+
cacheNote !== null
|
|
657
|
+
? h('div', { className: 'dsb-cache-note' + (cacheNote.tone === 'bad' ? ' bad' : '') }, cacheNote.text)
|
|
658
|
+
: null,
|
|
659
|
+
h('div', { className: 'dsb-footrow' },
|
|
660
|
+
cacheError !== null
|
|
661
|
+
? h('span', { className: 'dsb-cache-label bad' }, '图片缓存读取失败')
|
|
662
|
+
: h('span', {
|
|
663
|
+
className: 'dsb-cache-label',
|
|
664
|
+
title: (cache && cache.exists ? cache.files + ' 个文件\n' : '')
|
|
665
|
+
+ (cache && cache.path ? cache.path + '\n' : '')
|
|
666
|
+
+ '这里只统计「需要缩放或重新编码」的图片派生版本。\n'
|
|
667
|
+
+ '尺寸和体积本来就符合模型要求的图片会被原样发送,不产生缓存文件,\n'
|
|
668
|
+
+ '所以发图不等于这里会变大。',
|
|
669
|
+
}, '图片缓存 ' + (cache === null ? '…' : cacheSize)),
|
|
670
|
+
h('button', {
|
|
671
|
+
type: 'button',
|
|
672
|
+
className: 'dsb-btn small' + (armed ? ' danger' : ''),
|
|
673
|
+
disabled: cacheBusy || cache === null || !cache.exists || cache.files === 0,
|
|
674
|
+
title: '把图片缓存目录移进 Windows 回收站(不是永久删除)',
|
|
675
|
+
onClick: clearCache,
|
|
676
|
+
}, cacheBusy ? '清理中…' : armed ? '确认清理' : '清理')),
|
|
677
|
+
|
|
678
|
+
// 附件仓库盘点:列出每个附件、大小、被谁引用,以及谁没人引用。
|
|
679
|
+
h('div', { className: 'dsb-footrow secondary' },
|
|
680
|
+
h('span', {
|
|
681
|
+
className: 'dsb-cache-label',
|
|
682
|
+
title: '扫描整个附件仓库,列出每个附件被哪些会话引用。\n没有任何会话引用的就是孤儿,可以移进回收站。',
|
|
683
|
+
}, '孤儿附件' + (attachSummary === null ? '' : ' ' + attachSummary)),
|
|
684
|
+
h('button', {
|
|
685
|
+
type: 'button',
|
|
686
|
+
className: 'dsb-btn small',
|
|
687
|
+
disabled: attachBusy,
|
|
688
|
+
onClick: checkAttachments,
|
|
689
|
+
}, attachBusy ? '检查中…' : attachSummary === null ? '检查' : '重新检查')))
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/* ── 挂载 ──────────────────────────────────────────────────────── */
|
|
693
|
+
|
|
694
|
+
function apply(ctx) {
|
|
695
|
+
ensureStyle()
|
|
696
|
+
const purgeStore = createStore()
|
|
697
|
+
const attachmentsStore = createStore()
|
|
698
|
+
const slots = ctx.slots
|
|
699
|
+
|
|
700
|
+
// 左侧边栏的一项:图标 + 标题,和「插件」「自动化任务」同级。
|
|
701
|
+
// order 15 让它排在「自动化任务」(10)之后、「更多」溢出菜单之前。
|
|
702
|
+
slots.inject('sidebar.panellist', () => slots.register({
|
|
703
|
+
name: 'sidebar.panellist',
|
|
704
|
+
id: PANEL_ID,
|
|
705
|
+
order: 15,
|
|
706
|
+
label: () => '回收站',
|
|
707
|
+
}, TrashPanelIcon))
|
|
708
|
+
|
|
709
|
+
// 点开这一项时主区域显示的内容。
|
|
710
|
+
slots.inject('main', () => slots.register({
|
|
711
|
+
name: 'main',
|
|
712
|
+
key: PANEL_ID,
|
|
713
|
+
inject: () => ({ attachmentsStore }),
|
|
714
|
+
}, BinPage))
|
|
715
|
+
|
|
716
|
+
// 会话「⋯」菜单:官方条目的 order 是 pin 100 / rename 200 / fork 300 /
|
|
717
|
+
// archive 400 / session-id 450。用 410 紧跟在「归档会话」下面。
|
|
718
|
+
slots.inject('sidebar.workspaces.session.menu.item', () => slots.register({
|
|
719
|
+
name: 'sidebar.workspaces.session.menu.item',
|
|
720
|
+
id: 'recyclebin-delete',
|
|
721
|
+
order: 410,
|
|
722
|
+
inject: () => ({ purgeStore }),
|
|
723
|
+
}, DeleteSessionMenuItem))
|
|
724
|
+
|
|
725
|
+
slots.inject('shell.overlay', () => slots.register({
|
|
726
|
+
name: 'shell.overlay',
|
|
727
|
+
id: 'recyclebin-dialog',
|
|
728
|
+
inject: () => ({ purgeStore }),
|
|
729
|
+
}, DeleteDialog))
|
|
730
|
+
|
|
731
|
+
slots.inject('shell.overlay', () => slots.register({
|
|
732
|
+
name: 'shell.overlay',
|
|
733
|
+
id: 'recyclebin-attachments',
|
|
734
|
+
inject: () => ({ attachmentsStore }),
|
|
735
|
+
}, AttachmentsDialog))
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
return { name: NS, inject: ['slots'], apply }
|
|
739
|
+
},
|
|
740
|
+
})
|