(filePath: string)
| 100 | |
| 101 | // --- Tauri file loading --- |
| 102 | async function loadFileAsBlob(filePath: string): Promise<Blob> { |
| 103 | // Resolve managed relative paths (e.g., "books/{id}.epub") to the active desktop library root. |
| 104 | const resolvedPath = await resolveDesktopDataPath(filePath); |
| 105 | |
| 106 | try { |
| 107 | const { convertFileSrc } = await import("@tauri-apps/api/core"); |
| 108 | const assetUrl = |
| 109 | resolvedPath.startsWith("asset://") || resolvedPath.startsWith("http") |
| 110 | ? resolvedPath |
| 111 | : convertFileSrc(resolvedPath); |
| 112 | const response = await fetch(assetUrl); |
| 113 | if (!response.ok) throw new Error(`fetch failed: ${response.status}`); |
| 114 | return await response.blob(); |
| 115 | } catch { |
| 116 | const { readFile } = await import("@tauri-apps/plugin-fs"); |
| 117 | const fileBytes = await readFile(resolvedPath); |
| 118 | return new Blob([fileBytes]); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // --- Blob cache --- |
| 123 | const fileBlobCache = new Map<string, Blob>(); |
no test coverage detected