|
|
@@ -1,11 +1,9 @@
|
|
|
import axios from 'axios';
|
|
|
import type { MinioUploadPolicy, OSSUploadPolicy } from '@d8d-appcontainer/types';
|
|
|
-import type {
|
|
|
+import type {
|
|
|
FileLibrary, FileCategory
|
|
|
} from '../../share/types.ts';
|
|
|
|
|
|
-const API_BASE_URL = '/api';
|
|
|
-
|
|
|
interface FileUploadPolicyResponse {
|
|
|
message: string;
|
|
|
data: MinioUploadPolicy | OSSUploadPolicy;
|
|
|
@@ -64,7 +62,7 @@ export const FileAPI = {
|
|
|
// 获取文件上传策略
|
|
|
getUploadPolicy: async (filename: string, prefix: string = 'uploads/', maxSize: number = 10 * 1024 * 1024): Promise<FileUploadPolicyResponse> => {
|
|
|
try {
|
|
|
- const response = await axios.get(`${API_BASE_URL}/upload/policy`, {
|
|
|
+ const response = await axios.get('/upload/policy', {
|
|
|
params: { filename, prefix, maxSize }
|
|
|
});
|
|
|
return response.data;
|
|
|
@@ -76,7 +74,7 @@ export const FileAPI = {
|
|
|
// 保存文件信息
|
|
|
saveFileInfo: async (fileData: Partial<FileLibrary>): Promise<FileSaveResponse> => {
|
|
|
try {
|
|
|
- const response = await axios.post(`${API_BASE_URL}/upload/save`, fileData);
|
|
|
+ const response = await axios.post('/upload/save', fileData);
|
|
|
return response.data;
|
|
|
} catch (error) {
|
|
|
throw error;
|
|
|
@@ -92,7 +90,7 @@ export const FileAPI = {
|
|
|
keyword?: string
|
|
|
}): Promise<FileListResponse> => {
|
|
|
try {
|
|
|
- const response = await axios.get(`${API_BASE_URL}/upload/list`, { params });
|
|
|
+ const response = await axios.get('/upload/list', { params });
|
|
|
return response.data;
|
|
|
} catch (error) {
|
|
|
throw error;
|
|
|
@@ -102,7 +100,7 @@ export const FileAPI = {
|
|
|
// 获取单个文件信息
|
|
|
getFileInfo: async (id: number): Promise<FileInfoResponse> => {
|
|
|
try {
|
|
|
- const response = await axios.get(`${API_BASE_URL}/upload/${id}`);
|
|
|
+ const response = await axios.get(`/upload/${id}`);
|
|
|
return response.data;
|
|
|
} catch (error) {
|
|
|
throw error;
|
|
|
@@ -112,7 +110,7 @@ export const FileAPI = {
|
|
|
// 更新文件下载计数
|
|
|
updateDownloadCount: async (id: number): Promise<FileDeleteResponse> => {
|
|
|
try {
|
|
|
- const response = await axios.post(`${API_BASE_URL}/upload/${id}/download`);
|
|
|
+ const response = await axios.post(`/upload/${id}/download`);
|
|
|
return response.data;
|
|
|
} catch (error) {
|
|
|
throw error;
|
|
|
@@ -122,7 +120,7 @@ export const FileAPI = {
|
|
|
// 删除文件
|
|
|
deleteFile: async (id: number): Promise<FileDeleteResponse> => {
|
|
|
try {
|
|
|
- const response = await axios.delete(`${API_BASE_URL}/upload/${id}`);
|
|
|
+ const response = await axios.delete(`/upload/${id}`);
|
|
|
return response.data;
|
|
|
} catch (error) {
|
|
|
throw error;
|
|
|
@@ -136,7 +134,7 @@ export const FileAPI = {
|
|
|
search?: string
|
|
|
}): Promise<FileCategoryListResponse> => {
|
|
|
try {
|
|
|
- const response = await axios.get(`${API_BASE_URL}/file-categories`, { params });
|
|
|
+ const response = await axios.get('/file-categories', { params });
|
|
|
return response.data;
|
|
|
} catch (error) {
|
|
|
throw error;
|
|
|
@@ -146,7 +144,7 @@ export const FileAPI = {
|
|
|
// 创建文件分类
|
|
|
createCategory: async (data: Partial<FileCategory>): Promise<FileCategoryCreateResponse> => {
|
|
|
try {
|
|
|
- const response = await axios.post(`${API_BASE_URL}/file-categories`, data);
|
|
|
+ const response = await axios.post('/file-categories', data);
|
|
|
return response.data;
|
|
|
} catch (error) {
|
|
|
throw error;
|
|
|
@@ -156,7 +154,7 @@ export const FileAPI = {
|
|
|
// 更新文件分类
|
|
|
updateCategory: async (id: number, data: Partial<FileCategory>): Promise<FileCategoryUpdateResponse> => {
|
|
|
try {
|
|
|
- const response = await axios.put(`${API_BASE_URL}/file-categories/${id}`, data);
|
|
|
+ const response = await axios.put(`/file-categories/${id}`, data);
|
|
|
return response.data;
|
|
|
} catch (error) {
|
|
|
throw error;
|
|
|
@@ -166,7 +164,7 @@ export const FileAPI = {
|
|
|
// 删除文件分类
|
|
|
deleteCategory: async (id: number): Promise<FileCategoryDeleteResponse> => {
|
|
|
try {
|
|
|
- const response = await axios.delete(`${API_BASE_URL}/file-categories/${id}`);
|
|
|
+ const response = await axios.delete(`/file-categories/${id}`);
|
|
|
return response.data;
|
|
|
} catch (error) {
|
|
|
throw error;
|