feat: implement download functionality for filtered dataset entries as ZIP

This commit is contained in:
averel10
2026-03-13 10:53:55 +01:00
parent e107765752
commit 03118c468a
7 changed files with 402 additions and 14 deletions

46
src/lib/download-utils.ts Normal file
View File

@@ -0,0 +1,46 @@
interface FilterParams {
speakerId?: string;
modelName?: string;
dialect?: string;
iteration?: number | string;
utteranceId?: string;
}
export async function downloadFilteredEntriesAsZip(
datasetId: number,
filters: FilterParams
) {
try {
const response = await fetch('/api/download-filtered-entries', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
datasetId,
filters,
}),
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || 'Failed to download ZIP');
}
// Get the ZIP blob from response
const blob = await response.blob();
// Trigger download
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `dataset-${datasetId}-export-${new Date().toISOString().split('T')[0]}.zip`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
} catch (error) {
console.error('Error downloading ZIP:', error);
throw error;
}
}