diff --git a/reading-platform-frontend/src/api/file.ts b/reading-platform-frontend/src/api/file.ts index 2b45a99..b6a0f13 100644 --- a/reading-platform-frontend/src/api/file.ts +++ b/reading-platform-frontend/src/api/file.ts @@ -1,4 +1,5 @@ import { http } from "./index"; +import axios from "axios"; import { buildOssDirPath } from "@/utils/env"; /** 上传请求 AbortController 映射,用于取消上传 */ @@ -80,13 +81,11 @@ export const fileApi = { // 自动添加环境前缀 const fullDir = buildOssDirPath(dir); - const response = await http.get<{ data: OssToken }>( - `/v1/files/oss/token`, - { - params: { fileName, dir: fullDir }, - }, - ); - return response.data; + const response = await http.get(`/v1/files/oss/token`, { + params: { fileName, dir: fullDir }, + }); + console.log("getOssToken", response); + return response; }, /** @@ -109,9 +108,7 @@ export const fileApi = { }, ): Promise<{ url: string }> => { const opts = - typeof options === "function" - ? { onProgress: options } - : options ?? {}; + typeof options === "function" ? { onProgress: options } : (options ?? {}); const formData = new FormData(); // 按照阿里云 OSS PostObject 要求构造表单 @@ -125,7 +122,7 @@ export const fileApi = { const controller = getUploadController(file); const signal = opts.signal ?? controller.signal; - + console.log(token.host, formData, signal); try { await axios.post(token.host, formData, { headers: { @@ -145,10 +142,12 @@ export const fileApi = { } }, }); - return { url: `${token.host}/${token.key}`, }; + } catch (error) { + console.error(error); + throw error; } finally { abortUpload(file); } @@ -204,12 +203,9 @@ export const fileApi = { * 删除文件 */ deleteFile: async (filePath: string): Promise => { - const response = await http.post( - `/v1/files/delete`, - { - filePath, - }, - ); + const response = await http.post(`/v1/files/delete`, { + filePath, + }); return response; },