fix(frontend): 跨服务器传输默认使用各机目标路径

选源机浏览 A.target_path;选目标机填入 B.target_path。
This commit is contained in:
Nexus Agent
2026-06-21 13:09:48 +08:00
parent da26d648a9
commit 113718b553
2 changed files with 63 additions and 18 deletions
@@ -0,0 +1,28 @@
# 跨服务器传输:默认进入各机目标路径
**日期**2026-06-21
## 摘要
选源服务器 A 后浏览目录默认进入 A 的 `target_path`;选目标服务器 B 后「目标目录/归档路径」默认填入 B 的 `target_path`(切换 B 时不用旧 localStorage 覆盖)。
## 动机
与文件管理页一致:运维以各机业务根目录为起点,减少每次手动改路径。
## 涉及文件
- `frontend/src/composables/useServerFileTransfer.ts``serverTargetPath``applyDestPathForServer`
## 行为
| 操作 | 默认路径 |
|------|----------|
| 选 A | 左侧浏览 `A.target_path`(无则 `/www/wwwroot` |
| 从文件页带 `?path=` | 仍用 query 路径 |
| 选 B | 直传 → `B.target_path`;打包 → `B.target_path/xxx.tar.gz` |
| 仅切换直传/打包 | 仍可读该 B 机上次保存的路径 |
## 验证
`cd frontend && npx vite build`;页内选 A/B 观察路径字段。
@@ -126,9 +126,15 @@ export function useServerFileTransfer() {
}
}
function serverTargetPath(serverId: number | null): string {
if (!serverId) return DEFAULT_FILES_ROOT
const srv = serverList.value.find((s) => s.id === serverId)
const tp = srv?.target_path?.trim()
return tp ? normalizeRemotePath(tp) : DEFAULT_FILES_ROOT
}
function defaultDestPath(mode: ServerTransferMode, destId: number | null): string {
const destSrv = destId ? serverList.value.find((s) => s.id === destId) : undefined
const base = destSrv?.target_path?.trim() || '/tmp'
const base = serverTargetPath(destId)
const normalizedBase = base.endsWith('/') ? base.slice(0, -1) : base
if (mode === 'relay') return normalizedBase
const first = effectivePaths.value[0]
@@ -137,6 +143,21 @@ export function useServerFileTransfer() {
return `${normalizedBase}/${safe}.tar.gz`
}
function applyDestPathForServer(destId: number | null, preferStored = false) {
if (!destId) {
destPath.value = ''
return
}
if (preferStored) {
const stored = loadStoredDest(transferMode.value, destId)
if (stored) {
destPath.value = stored
return
}
}
destPath.value = defaultDestPath(transferMode.value, destId)
}
function recommendMode(paths: string[]): ServerTransferMode {
for (const p of paths) {
const item = files.value.find(
@@ -155,40 +176,32 @@ export function useServerFileTransfer() {
return 'relay'
}
function syncDestPathDefaults() {
if (!destServerId.value) return
const stored = loadStoredDest(transferMode.value, destServerId.value)
destPath.value = stored || defaultDestPath(transferMode.value, destServerId.value)
}
function onSourceServerChange(id: number | null) {
sourceServerId.value = id
sourceServerSearchQuery.value = ''
selectedPaths.value = []
currentPath.value = DEFAULT_FILES_ROOT
if (id) {
const srv = serverList.value.find((s) => s.id === id)
if (srv?.target_path?.trim()) {
currentPath.value = normalizeRemotePath(srv.target_path)
}
currentPath.value = serverTargetPath(id)
} else {
currentPath.value = DEFAULT_FILES_ROOT
}
const candidates = destServers.value
if (!destServerId.value || destServerId.value === id) {
destServerId.value = candidates[0]?.id ?? null
}
syncDestPathDefaults()
applyDestPathForServer(destServerId.value, false)
void browse()
}
function onDestServerChange(id: number | null) {
destServerId.value = id
destServerSearchQuery.value = ''
syncDestPathDefaults()
applyDestPathForServer(id, false)
}
function onModeChange(mode: ServerTransferMode) {
transferMode.value = mode
syncDestPathDefaults()
applyDestPathForServer(destServerId.value, true)
}
async function browse(path?: string) {
@@ -254,7 +267,11 @@ export function useServerFileTransfer() {
if (Number.isFinite(src) && src > 0) {
sourceServerId.value = src
const pathQ = typeof q.path === 'string' ? q.path : ''
if (pathQ) currentPath.value = normalizeRemotePath(pathQ)
if (pathQ) {
currentPath.value = normalizeRemotePath(pathQ)
} else {
currentPath.value = serverTargetPath(src)
}
const pathsQ = typeof q.paths === 'string' ? q.paths : ''
if (pathsQ) {
selectedPaths.value = pathsQ.split('|').map((p) => normalizeRemotePath(p))
@@ -265,7 +282,7 @@ export function useServerFileTransfer() {
const candidates = serverList.value.filter((s) => s.id !== sourceServerId.value)
destServerId.value = candidates[0]?.id ?? null
transferMode.value = recommendMode(selectedPaths.value)
syncDestPathDefaults()
applyDestPathForServer(destServerId.value, false)
void browse()
}
}