Skip to content

Commit

Permalink
feat: add method to download files from Moodle as blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemSBulgakov committed Jul 7, 2024
1 parent d8c2e61 commit 171af6e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/shared/moodle-ws-api/download-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import axios from 'axios'
import { getToken } from '@/shared/moodle-ws-api/token-store'

export async function downloadFileByUrl(fileUrl: string) {
const token = await getToken()
if (!token) {
throw new Error('Token is not present')
}

const resp = await axios({
url: fileUrl,
params: {
token: await getToken(),
},
responseType: 'blob',
})
if (resp.status !== 200) {
throw new Error('Failed to download file')
}

return resp.data as Blob
}

0 comments on commit 171af6e

Please # to comment.