From 1ac9cf8ff550a95cc14bb20c4c4c91fdc77c54c4 Mon Sep 17 00:00:00 2001 From: frostime Date: Thu, 1 Aug 2024 13:34:25 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(api):=20getFileBlob?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/api.ts b/src/api.ts index 0a421ce..0595371 100644 --- a/src/api.ts +++ b/src/api.ts @@ -335,6 +335,28 @@ export async function getFile(path: string): Promise { }); } + +/** + * fetchPost will secretly convert data into json, this func merely return Blob + * @param endpoint + * @returns + */ +export const getFileBlob = async (path: string): Promise => { + 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);