新增: SFTP直连+网站预览+OSS区域嗅探+热键+BGM播放

This commit is contained in:
lxy
2026-05-12 11:06:28 +08:00
parent 545d7a864d
commit 2a363fd729
62 changed files with 6685 additions and 658 deletions
+8 -25
View File
@@ -9,8 +9,8 @@ import type { ConnectionProfile } from './connection-manager'
import {
SftpConnect, SftpDisconnect, SftpListDir, SftpReadFile,
SftpWriteFile, SftpGetFileInfo, SftpCreateDir, SftpCreateFile,
SftpDeletePath, SftpRenamePath, SftpDownloadToTemp, SftpGetCommonPaths,
SftpWriteBase64File,
SftpDeletePath, SftpRenamePath, SftpDownloadToTemp, SftpDownloadSiteForPreview,
SftpGetCommonPaths, SftpWriteBase64File,
} from '@bindings/u-desk/app'
function transformFile(file: any): FileItem {
@@ -21,13 +21,9 @@ function transformFileList(files: any[]): FileItem[] {
return files.map(transformFile)
}
const PREVIEW_CACHE_MAX = 50
export class SftpTransport implements FsTransport {
private profile: ConnectionProfile
private connID: string | null = null
private previewCache = new Map<string, string>() // remotePath -> localTempPath (LRU)
private previewOrder: string[] = [] // LRU 排序键列表
constructor(profile: ConnectionProfile) {
this.profile = profile
@@ -55,8 +51,6 @@ export class SftpTransport implements FsTransport {
}
this.connID = null
}
this.previewCache.clear()
this.previewOrder = []
}
private requireConn(): string {
@@ -176,24 +170,13 @@ export class SftpTransport implements FsTransport {
// ====== 预览辅助 ======
/** 下载远程文件到本地临时目录用于预览(带 LRU 缓存,上限 50) */
/** 下载远程文件到本地临时目录用于预览(缓存由 Go 后端管理) */
async downloadForPreview(remotePath: string): Promise<string> {
// 命中:移到队尾(最近使用)
if (this.previewCache.has(remotePath)) {
this.previewOrder = this.previewOrder.filter(p => p !== remotePath)
this.previewOrder.push(remotePath)
return this.previewCache.get(remotePath)!
}
const localPath = await SftpDownloadToTemp(this.requireConn(), remotePath)
return SftpDownloadToTemp(this.requireConn(), remotePath)
}
// 淘汰最旧条目
if (this.previewOrder.length >= PREVIEW_CACHE_MAX) {
const oldest = this.previewOrder.shift()!
this.previewCache.delete(oldest)
}
this.previewCache.set(remotePath, localPath)
this.previewOrder.push(remotePath)
return localPath
/** 下载 HTML 及其网站资源到临时目录用于预览 */
async downloadSiteForPreview(remotePath: string): Promise<string> {
return SftpDownloadSiteForPreview(this.requireConn(), remotePath)
}
}