feat: allow users to download exports

This commit is contained in:
Pablo Lara authored and Adrián Jesús Peña Rodríguez committed 2025-02-19 10:40:12 +01:00
1 parent 526b20ca0a
commit eb0f6addb4
3 files changed
+81 -6

No files matched your search

+37
View File
@@ -198,3 +198,40 @@ export const updateScan = async (formData: FormData) => {
};
}
};
export const getExportsZip = async (scanId: string) => {
const session = await auth();
const keyServer = process.env.API_BASE_URL;
const url = new URL(`${keyServer}/scans/${scanId}/report`);
try {
const response = await fetch(url.toString(), {
headers: {
Authorization: `Bearer ${session?.accessToken}`,
},
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(
errorData?.errors?.[0]?.detail || "Failed to fetch report",
);
}
// Get the blob data as an array buffer
const arrayBuffer = await response.arrayBuffer();
// Convert to base64
const base64 = Buffer.from(arrayBuffer).toString("base64");
return {
success: true,
data: base64,
filename: `scan-${scanId}-report.zip`,
};
} catch (error) {
return {
error: getErrorMessage(error),
};
}
};