feat(api): getFileBlob

This commit is contained in:
frostime 2024-08-01 13:34:25 +08:00
parent 4c004d73b5
commit 1ac9cf8ff5

View file

@ -335,6 +335,28 @@ export async function getFile(path: string): Promise<any> {
});
}
/**
* fetchPost will secretly convert data into json, this func merely return Blob
* @param endpoint
* @returns
*/
export const getFileBlob = async (path: string): Promise<Blob | null> => {
const endpoint = '/api/file/getFile'
let response = await fetch(endpoint, {
method: 'POST',
body: JSON.stringify({
path: path
})
});
if (!response.ok) {
return null;
}
let data = await response.blob();
return data;
}
export async function putFile(path: string, isDir: boolean, file: any) {
let form = new FormData();
form.append('path', path);