| 72 | * files: [{ path: "directory", name: "filename", content: "..." }] |
| 73 | */ |
| 74 | export async function putTextFilesByJSON(data: { |
| 75 | files: Array<{ path?: string; name?: string; content?: string }>; |
| 76 | }): Promise<void> { |
| 77 | const promises = data.files.map(async (file) => { |
| 78 | const fullPath = file.path ? `${file.path}/${file.name}` : file.name || ''; |
| 79 | if (!fullPath) return; |
| 80 | try { |
| 81 | await fetch(apiUrl(fullPath), { |
| 82 | method: 'POST', |
| 83 | headers: { 'Content-Type': 'text/plain' }, |
| 84 | body: file.content || '', |
| 85 | }); |
| 86 | } catch (e) { |
| 87 | console.warn('[diskStorage] putTextFilesByJSON write failed:', e); |
| 88 | } |
| 89 | }); |
| 90 | await Promise.all(promises); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Delete files by paths. |