diff --git a/webapp/src/components/App/Singlestudy/explore/Debug/Data/Json.tsx b/webapp/src/components/App/Singlestudy/explore/Debug/Data/Json.tsx index 6f04cb26f1..5df699950b 100644 --- a/webapp/src/components/App/Singlestudy/explore/Debug/Data/Json.tsx +++ b/webapp/src/components/App/Singlestudy/explore/Debug/Data/Json.tsx @@ -42,8 +42,8 @@ function Json({ filePath, filename, studyId, canEdit }: DataCompProps) { //////////////////////////////////////////////////////////////// const handleDownload = async () => { - const { data, filename } = await getRawFile({ studyId, path: filePath }); - downloadFile(data, filename); + const file = await getRawFile({ studyId, path: filePath }); + downloadFile(file, file.name); }; const handleSave: JSONEditorProps["onSave"] = (json) => { diff --git a/webapp/src/components/App/Singlestudy/explore/Debug/Data/Text.tsx b/webapp/src/components/App/Singlestudy/explore/Debug/Data/Text.tsx index 3ea722e4d9..1ee8be74c0 100644 --- a/webapp/src/components/App/Singlestudy/explore/Debug/Data/Text.tsx +++ b/webapp/src/components/App/Singlestudy/explore/Debug/Data/Text.tsx @@ -92,8 +92,8 @@ function Text({ //////////////////////////////////////////////////////////////// const handleDownload = async () => { - const { data, filename } = await getRawFile({ studyId, path: filePath }); - downloadFile(data, filename); + const file = await getRawFile({ studyId, path: filePath }); + downloadFile(file, file.name); }; const handleUploadSuccessful = () => { diff --git a/webapp/src/components/App/Singlestudy/explore/Debug/Data/Unsupported.tsx b/webapp/src/components/App/Singlestudy/explore/Debug/Data/Unsupported.tsx index c56c9f89d2..81307a4edf 100644 --- a/webapp/src/components/App/Singlestudy/explore/Debug/Data/Unsupported.tsx +++ b/webapp/src/components/App/Singlestudy/explore/Debug/Data/Unsupported.tsx @@ -30,8 +30,8 @@ function Unsupported({ studyId, filePath, filename, canEdit }: DataCompProps) { //////////////////////////////////////////////////////////////// const handleDownload = async () => { - const { data, filename } = await getRawFile({ studyId, path: filePath }); - downloadFile(data, filename); + const file = await getRawFile({ studyId, path: filePath }); + downloadFile(file, file.name); }; //////////////////////////////////////////////////////////////// diff --git a/webapp/src/components/common/buttons/DownloadMatrixButton.tsx b/webapp/src/components/common/buttons/DownloadMatrixButton.tsx index 30e4db88b0..b50e3e81da 100644 --- a/webapp/src/components/common/buttons/DownloadMatrixButton.tsx +++ b/webapp/src/components/common/buttons/DownloadMatrixButton.tsx @@ -19,6 +19,8 @@ import { useTranslation } from "react-i18next"; import DownloadButton from "./DownloadButton"; import type { TTableExportFormat } from "@/services/api/studies/raw/types"; +type ExportFormat = TTableExportFormat | "raw"; + export interface DownloadMatrixButtonProps { studyId: StudyMetadata["id"]; path: string; @@ -30,7 +32,7 @@ function DownloadMatrixButton(props: DownloadMatrixButtonProps) { const { t } = useTranslation(); const { studyId, path, disabled, label = t("global.export") } = props; - const options: Array<{ label: string; value: TTableExportFormat }> = [ + const options: Array<{ label: string; value: ExportFormat }> = [ { label: "CSV", value: "csv" }, { label: `CSV (${t("global.semicolon").toLowerCase()})`, @@ -45,14 +47,14 @@ function DownloadMatrixButton(props: DownloadMatrixButtonProps) { // Event Handlers //////////////////////////////////////////////////////////////// - const handleDownload = async (format: TTableExportFormat) => { + const handleDownload = async (format: ExportFormat) => { if (!path) { return; } if (format === "raw") { - const { data, filename } = await getRawFile({ studyId, path }); - return downloadFile(data, filename); + const file = await getRawFile({ studyId, path }); + return downloadFile(file, file.name); } const isXlsx = format === "xlsx"; diff --git a/webapp/src/services/api/studies/raw/constants.ts b/webapp/src/services/api/studies/raw/constants.ts index d4a701d611..9481e0557c 100644 --- a/webapp/src/services/api/studies/raw/constants.ts +++ b/webapp/src/services/api/studies/raw/constants.ts @@ -18,5 +18,4 @@ export const TableExportFormat = { TSV: "tsv", CSV: "csv", CSV_SEMICOLON: "csv (semicolon)", - RAW: "raw", } as const; diff --git a/webapp/src/services/api/studies/raw/index.ts b/webapp/src/services/api/studies/raw/index.ts index 4e2938c4a6..663877aafc 100644 --- a/webapp/src/services/api/studies/raw/index.ts +++ b/webapp/src/services/api/studies/raw/index.ts @@ -17,7 +17,6 @@ import type { DeleteFileParams, GetMatrixFileParams, GetRawFileParams, - RawFile, UploadFileParams, } from "./types"; @@ -94,10 +93,10 @@ export async function deleteFile(params: DeleteFileParams) { * @param params.path - Path to the file within the study * @returns Promise containing the file data and metadata */ -export async function getRawFile(params: GetRawFileParams): Promise { +export async function getRawFile(params: GetRawFileParams) { const { studyId, path } = params; - const { data, headers } = await client.get( + const { data, headers } = await client.get( `/v1/studies/${studyId}/raw/original-file`, { params: { @@ -119,8 +118,8 @@ export async function getRawFile(params: GetRawFileParams): Promise { } } - return { - data, - filename, - }; + return new File([data], filename, { + type: data.type, // Preserve the MIME type from the Blob + lastModified: new Date().getTime(), + }); } diff --git a/webapp/src/services/api/studies/raw/types.ts b/webapp/src/services/api/studies/raw/types.ts index 13bece37f8..c74958c376 100644 --- a/webapp/src/services/api/studies/raw/types.ts +++ b/webapp/src/services/api/studies/raw/types.ts @@ -46,7 +46,3 @@ export interface GetRawFileParams { studyId: string; path: string; } -export interface RawFile { - data: Blob; - filename: string; -}