feat: add inline file preview for text-based files

- Add fetchFileText() to download API
- Add preview modal to MarkdownRenderer for .txt/.md/.json/.csv etc.
- File card: click card body → preview, click download button → download
This commit is contained in:
w770583069
2026-05-22 16:53:25 +08:00
committed by ekko
parent 3f16c4a20e
commit bf74745b83
3 changed files with 85 additions and 4 deletions
@@ -53,3 +53,17 @@ export async function downloadFile(filePath: string, fileName?: string): Promise
document.body.removeChild(a)
URL.revokeObjectURL(blobUrl)
}
/**
* Get preview file content.
* Throws with error message on failure.
*/
export async function fetchFileText(filePath: string, fileName?: string): Promise<string> {
const url = getDownloadUrl(filePath, fileName)
const res = await fetch(url)
if (!res.ok) {
const body = await res.json().catch(() => ({ error: `HTTP ${res.status}` }))
throw new Error(body.error || `Preview failed: ${res.status}`)
}
return res.text()
}