import { request } from "@/components/service/index";

import { saveBlob, filenameFromContentDisposition } from "@/utils/download";

/**
 * 전역 스토리지 서비스 (MinIO, S3, FileSystem 통합 지원)
 */
export const StorageService = {
  async download(objectName: string) {
    const res = await request.getFile("/api/minio/download", {
      objectName,
      type: "type2", // Mlflow artifacts 등 대용량 다운로드용
    });

    const blob: Blob = res.data;
    const cd = res.headers?.["content-disposition"];
    const fallback = objectName.split("/").pop() || "download.bin";
    const filename = filenameFromContentDisposition(cd, fallback);

    saveBlob(blob, filename);
  },
};
