LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。
TypeScript
feat: add multi-format file preview support
nash_su2483037fcad1
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lockindex d73608cf..70d5a7f0 100644--- a/src-tauri/Cargo.lock+++ b/src-tauri/Cargo.lock@@ -1616,6 +1616,12 @@ dependencies = ["pin-project-lite",]+[[package]]+name = "http-range"+version = "0.1.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"+[[package]]name = "httparse"version = "1.10.1"@@ -3895,6 +3901,7 @@ dependencies = ["gtk","heck 0.5.0","http",+ "http-range","jni","libc","log",diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.tomlindex 044f1532..2be6cb23 100644--- a/src-tauri/Cargo.toml+++ b/src-tauri/Cargo.toml@@ -19,7 +19,7 @@ path = "src/main.rs"tauri-build = { version = "2", features = [] }[dependencies]-tauri = { version = "2", features = [] }+tauri = { version = "2", features = ["protocol-asset"] }tauri-plugin-opener = "2"serde = { version = "1", features = ["derive"] }serde_json = "1"diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.jsonindex 04536ff4..6fd35a11 100644--- a/src-tauri/tauri.conf.json+++ b/src-tauri/tauri.conf.json@@ -20,7 +20,11 @@}],"security": {- "csp": null+ "csp": "default-src 'self'; img-src 'self' asset: https://asset.localhost; media-src 'self' asset: https://asset.localhost; style-src 'self' 'unsafe-inline'",+ "assetProtocol": {+ "enable": true,+ "scope": ["**"]+ }}},"bundle": {diff --git a/src/components/editor/file-preview.tsx b/src/components/editor/file-preview.tsxnew file mode 100644index 00000000..10493d52--- /dev/null+++ b/src/components/editor/file-preview.tsx@@ -0,0 +1,148 @@+import { convertFileSrc } from "@tauri-apps/api/core"+import {+ FileText,+ Image as ImageIcon,+ Film,+ Music,+ FileSpreadsheet,+ FileQuestion,+} from "lucide-react"+import { getFileCategory, getCodeLanguage } from "@/lib/file-types"+import type { FileCategory } from "@/lib/file-types"++interface FilePreviewProps {+ filePath: string+ textContent: string+}++export function FilePreview({ filePath, textContent }: FilePreviewProps) {+ const category = getFileCategory(filePath)+ const fileName = filePath.split("/").pop() ?? filePath++ switch (category) {+ case "image":+ return <ImagePreview filePath={filePath} fileName={fileName} />+ case "video":+ return <VideoPreview filePath={filePath} fileName={fileName} />+ case "audio":+ return <AudioPreview filePath={filePath} fileName={fileName} />+ case "pdf":+ return <TextPreview filePath={filePath} content={textContent} label="PDF (extracted text)" />+ case "code":+ return <CodePreview filePath={filePath} content={textContent} />+ case "data":+ return <CodePreview filePath={filePath} content={textContent} />+ case "text":+ return <TextPreview filePath={filePath} content={textContent} label="Text" />+ case "document":+ return <BinaryPlaceholder filePath={filePath} fileName={fileName} category={category} />+ default:+ return <BinaryPlaceholder filePath={filePath} fileName={fileName} category={category} />+ }+}++function ImagePreview({ filePath, fileName }: { filePath: string; fileName: string }) {+ const src = convertFileSrc(filePath)+ return (+ <div className="flex h-full flex-col p-6">+ <div className="mb-4 text-xs text-muted-foreground">{filePath}</div>+ <div className="flex flex-1 items-center justify-center overflow-auto rounded-lg bg-muted/30">+ <img+ src={src}+ alt={fileName}+ className="max-h-full max-w-full object-contain"+ />+ </div>+ </div>+ )+}++function VideoPreview({ filePath, fileName }: { filePath: string; fileName: string }) {+ const src = convertFileSrc(filePath)+ return (+ <div className="flex h-full flex-col p-6">+ <div className="mb-4 text-xs text-muted-foreground">{filePath}</div>+ <div className="flex flex-1 items-center justify-center overflow-auto rounded-lg bg-black">+ <video+ src={src}+ controls+ className="max-h-full max-w-full"+ >+ <track kind="captions" label={fileName} />+ </video>+ </div>+ </div>+ )+}++function AudioPreview({ filePath, fileName }: { filePath: string; fileName: string }) {+ const src = convertFileSrc(filePath)+ return (+ <div className="flex h-full flex-col items-center justify-center gap-4 p-6">+ <div className="text-xs text-muted-foreground">{filePath}</div>+ <Music className="h-16 w-16 text-muted-foreground/50" />+ <p className="text-sm font-medium">{fileName}</p>+ <audio src={src} controls className="w-full max-w-md">+ <track kind="captions" label={fileName} />+ </audio>+ </div>+ )+}++function CodePreview({ filePath, content }: { filePath: string; content: string }) {+ const lang = getCodeLanguage(filePath)+ return (+ <div className="h-full overflow-auto p-6">+ <div className="mb-2 flex items-center gap-2 text-xs text-muted-foreground">+ <span>{filePath}</span>+ <span className="rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase">{lang}</span>+ </div>+ <pre className="whitespace-pre-wrap rounded-lg bg-muted/30 p-4 font-mono text-sm">+ {content}+ </pre>+ </div>+ )+}++function TextPreview({ filePath, content, label }: { filePath: string; content: string; label: string }) {+ return (+ <div className="h-full overflow-auto p-6">+ <div className="mb-2 flex items-center gap-2 text-xs text-muted-foreground">+ <span>{filePath}</span>+ <span className="rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase">{label}</span>+ </div>+ <pre className="whitespace-pre-wrap font-mono text-sm">{content}</pre>+ </div>+ )+}++function BinaryPlaceholder({+ filePath,+ fileName,+ category,+}: {+ filePath: string+ fileName: string+ category: FileCategory+}) {+ const iconMap: Record<string, typeof FileText> = {+ document: FileSpreadsheet,+ unknown: FileQuestion,+ image: ImageIcon,+ video: Film,+ }+ const Icon = iconMap[category] ?? FileQuestion++ return (+ <div className="flex h-full flex-col items-center justify-center gap-4 p-6 text-center">+ <Icon className="h-16 w-16 text-muted-foreground/30" />+ <div>+ <p className="text-sm font-medium">{fileName}</p>+ <p className="mt-1 text-xs text-muted-foreground">{filePath}</p>+ </div>+ <p className="text-sm text-muted-foreground">+ Preview not available for this file type+ </p>+ </div>+ )+}diff --git a/src/components/layout/content-area.tsx b/src/components/layout/content-area.tsxindex 7de9eab6..74ff67a7 100644--- a/src/components/layout/content-area.tsx+++ b/src/components/layout/content-area.tsx@@ -1,7 +1,9 @@import { useEffect, useCallback, useRef } from "react"import { useWikiStore } from "@/stores/wiki-store"import { readFile, writeFile } from "@/commands/fs"+import { getFileCategory, isBinary } from "@/lib/file-types"import { WikiEditor } from "@/components/editor/wiki-editor"+import { FilePreview } from "@/components/editor/file-preview"import { ChatBar } from "./chat-bar"import { SettingsView } from "@/components/settings/settings-view"import { SourcesView } from "@/components/sources/sources-view"@@ -19,6 +21,17 @@ export function ContentArea() {setFileContent("")return}++ const category = getFileCategory(selectedFile)++ // Don't try to read binary files as text+ if (isBinary(category)) {+ setFileContent("")+ return+ }++ // For PDF, read_file extracts text on Rust side+ // For text/code/data/markdown, read as textreadFile(selectedFile).then(setFileContent).catch((err) => setFileContent(`Error loading file: ${err}`))@@ -51,22 +64,23 @@ export function ContentArea() {return <SourcesView />}- const isMarkdown = selectedFile?.endsWith(".md")+ const category = selectedFile ? getFileCategory(selectedFile) : nullconst editorContent = (<div className="h-full min-w-0 overflow-auto">{selectedFile ? (- isMarkdown ? (+ category === "markdown" ? (<WikiEditorkey={selectedFile}content={fileContent}onSave={handleSave}/>) : (- <div className="p-6">- <div className="mb-4 text-xs text-muted-foreground">{selectedFile}</div>- <pre className="whitespace-pre-wrap font-mono text-sm">{fileContent}</pre>- </div>+ <FilePreview+ key={selectedFile}+ filePath={selectedFile}+ textContent={fileContent}+ />)) : (<div className="flex h-full items-center justify-center text-muted-foreground">diff --git a/src/components/sources/sources-view.tsx b/src/components/sources/sources-view.tsxindex 65db3747..0fd94661 100644--- a/src/components/sources/sources-view.tsx+++ b/src/components/sources/sources-view.tsx@@ -39,7 +39,31 @@ export function SourcesView() {filters: [{name: "Documents",- extensions: ["md", "txt", "pdf", "html", "htm", "json", "csv"],+ extensions: [+ "md", "mdx", "txt", "rtf", "pdf",+ "html", "htm", "xml",+ "doc", "docx", "xls", "xlsx", "ppt", "pptx",+ "odt", "ods", "odp", "epub", "pages", "numbers", "key",+ ],+ },+ {+ name: "Data",+ extensions: ["json", "jsonl", "csv", "tsv", "yaml", "yml", "ndjson"],+ },+ {+ name: "Code",+ extensions: [+ "py", "js", "ts", "jsx", "tsx", "rs", "go", "java",+ "c", "cpp", "h", "rb", "php", "swift", "sql", "sh",+ ],+ },+ {+ name: "Images",+ extensions: ["png", "jpg", "jpeg", "gif", "webp", "svg", "bmp", "tiff", "avif", "heic"],+ },+ {+ name: "Media",+ extensions: ["mp4", "webm", "mov", "avi", "mkv", "mp3", "wav", "ogg", "flac", "m4a"],},{ name: "All Files", extensions: ["*"] },],diff --git a/src/lib/file-types.ts b/src/lib/file-types.tsnew file mode 100644index 00000000..f1abf555--- /dev/null+++ b/src/lib/file-types.ts@@ -0,0 +1,164 @@+export type FileCategory =+ | "markdown"+ | "text"+ | "code"+ | "image"+ | "video"+ | "audio"+ | "pdf"+ | "document"+ | "data"+ | "unknown"++const EXT_MAP: Record<string, FileCategory> = {+ // Markdown+ md: "markdown",+ mdx: "markdown",++ // Text+ txt: "text",+ rtf: "text",+ log: "text",++ // Code+ js: "code",+ jsx: "code",+ ts: "code",+ tsx: "code",+ py: "code",+ rs: "code",+ go: "code",+ java: "code",+ c: "code",+ cpp: "code",+ h: "code",+ hpp: "code",+ rb: "code",+ php: "code",+ swift: "code",+ kt: "code",+ scala: "code",+ sh: "code",+ bash: "code",+ zsh: "code",+ sql: "code",+ r: "code",+ lua: "code",+ css: "code",+ scss: "code",+ less: "code",+ html: "code",+ htm: "code",+ xml: "code",+ svg: "code",+ vue: "code",+ svelte: "code",+ toml: "code",+ ini: "code",+ cfg: "code",+ conf: "code",+ dockerfile: "code",+ makefile: "code",++ // Images+ png: "image",+ jpg: "image",+ jpeg: "image",+ gif: "image",+ webp: "image",+ bmp: "image",+ ico: "image",+ tiff: "image",+ tif: "image",+ avif: "image",+ heic: "image",+ heif: "image",++ // Video+ mp4: "video",+ webm: "video",+ mov: "video",+ avi: "video",+ mkv: "video",+ flv: "video",+ wmv: "video",+ m4v: "video",++ // Audio+ mp3: "audio",+ wav: "audio",+ ogg: "audio",+ flac: "audio",+ aac: "audio",+ m4a: "audio",+ wma: "audio",++ pdf: "pdf",++ // Documents (binary, not directly previewable)+ doc: "document",+ docx: "document",+ xls: "document",+ xlsx: "document",+ ppt: "document",+ pptx: "document",+ odt: "document",+ ods: "document",+ odp: "document",+ pages: "document",+ numbers: "document",+ key: "document",+ epub: "document",++ // Data+ json: "data",+ jsonl: "data",+ csv: "data",+ tsv: "data",+ yaml: "data",+ yml: "data",+ ndjson: "data",+}++export function getFileCategory(filePath: string): FileCategory {+ const ext = filePath.split(".").pop()?.toLowerCase() ?? ""+ return EXT_MAP[ext] ?? "unknown"+}++export function isTextReadable(category: FileCategory): boolean {+ return ["markdown", "text", "code", "data"].includes(category)+}++export function isBinary(category: FileCategory): boolean {+ return ["image", "video", "audio", "document", "unknown"].includes(category)+}++export function getCodeLanguage(filePath: string): string {+ const ext = filePath.split(".").pop()?.toLowerCase() ?? ""+ const langMap: Record<string, string> = {+ js: "javascript",+ jsx: "javascript",+ ts: "typescript",+ tsx: "typescript",+ py: "python",+ rs: "rust",+ go: "go",+ java: "java",+ rb: "ruby",+ php: "php",+ swift: "swift",+ sql: "sql",+ html: "html",+ htm: "html",+ css: "css",+ json: "json",+ yaml: "yaml",+ yml: "yaml",+ xml: "xml",+ sh: "bash",+ bash: "bash",+ toml: "toml",+ }+ return langMap[ext] ?? ext+}