-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add method to download files from Moodle as blobs
- Loading branch information
1 parent
d8c2e61
commit 171af6e
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |