✨ feat(api): getFileBlob
This commit is contained in:
parent
4c004d73b5
commit
1ac9cf8ff5
1 changed files with 22 additions and 0 deletions
22
src/api.ts
22
src/api.ts
|
@ -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) {
|
export async function putFile(path: string, isDir: boolean, file: any) {
|
||||||
let form = new FormData();
|
let form = new FormData();
|
||||||
form.append('path', path);
|
form.append('path', path);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue