import request from "@/utils/request";

export interface UploadResponse {
  url: string;
  filename: string;
  originalname: string;
  size: number;
}

export const uploadApi = {
  // 上传文件
  upload: async (formData: FormData): Promise<UploadResponse> => {
    const response = await request.post<any, UploadResponse>(
      "/api/upload",
      formData,
      {
        headers: {
          "Content-Type": "multipart/form-data",
        },
      }
    );
    return response;
  },
};

/**
 * 上传单个文件
 */
export async function uploadFile(file: File): Promise<UploadResponse> {
  const formData = new FormData();
  formData.append("file", file);
  return uploadApi.upload(formData);
}
