@andy.ian/dsh-homing 2.1.2 → 2.1.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/index.js +115 -46
- package/lib/compress.mjs +164 -0
- package/lib/files-page.mjs +63 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -27,7 +27,8 @@ import * as deviceStore from './lib/devices.mjs';
|
|
|
27
27
|
import { createRestartPolicy } from './restart/face.mjs';
|
|
28
28
|
import * as ptyrun from './lib/pty.mjs';
|
|
29
29
|
import { renderTermPage } from './lib/term-page.mjs';
|
|
30
|
-
import
|
|
30
|
+
import * as compress from './lib/compress.mjs';
|
|
31
|
+
import { renderListing as renderFileListing, renderFile as renderFileView, renderRunPage, renderGitPage, renderEditPage, renderCompressPage } from './lib/files-page.mjs';
|
|
31
32
|
import { checkUnsafeOrigin } from './lib/csrf.mjs';
|
|
32
33
|
import * as limits from './lib/limits.mjs';
|
|
33
34
|
|
|
@@ -530,15 +531,16 @@ const MOBILE_JS = `(() => {
|
|
|
530
531
|
closeRightBar()
|
|
531
532
|
}
|
|
532
533
|
|
|
533
|
-
/* ----------
|
|
534
|
-
* 在 DSH
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
*
|
|
534
|
+
/* ---------- SESSION_MENU_ITEMS ----------
|
|
535
|
+
* 在 DSH 会话「…」菜单里追加两项:
|
|
536
|
+
* - 下载工作区文件:跳到文件页(可逐个文件下载)
|
|
537
|
+
* - 重启 DSH / 守护进程:跳到重启页
|
|
538
|
+
* 做法:复制一个原生菜单项(连同图标容器与样式),只替换文字和图标路径;
|
|
539
|
+
* 每轮先清掉旧项,并全局 prune,保证每项最多一个。
|
|
538
540
|
*/
|
|
539
541
|
const MENU_HINT = /下载 Session 日志|复制会话为 Markdown|反馈/u
|
|
540
|
-
|
|
541
|
-
const
|
|
542
|
+
const ICON_RESTART = '<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/>'
|
|
543
|
+
const ICON_DOWNLOAD = '<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="M7 10l5 5 5-5"/><path d="M12 15V3"/>'
|
|
542
544
|
let menuTimer = null
|
|
543
545
|
|
|
544
546
|
const textNodeMatching = (node, pattern) => {
|
|
@@ -549,9 +551,33 @@ const MOBILE_JS = `(() => {
|
|
|
549
551
|
return null
|
|
550
552
|
}
|
|
551
553
|
|
|
554
|
+
const buildMenuItem = (template, label, icon, action) => {
|
|
555
|
+
const link = template.cloneNode(true)
|
|
556
|
+
link.setAttribute('role', 'menuitem')
|
|
557
|
+
link.setAttribute('href', '#')
|
|
558
|
+
link.style.textDecoration = 'none'
|
|
559
|
+
const textNode = textNodeMatching(link, /反馈|下载 Session 日志|复制会话为 Markdown/u)
|
|
560
|
+
if (textNode !== null) textNode.nodeValue = label
|
|
561
|
+
else link.textContent = label
|
|
562
|
+
const svg = link.querySelector('svg')
|
|
563
|
+
if (svg !== null) {
|
|
564
|
+
svg.innerHTML = icon
|
|
565
|
+
svg.setAttribute('viewBox', '0 0 24 24')
|
|
566
|
+
svg.setAttribute('fill', 'none')
|
|
567
|
+
svg.setAttribute('stroke', 'currentColor')
|
|
568
|
+
svg.setAttribute('stroke-width', '2')
|
|
569
|
+
svg.setAttribute('stroke-linecap', 'round')
|
|
570
|
+
svg.setAttribute('stroke-linejoin', 'round')
|
|
571
|
+
}
|
|
572
|
+
link.addEventListener('click', (event) => {
|
|
573
|
+
event.preventDefault()
|
|
574
|
+
event.stopPropagation()
|
|
575
|
+
action()
|
|
576
|
+
}, true)
|
|
577
|
+
return link
|
|
578
|
+
}
|
|
579
|
+
|
|
552
580
|
const enhanceMenus = () => {
|
|
553
|
-
// 每个 role=menu 容器只处理一次;注意菜单项外面可能还包了一层 wrapper,
|
|
554
|
-
// 所以必须向上找到真正的菜单容器,而不是用 item.parentElement。
|
|
555
581
|
const done = new Set()
|
|
556
582
|
for (const item of document.querySelectorAll('[role="menuitem"]')) {
|
|
557
583
|
const menu = item.closest('[role="menu"]') ?? item.parentElement
|
|
@@ -559,52 +585,33 @@ const MOBILE_JS = `(() => {
|
|
|
559
585
|
if (!MENU_HINT.test(menu.textContent || '')) continue
|
|
560
586
|
done.add(menu)
|
|
561
587
|
|
|
562
|
-
|
|
563
|
-
for (const old of menu.querySelectorAll('[data-dsh-homing-restart]')) old.remove()
|
|
588
|
+
for (const old of menu.querySelectorAll('[data-dsh-homing-download],[data-dsh-homing-restart]')) old.remove()
|
|
564
589
|
|
|
565
590
|
const items = [...menu.querySelectorAll('[role="menuitem"]')]
|
|
566
591
|
const template = items.find((node) => node.querySelector('svg')) ?? items[0]
|
|
567
592
|
if (!template) continue
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
else link.textContent = '重启 DSH / 守护进程'
|
|
577
|
-
|
|
578
|
-
const svg = link.querySelector('svg')
|
|
579
|
-
if (svg !== null) {
|
|
580
|
-
// 图标按菜单项的描边风格来,避免 fill=currentColor 渲染成一坨实心圆
|
|
581
|
-
svg.innerHTML = RESTART_ICON
|
|
582
|
-
svg.setAttribute('viewBox', '0 0 24 24')
|
|
583
|
-
svg.setAttribute('fill', 'none')
|
|
584
|
-
svg.setAttribute('stroke', 'currentColor')
|
|
585
|
-
svg.setAttribute('stroke-width', '2')
|
|
586
|
-
svg.setAttribute('stroke-linecap', 'round')
|
|
587
|
-
svg.setAttribute('stroke-linejoin', 'round')
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
link.addEventListener('click', (event) => {
|
|
591
|
-
event.preventDefault()
|
|
592
|
-
event.stopPropagation()
|
|
593
|
-
window.location.assign('/dsh_homing/restart')
|
|
594
|
-
}, true)
|
|
595
|
-
menu.appendChild(link)
|
|
593
|
+
|
|
594
|
+
const download = buildMenuItem(template, '下载工作区文件', ICON_DOWNLOAD, () => goFiles())
|
|
595
|
+
download.setAttribute('data-dsh-homing-download', '1')
|
|
596
|
+
const restart = buildMenuItem(template, '重启 DSH / 守护进程', ICON_RESTART, () => window.location.assign('/dsh_homing/restart'))
|
|
597
|
+
restart.setAttribute('data-dsh-homing-restart', '1')
|
|
598
|
+
|
|
599
|
+
menu.appendChild(download)
|
|
600
|
+
menu.appendChild(restart)
|
|
596
601
|
}
|
|
597
602
|
}
|
|
598
603
|
|
|
599
|
-
//
|
|
600
|
-
const
|
|
601
|
-
const
|
|
602
|
-
|
|
604
|
+
// 兜底:无论菜单容器怎么嵌套,每类最多保留一个
|
|
605
|
+
const pruneMenuItems = () => {
|
|
606
|
+
for (const selector of ['[data-dsh-homing-download]', '[data-dsh-homing-restart]']) {
|
|
607
|
+
const all = [...document.querySelectorAll(selector)]
|
|
608
|
+
for (let i = 0; i < all.length - 1; i += 1) all[i].remove()
|
|
609
|
+
}
|
|
603
610
|
}
|
|
604
611
|
|
|
605
612
|
const menuObserver = new MutationObserver(() => {
|
|
606
613
|
if (menuTimer) return
|
|
607
|
-
menuTimer = setTimeout(() => { menuTimer = null; enhanceMenus();
|
|
614
|
+
menuTimer = setTimeout(() => { menuTimer = null; enhanceMenus(); pruneMenuItems() }, 80)
|
|
608
615
|
})
|
|
609
616
|
menuObserver.observe(document.body, { childList: true, subtree: true })
|
|
610
617
|
|
|
@@ -2355,7 +2362,7 @@ function createBridge({ getUpstreamPort, mintCookie, auth, config, dir, secureCo
|
|
|
2355
2362
|
return;
|
|
2356
2363
|
}
|
|
2357
2364
|
|
|
2358
|
-
if (url.pathname === '/files' || url.pathname === '/files/view' || url.pathname === '/files/run'
|
|
2365
|
+
if (url.pathname === '/files' || url.pathname === '/files/view' || url.pathname === '/files/download' || url.pathname === '/files/compress' || url.pathname === '/files/run'
|
|
2359
2366
|
|| url.pathname === '/files/rename'
|
|
2360
2367
|
|| url.pathname === '/files/delete' || url.pathname === '/files/paste'
|
|
2361
2368
|
|| url.pathname === '/files/mkdir' || url.pathname === '/files/newfile') {
|
|
@@ -2402,6 +2409,68 @@ function createBridge({ getUpstreamPort, mintCookie, auth, config, dir, secureCo
|
|
|
2402
2409
|
return;
|
|
2403
2410
|
}
|
|
2404
2411
|
|
|
2412
|
+
if (url.pathname === '/files/compress' && req.method === 'GET') {
|
|
2413
|
+
const target = filebrowse.resolvePath(url.searchParams.get('path') ?? '');
|
|
2414
|
+
const tools = compress.availableBackends().map((item) => ({ label: item.label, strength: item.strength, level: item.level }));
|
|
2415
|
+
appendAudit(dir, 'file-compress-view', { path: target, tools: tools.length });
|
|
2416
|
+
sendHtml(renderCompressPage({ target, archive: '', tools }));
|
|
2417
|
+
return;
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
if (url.pathname === '/files/compress' && req.method === 'POST') {
|
|
2421
|
+
const form = new URLSearchParams(await readBody(req, 64 * 1024));
|
|
2422
|
+
const target = filebrowse.resolvePath(form.get('path') ?? '');
|
|
2423
|
+
const password = form.get('password') ?? '';
|
|
2424
|
+
const confirm = form.get('confirm') ?? '';
|
|
2425
|
+
const tools = compress.availableBackends().map((item) => ({ label: item.label, strength: item.strength, level: item.level }));
|
|
2426
|
+
if (password !== confirm) {
|
|
2427
|
+
sendHtml(renderCompressPage({ target, archive: '', tools, message: '两次输入的密码不一致', isError: true }));
|
|
2428
|
+
return;
|
|
2429
|
+
}
|
|
2430
|
+
const result = compress.createEncryptedArchive({ target, password });
|
|
2431
|
+
appendAudit(dir, 'file-compress', {
|
|
2432
|
+
path: target,
|
|
2433
|
+
ok: result.ok,
|
|
2434
|
+
tool: result.tool ?? null,
|
|
2435
|
+
bytes: result.bytes ?? 0,
|
|
2436
|
+
error: result.error ?? null,
|
|
2437
|
+
});
|
|
2438
|
+
sendHtml(renderCompressPage({
|
|
2439
|
+
target,
|
|
2440
|
+
archive: result.ok ? result.path : '',
|
|
2441
|
+
tools,
|
|
2442
|
+
tool: result.tool ?? '',
|
|
2443
|
+
strength: result.strength ?? '',
|
|
2444
|
+
message: result.ok ? '已生成加密压缩包' : result.error,
|
|
2445
|
+
isError: !result.ok,
|
|
2446
|
+
done: result.ok,
|
|
2447
|
+
}));
|
|
2448
|
+
return;
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
if (url.pathname === '/files/download' && req.method === 'GET') {
|
|
2452
|
+
const target = filebrowse.resolvePath(url.searchParams.get('path') ?? '');
|
|
2453
|
+
let stat = null;
|
|
2454
|
+
try { stat = fs.statSync(target); } catch { stat = null; }
|
|
2455
|
+
if (!stat || !stat.isFile()) {
|
|
2456
|
+
res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store' });
|
|
2457
|
+
res.end('文件不存在或不是普通文件\n');
|
|
2458
|
+
return;
|
|
2459
|
+
}
|
|
2460
|
+
const name = path.basename(target);
|
|
2461
|
+
const ascii = name.replace(/[^\x20-\x7E]/gu, '_').replace(/["\\]/gu, '_');
|
|
2462
|
+
appendAudit(dir, 'file-download', { path: target, bytes: stat.size });
|
|
2463
|
+
res.writeHead(200, {
|
|
2464
|
+
'content-type': 'application/octet-stream',
|
|
2465
|
+
'content-length': String(stat.size),
|
|
2466
|
+
'content-disposition': `attachment; filename="${ascii}"; filename*=UTF-8''${encodeURIComponent(name)}`,
|
|
2467
|
+
'cache-control': 'no-store',
|
|
2468
|
+
'x-content-type-options': 'nosniff',
|
|
2469
|
+
});
|
|
2470
|
+
fs.createReadStream(target).pipe(res);
|
|
2471
|
+
return;
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2405
2474
|
if (url.pathname === '/files/view' && req.method === 'GET') {
|
|
2406
2475
|
const info = filebrowse.readTextFile(url.searchParams.get('path') ?? '');
|
|
2407
2476
|
appendAudit(dir, 'file-view', { path: info.path });
|
package/lib/compress.mjs
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本机加密压缩(跨平台,不内置任何二进制)
|
|
3
|
+
*
|
|
4
|
+
* 设计:
|
|
5
|
+
* - 只调用机器上**已安装**的压缩工具,按可用性自动选择;
|
|
6
|
+
* - 支持 7-Zip / WinRAR / Info-ZIP zip,加密强度不同,页面上如实标注;
|
|
7
|
+
* - 插件目录不带二进制,避免平台绑定与体积膨胀;
|
|
8
|
+
* - 用户也可以把工具放进 <DSH_HOME>/integrations/dsh-homing/tools/,
|
|
9
|
+
* 或用 DSH_HOMING_ARCHIVER 指定。
|
|
10
|
+
*/
|
|
11
|
+
import fs from 'node:fs'
|
|
12
|
+
import path from 'node:path'
|
|
13
|
+
import { spawnSync } from 'node:child_process'
|
|
14
|
+
|
|
15
|
+
/** 工具候选:id → 可执行文件候选名 + 归档扩展名 + 加密说明 */
|
|
16
|
+
export const BACKENDS = [
|
|
17
|
+
{
|
|
18
|
+
id: '7z',
|
|
19
|
+
label: '7-Zip',
|
|
20
|
+
bins: ['7z', '7za', '7zr', '7zz'],
|
|
21
|
+
ext: '7z',
|
|
22
|
+
strength: 'AES-256(文件名也加密)',
|
|
23
|
+
level: 'strong',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: 'rar',
|
|
27
|
+
label: 'WinRAR',
|
|
28
|
+
bins: ['rar'],
|
|
29
|
+
ext: 'rar',
|
|
30
|
+
strength: 'AES-256(文件名也加密)',
|
|
31
|
+
level: 'strong',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'zip',
|
|
35
|
+
label: 'Info-ZIP',
|
|
36
|
+
bins: ['zip'],
|
|
37
|
+
ext: 'zip',
|
|
38
|
+
strength: 'ZipCrypto(较弱,仅兼容性用途)',
|
|
39
|
+
level: 'weak',
|
|
40
|
+
},
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
const TOOL_DIRS = () => {
|
|
44
|
+
const home = process.env.DSH_HOME?.trim() || path.join(process.env.USERPROFILE || process.env.HOME || '.', '.dsh')
|
|
45
|
+
return [
|
|
46
|
+
process.env.DSH_HOMING_TOOLS?.trim(),
|
|
47
|
+
path.join(home, 'integrations', 'dsh-homing', 'tools'),
|
|
48
|
+
].filter(Boolean)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const which = (name) => {
|
|
52
|
+
const probe = spawnSync(name, ['--help'], { encoding: 'utf8', windowsHide: true, timeout: 8000 })
|
|
53
|
+
// 有的工具 --help 返回非 0,但只要能执行起来(不是 ENOENT)就算找到
|
|
54
|
+
return probe.error ? null : name
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 在指定目录里找可执行文件(Windows 补 .exe) */
|
|
58
|
+
function findInDirs(dirs, name) {
|
|
59
|
+
const names = process.platform === 'win32' ? [`${name}.exe`, name] : [name]
|
|
60
|
+
for (const dir of dirs) {
|
|
61
|
+
for (const file of names) {
|
|
62
|
+
const full = path.join(dir, file)
|
|
63
|
+
try {
|
|
64
|
+
if (fs.statSync(full).isFile()) return full
|
|
65
|
+
} catch { /* 不存在 */ }
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return null
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 返回当前可用的后端列表(按优先级),每项含 bin 实际路径 */
|
|
72
|
+
export function availableBackends() {
|
|
73
|
+
const dirs = TOOL_DIRS()
|
|
74
|
+
const explicit = process.env.DSH_HOMING_ARCHIVER?.trim()
|
|
75
|
+
const found = []
|
|
76
|
+
for (const backend of BACKENDS) {
|
|
77
|
+
const fromExplicit = explicit && backend.bins.some((name) => explicit.toLowerCase().includes(name)) ? explicit : null
|
|
78
|
+
const binaries = []
|
|
79
|
+
if (fromExplicit) binaries.push(fromExplicit)
|
|
80
|
+
for (const name of backend.bins) {
|
|
81
|
+
const local = findInDirs(dirs, name)
|
|
82
|
+
if (local) binaries.push(local)
|
|
83
|
+
const onPath = which(name)
|
|
84
|
+
if (onPath) binaries.push(onPath)
|
|
85
|
+
}
|
|
86
|
+
const unique = [...new Set(binaries)]
|
|
87
|
+
if (unique.length === 0) continue
|
|
88
|
+
found.push({ ...backend, bin: unique[0] })
|
|
89
|
+
}
|
|
90
|
+
return found
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 密码校验:太短起不到保护作用,太长没必要;返回错误文案或 null */
|
|
94
|
+
export function checkPassword(password) {
|
|
95
|
+
if (typeof password !== 'string' || password.length < 6) return '密码至少 6 位'
|
|
96
|
+
if (password.length > 128) return '密码最多 128 位'
|
|
97
|
+
return null
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function nextArchivePath(dir, base, ext) {
|
|
101
|
+
let archive = path.join(dir, `${base}.${ext}`)
|
|
102
|
+
for (let i = 2; fs.existsSync(archive) && i < 100; i += 1) archive = path.join(dir, `${base}-${i}.${ext}`)
|
|
103
|
+
return archive
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function run(bin, args, { cwd, timeoutMs }) {
|
|
107
|
+
return spawnSync(bin, args, { cwd, encoding: 'utf8', windowsHide: true, timeout: timeoutMs })
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 把 target(文件或目录)压缩成加密归档,放在同级目录。
|
|
112
|
+
* 返回 { ok, path, bytes, tool, strength, error }
|
|
113
|
+
*/
|
|
114
|
+
export function createEncryptedArchive({ target, password, timeoutMs = 10 * 60_000 }) {
|
|
115
|
+
const passwordError = checkPassword(password)
|
|
116
|
+
if (passwordError) return { ok: false, error: passwordError }
|
|
117
|
+
if (typeof target !== 'string' || target.trim() === '') return { ok: false, error: '路径为空' }
|
|
118
|
+
if (!fs.existsSync(target)) return { ok: false, error: '目标不存在' }
|
|
119
|
+
|
|
120
|
+
const backends = availableBackends()
|
|
121
|
+
if (backends.length === 0) {
|
|
122
|
+
return {
|
|
123
|
+
ok: false,
|
|
124
|
+
error: '本机没有可用的压缩工具:请安装 7-Zip / WinRAR / Info-ZIP,或把可执行文件放到 integrations/dsh-homing/tools/',
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const abs = path.resolve(target)
|
|
129
|
+
const dir = path.dirname(abs)
|
|
130
|
+
const base = path.basename(abs)
|
|
131
|
+
const failures = []
|
|
132
|
+
|
|
133
|
+
for (const backend of backends) {
|
|
134
|
+
const archive = nextArchivePath(dir, base, backend.ext)
|
|
135
|
+
let result = null
|
|
136
|
+
if (backend.id === '7z') {
|
|
137
|
+
result = run(backend.bin, ['a', '-t7z', `-p${password}`, '-mhe=on', '-y', archive, base], { cwd: dir, timeoutMs })
|
|
138
|
+
} else if (backend.id === 'rar') {
|
|
139
|
+
result = run(backend.bin, ['a', `-p${password}`, `-hp${password}`, '-y', archive, base], { cwd: dir, timeoutMs })
|
|
140
|
+
} else if (backend.id === 'zip') {
|
|
141
|
+
result = run(backend.bin, ['-r', '-P', password, archive, base], { cwd: dir, timeoutMs })
|
|
142
|
+
}
|
|
143
|
+
if (result === null) continue
|
|
144
|
+
|
|
145
|
+
if (result.error || result.status !== 0 || !fs.existsSync(archive)) {
|
|
146
|
+
try { fs.rmSync(archive, { force: true }) } catch { /* 忽略 */ }
|
|
147
|
+
const detail = String(result.stderr || result.stdout || result.error?.message || '').split('\n').filter(Boolean).slice(-1).join(' ')
|
|
148
|
+
failures.push(`${backend.label}: ${detail || ('退出码 ' + result.status)}`)
|
|
149
|
+
continue
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const stat = fs.statSync(archive)
|
|
153
|
+
return {
|
|
154
|
+
ok: true,
|
|
155
|
+
path: archive,
|
|
156
|
+
bytes: stat.size,
|
|
157
|
+
tool: backend.label,
|
|
158
|
+
strength: backend.strength,
|
|
159
|
+
level: backend.level,
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return { ok: false, error: `压缩失败(${failures.join(';')})` }
|
|
164
|
+
}
|
package/lib/files-page.mjs
CHANGED
|
@@ -117,6 +117,14 @@ const MENU_JS = `<script>
|
|
|
117
117
|
location.href = '/files/run?path=' + encodeURIComponent(path);
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
|
+
if (kind === 'download') {
|
|
121
|
+
location.href = '/files/download?path=' + encodeURIComponent(path);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (kind === 'compress') {
|
|
125
|
+
location.href = '/files/compress?path=' + encodeURIComponent(path);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
120
128
|
if (kind === 'copy' || kind === 'cut') {
|
|
121
129
|
try { localStorage.setItem('dsh-files-clip', JSON.stringify({ path: path, op: kind === 'cut' ? 'cut' : 'copy' })); } catch (error) { /* 忽略 */ }
|
|
122
130
|
return;
|
|
@@ -217,6 +225,8 @@ export function renderListing({ info, message, isError, home, dataDir, workspace
|
|
|
217
225
|
<button type="button" class="mm-btn" aria-haspopup="menu" title="更多操作">\u22ef</button>
|
|
218
226
|
<span class="rowmenu" hidden role="menu">
|
|
219
227
|
${entry.dir ? '' : `<a class="mi" role="menuitem" data-act="edit" data-path="${escapeHtml(entry.path)}" href="#"><span class="ico">\u270F\uFE0F</span>编辑</a>`}
|
|
228
|
+
${entry.dir ? '' : `<a class="mi" role="menuitem" data-act="download" data-path="${escapeHtml(entry.path)}" href="#"><span class="ico">\u2B07\uFE0F</span>下载</a>`}
|
|
229
|
+
<a class="mi" role="menuitem" data-act="compress" data-path="${escapeHtml(entry.path)}" href="#"><span class="ico">\u{1F512}</span>加密压缩</a>
|
|
220
230
|
${entry.runnable ? `<a class="mi" role="menuitem" data-act="run" data-path="${escapeHtml(entry.path)}" href="#"><span class="ico">\u25B6\uFE0F</span>执行</a>` : ''}
|
|
221
231
|
<a class="mi" role="menuitem" data-act="rename" data-path="${escapeHtml(entry.path)}" data-name="${escapeHtml(entry.name)}" href="#"><span class="ico">\u{1F3F7}\uFE0F</span>重命名</a>
|
|
222
232
|
<a class="mi" role="menuitem" data-act="cut" data-path="${escapeHtml(entry.path)}" href="#"><span class="ico">\u2702\uFE0F</span>剪切</a>
|
|
@@ -314,7 +324,59 @@ ${entry.dir ? `<a class="mi" role="menuitem" data-act="paste" data-path="${escap
|
|
|
314
324
|
return layout({ title: info.path, body })
|
|
315
325
|
}
|
|
316
326
|
|
|
317
|
-
/**
|
|
327
|
+
/** 加密压缩页:在电脑上生成加密归档,产物放在同级目录 */
|
|
328
|
+
export function renderCompressPage({ target, archive, message, isError, done = false, tools = [], tool = '', strength = '' }) {
|
|
329
|
+
const name = target.split(/[\\/]/u).pop() || target;
|
|
330
|
+
const dir = target.split(/[\\/]/u).slice(0, -1).join('/');
|
|
331
|
+
const toolsHtml = tools.length === 0
|
|
332
|
+
? '<div class="msg err">本机没有可用的压缩工具:请安装 7-Zip / WinRAR / Info-ZIP,或把可执行文件放到 <code>~/.dsh/integrations/dsh-homing/tools/</code></div>'
|
|
333
|
+
: `<p style="margin:0 0 12px;color:#9aa3b2;font-size:13px">可用工具:${tools.map((item) => `${escapeHtml(item.label)}(${escapeHtml(item.strength)})`).join('、')}</p>`;
|
|
334
|
+
const body = `
|
|
335
|
+
<div class="bar">
|
|
336
|
+
<div style="display:flex;align-items:center;gap:8px;flex-wrap:nowrap;min-width:0">
|
|
337
|
+
<h1 style="margin:0;flex:0 0 auto;font-size:18px">加密压缩</h1>
|
|
338
|
+
<div style="flex:1 1 auto;display:flex;align-items:center;justify-content:flex-end;gap:4px;flex-wrap:nowrap;overflow-x:auto">
|
|
339
|
+
<a class="btn ghost" href="/files?path=${encodeURIComponent(dir)}" style="flex:0 0 auto;padding:4px 7px;border-radius:6px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:11px">返回目录</a>
|
|
340
|
+
</div>
|
|
341
|
+
</div>
|
|
342
|
+
</div>
|
|
343
|
+
${messageHtml(message, isError)}
|
|
344
|
+
<div class="card" style="background:#20262f;border:1px solid #3a4351;border-radius:10px;padding:14px">
|
|
345
|
+
<p style="margin:0 0 10px;color:#9aa3b2;font-size:13px;line-height:1.6">
|
|
346
|
+
在<b>这台电脑上</b>把目标压缩成加密归档,产物放在同级目录。<br>
|
|
347
|
+
目标:<code style="color:#dce9f7">${escapeHtml(target)}</code>
|
|
348
|
+
${done ? `<br>产物:<code style="color:#dce9f7">${escapeHtml(archive)}</code>` : ''}
|
|
349
|
+
</p>
|
|
350
|
+
${toolsHtml}
|
|
351
|
+
${done ? `
|
|
352
|
+
<p style="margin:0 0 12px;color:#9aa3b2;font-size:13px">使用工具:${escapeHtml(tool)} · ${escapeHtml(strength)}</p>
|
|
353
|
+
<div style="display:flex;gap:8px;flex-wrap:wrap">
|
|
354
|
+
<a class="btn" href="/files/download?path=${encodeURIComponent(archive)}" style="padding:8px 14px;border-radius:8px;background:#2f4a68;color:#dce9f7;text-decoration:none;font-size:13px">下载压缩包</a>
|
|
355
|
+
<a class="btn ghost" href="/files?path=${encodeURIComponent(dir)}" style="padding:8px 14px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:13px">返回目录</a>
|
|
356
|
+
</div>
|
|
357
|
+
` : `
|
|
358
|
+
<form method="post" action="/files/compress" style="display:flex;flex-direction:column;gap:10px;max-width:420px">
|
|
359
|
+
<input type="hidden" name="path" value="${escapeHtml(target)}">
|
|
360
|
+
<label style="font-size:13px;color:#9aa3b2">密码(至少 6 位,不保存、忘记无法恢复)</label>
|
|
361
|
+
<input type="password" name="password" required minlength="6" maxlength="128" autocomplete="new-password"
|
|
362
|
+
style="padding:10px 12px;border-radius:8px;border:1px solid #3a4351;background:#161a20;color:#e6e8ee;font-size:15px">
|
|
363
|
+
<label style="font-size:13px;color:#9aa3b2">再输一次</label>
|
|
364
|
+
<input type="password" name="confirm" required minlength="6" maxlength="128" autocomplete="new-password"
|
|
365
|
+
style="padding:10px 12px;border-radius:8px;border:1px solid #3a4351;background:#161a20;color:#e6e8ee;font-size:15px">
|
|
366
|
+
<button type="submit" style="margin-top:4px;padding:10px 14px;border-radius:8px;border:1px solid #3f5f84;background:#2f4a68;color:#dce9f7;font-size:14px">开始压缩</button>
|
|
367
|
+
</form>
|
|
368
|
+
<p style="margin:14px 0 0;color:#6b7280;font-size:12px;line-height:1.6">
|
|
369
|
+
文件:${escapeHtml(name)}<br>
|
|
370
|
+
7-Zip / WinRAR 为 AES-256(强);Info-ZIP 为 ZipCrypto(弱,仅兼容用途)。<br>
|
|
371
|
+
Windows 自带解压不支持密码,需用 7-Zip / WinRAR / Bandizip。
|
|
372
|
+
</p>
|
|
373
|
+
`}
|
|
374
|
+
</div>`;
|
|
375
|
+
|
|
376
|
+
return layout({ title: '加密压缩 · ' + name, body })
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** 文件内容页 *//** 文件内容页 */
|
|
318
380
|
export function renderFile({ info, message, isError }) {
|
|
319
381
|
const body = `
|
|
320
382
|
<div class="bar">
|