feat: update triggerDownload function to accept file extension parameter

This commit is contained in:
Andrej
2025-12-01 19:37:06 +01:00
parent 3a9f9c0d58
commit ddf6787b76
3 changed files with 5 additions and 5 deletions

View File

@@ -15,7 +15,7 @@ async function requestDownload() {
try {
const proof = await client<Blob>(`/api/internships/${props.internship_id}/default-proof`);
triggerDownload(proof, `default-proof-${props.internship_id}`);
triggerDownload(proof, `default-proof-${props.internship_id}`, 'pdf');
} catch (e) {
if (e instanceof FetchError) {
alert(`Nepodarilo sa vygenerovať zmluvu: ${e.statusMessage}`);

View File

@@ -9,12 +9,12 @@ const client = useSanctumClient();
async function downloadAgreement() {
const proof: Blob = await client(`/api/internships/${props.internship.id}/proof`);
triggerDownload(proof, `proof-${props.internship.id}`);
triggerDownload(proof, `proof-${props.internship.id}`, 'pdf');
}
async function downloadReport() {
const report: Blob = await client(`/api/internships/${props.internship.id}/report`);
triggerDownload(report, `report-${props.internship.id}`);
triggerDownload(report, `report-${props.internship.id}`, 'pdf');
}
</script>

View File

@@ -1,8 +1,8 @@
export function triggerDownload(file: Blob, file_name: string) {
export function triggerDownload(file: Blob, file_name: string, ext: string) {
const url = window.URL.createObjectURL(file);
const link = document.createElement('a');
link.href = url;
link.download = `${file_name}.pdf`;
link.download = `${file_name}.${ext}`;
link.target = "_blank";
link.click();
window.URL.revokeObjectURL(url);