update download function

This commit is contained in:
smanylov
2026-03-09 13:04:28 +07:00
parent c739f2e7b1
commit 060b684e57
3 changed files with 42 additions and 59 deletions
+23
View File
@@ -117,4 +117,27 @@ export async function viewFileInfo(fileId: string) {
} catch (error) {
return error
}
}
export async function downloadFile(fileId: string, fileName: string) {
const token = await getSessionData('token')
const response = await fetch(`${API_BASE_URL}/api/v1/files/download/${fileId}`, {
headers: {
'Authorization': `Bearer ${token}`,
},
})
if (!response.ok) {
throw 'failed-to-download-file';
}
const arrayBuffer = await response.arrayBuffer()
const base64 = Buffer.from(arrayBuffer).toString('base64')
return {
data: base64,
contentType: response.headers.get('content-type') || 'application/octet-stream',
fileName: fileName
}
}