已从10个API模块文件中移除重复的API_BASE_URL定义

所有API调用现在统一使用client/admin/api/index.ts中的全局axios配置
保持原有功能不变的同时简化了代码结构
This commit is contained in:
yourname
2025-05-13 11:44:28 +00:00
parent d0d88ab950
commit e4f45ed952
10 changed files with 64 additions and 66 deletions

View File

@@ -2,8 +2,6 @@ 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;
@@ -59,7 +57,7 @@ interface FileCategoryDeleteResponse {
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;
@@ -70,7 +68,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;
@@ -85,7 +83,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;
@@ -94,7 +92,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;
@@ -103,7 +101,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;
@@ -112,7 +110,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;
@@ -125,7 +123,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;
@@ -134,7 +132,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;
@@ -143,7 +141,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;
@@ -152,7 +150,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;