| 52 | * Read a file. Returns parsed JSON (if JSON file) or string content, or null if not found. |
| 53 | */ |
| 54 | export async function getFile(filePath: string): Promise<unknown> { |
| 55 | try { |
| 56 | const res = await fetch(apiUrl(filePath)); |
| 57 | if (!res.ok) return null; |
| 58 | const text = await res.text(); |
| 59 | try { |
| 60 | return JSON.parse(text); |
| 61 | } catch { |
| 62 | return text; |
| 63 | } |
| 64 | } catch (e) { |
| 65 | console.warn('[diskStorage] getFile failed:', e); |
| 66 | return null; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Write files. Compatible with the old putTextFilesByJSON signature. |