完整API模块结构:
client/admin/api/ ├── auth.ts (认证API) ├── users.ts (用户API) ├── files.ts (文件API) ├── theme.ts (主题API) ├── charts.ts (图表API) ├── messages.ts (消息API) ├── sys.ts (系统API) ├── know_info.ts (知识库API) ├── maps.ts (地图API) └── index.ts (统一入口)
This commit is contained in:
161
client/admin/api/files.ts
Normal file
161
client/admin/api/files.ts
Normal file
@@ -0,0 +1,161 @@
|
||||
import axios from 'axios';
|
||||
import type { FileLibrary, FileCategory } from '../../share/types.ts';
|
||||
import type { MinioUploadPolicy, OSSUploadPolicy } from '@d8d-appcontainer/types';
|
||||
|
||||
const API_BASE_URL = '/api';
|
||||
|
||||
interface FileUploadPolicyResponse {
|
||||
message: string;
|
||||
data: MinioUploadPolicy | OSSUploadPolicy;
|
||||
}
|
||||
|
||||
interface FileListResponse {
|
||||
message: string;
|
||||
data: {
|
||||
list: FileLibrary[];
|
||||
pagination: {
|
||||
current: number;
|
||||
pageSize: number;
|
||||
total: number;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
interface FileSaveResponse {
|
||||
message: string;
|
||||
data: FileLibrary;
|
||||
}
|
||||
|
||||
interface FileInfoResponse {
|
||||
message: string;
|
||||
data: FileLibrary;
|
||||
}
|
||||
|
||||
interface FileDeleteResponse {
|
||||
message: string;
|
||||
}
|
||||
|
||||
interface FileCategoryListResponse {
|
||||
data: FileCategory[];
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
}
|
||||
|
||||
interface FileCategoryCreateResponse {
|
||||
message: string;
|
||||
data: FileCategory;
|
||||
}
|
||||
|
||||
interface FileCategoryUpdateResponse {
|
||||
message: string;
|
||||
data: FileCategory;
|
||||
}
|
||||
|
||||
interface FileCategoryDeleteResponse {
|
||||
message: string;
|
||||
}
|
||||
|
||||
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`, {
|
||||
params: { filename, prefix, maxSize }
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
saveFileInfo: async (fileData: Partial<FileLibrary>): Promise<FileSaveResponse> => {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/upload/save`, fileData);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
getFileList: async (params?: {
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
category_id?: number,
|
||||
fileType?: string,
|
||||
keyword?: string
|
||||
}): Promise<FileListResponse> => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/upload/list`, { params });
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
getFileInfo: async (id: number): Promise<FileInfoResponse> => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/upload/${id}`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
updateDownloadCount: async (id: number): Promise<FileDeleteResponse> => {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/upload/${id}/download`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
deleteFile: async (id: number): Promise<FileDeleteResponse> => {
|
||||
try {
|
||||
const response = await axios.delete(`${API_BASE_URL}/upload/${id}`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
getCategories: async (params?: {
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
search?: string
|
||||
}): Promise<FileCategoryListResponse> => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/file-categories`, { params });
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
createCategory: async (data: Partial<FileCategory>): Promise<FileCategoryCreateResponse> => {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/file-categories`, data);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
updateCategory: async (id: number, data: Partial<FileCategory>): Promise<FileCategoryUpdateResponse> => {
|
||||
try {
|
||||
const response = await axios.put(`${API_BASE_URL}/file-categories/${id}`, data);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
deleteCategory: async (id: number): Promise<FileCategoryDeleteResponse> => {
|
||||
try {
|
||||
const response = await axios.delete(`${API_BASE_URL}/file-categories/${id}`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user