修复: PDF导出浏览器探测补全与链路加固

- 浏览器探测补按用户安装路径LOCALAPPDATA
- fs-agent远程HTML导出先拉取到本地临时目录
- Markdown通道空结果守卫,杜绝0字节PDF误报成功
- 清理死参数与无调用死代码
This commit is contained in:
lxy
2026-09-27 11:13:50 +08:00
parent e87ffe1d0c
commit 2002bb8cca
4 changed files with 23 additions and 24 deletions
+14 -1
View File
@@ -3,6 +3,7 @@
*/
import type { FsTransport, FileItem, FileOperationResult, DetectTypeResult } from './transport'
import { GetEnvVars, WriteFile } from '@bindings/u-desk/app'
const CONTENT_TYPE = 'application/json'
@@ -156,7 +157,19 @@ export class HttpTransport implements FsTransport {
async emptyRecycleBin(): Promise<void> {}
// HTML 的 PDF 导出与本地预览都依赖本地真实文件(导出在后端 os.Stat,预览走本地文件服务器),
// 因此把远端 HTML 文本拉到本机临时目录;其余类型保持返回原路径走 fs-agent 代理流式预览,
// 二进制内容若也走 read 接口会被当文本损坏
async downloadForPreview(path: string): Promise<string> {
return path
if (!/\.html?$/i.test(path)) return path
const content = await this.readFile(path)
const env = await GetEnvVars()
const tempDir = env['TEMP'] || env['TMP'] || env['TMPDIR'] || ''
if (!tempDir) return path
const sep = tempDir.includes('\\') ? '\\' : '/'
const base = path.split(/[\\/]/).pop() || 'preview.html'
const localPath = `${tempDir.replace(/[\\/]+$/, '')}${sep}udesk-http-${Date.now()}-${base}`
await WriteFile({ path: localPath, content })
return localPath
}
}
+1 -1
View File
@@ -81,7 +81,7 @@ export interface FsTransport {
emptyRecycleBin(): Promise<void>
// 预览辅助
/** 下载远程文件到本地临时目录,本地/HTTP 直接返回原路径 */
/** 下载远程文件到本地临时目录,本地直接返回原路径;HTTP 仅对 HTML 落本地副本,其余类型返回原路径 */
downloadForPreview(path: string): Promise<string>
/** 下载 HTML 及其引用的资源到临时目录(OSS 实现) */
downloadSiteForPreview?(path: string): Promise<string>