import { AxiosProgressEvent } from "axios";
import { request } from "@/api/request";

/** 上传文件 */
const FtsUpload = (data: FormData, onUploadProgress?: (progress: number) => void) => {
  data.append('provider', 'local');
  data.append('bucket', 'visual');
  
  return request.post(
    `/fts/v1/uploader`, 
    data,
    {
      headers: {
        'Content-Type': 'multipart/form-data'
      },
      onUploadProgress: onUploadProgress ? (progressEvent: AxiosProgressEvent) => {
        if (progressEvent.total) {
          const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
          onUploadProgress(percentCompleted);
        }
      } : undefined
    }
  );
};

export default FtsUpload;
