This commit is contained in:
Timothy Jaeryang Baek
2026-02-25 16:13:18 -06:00
parent bee13f72ad
commit 8b2160f2f7
4 changed files with 160 additions and 27 deletions
+1 -9
View File
@@ -68,22 +68,14 @@ export const downloadFileBlob = async (
apiKey: string,
path: string
): Promise<{ blob: Blob; filename: string } | null> => {
const url = `${baseUrl.replace(/\/$/, '')}/files/read?path=${encodeURIComponent(path)}`;
const url = `${baseUrl.replace(/\/$/, '')}/files/view?path=${encodeURIComponent(path)}`;
const res = await fetch(url, {
headers: { Authorization: `Bearer ${apiKey}` }
}).catch(() => null);
if (!res || !res.ok) return null;
const contentType = res.headers.get('content-type') ?? '';
const filename = path.split('/').pop() ?? 'file';
if (contentType.includes('application/json')) {
const json = await res.json().catch(() => null);
const blob = new Blob([json?.content ?? ''], { type: 'text/plain' });
return { blob, filename };
}
const blob = await res.blob();
return { blob, filename };
};