MCPcopy Create free account
hub / github.com/Sethispr/image-compressor / downloadJob

Function downloadJob

utils.ts:46–72  ·  view source on GitHub ↗
(job: ImageJob, customFilename?: string)

Source from the content-addressed store, hash-verified

44};
45
46export const downloadJob = (job: ImageJob, customFilename?: string): void => {
47 if (!job.optimizedBlob) return;
48
49 const url = URL.createObjectURL(job.optimizedBlob);
50 const anchor = document.createElement('a');
51 anchor.href = url;
52
53 let extension = 'png';
54 if (job.optimizedBlob.type === 'image/jpeg') extension = 'jpg';
55 if (job.optimizedBlob.type === 'image/webp') extension = 'webp';
56 if (job.optimizedBlob.type === 'image/avif') extension = 'avif';
57 if (job.optimizedBlob.type === 'image/qoi') extension = 'qoi';
58 if (job.optimizedBlob.type === 'image/jxl') extension = 'jxl';
59 if (job.optimizedBlob.type === 'image/svg+xml') extension = 'svg';
60
61 const filenameBase = customFilename ?? job.file.name;
62 const safeBaseName = generateFilename(filenameBase, '{o}', 0);
63
64 anchor.download = `${safeBaseName}.${extension}`;
65 anchor.rel = 'noopener';
66
67 document.body.appendChild(anchor);
68 anchor.click();
69 document.body.removeChild(anchor);
70
71 URL.revokeObjectURL(url);
72};
73
74export const verifyFileSignature = async (
75 file: File,

Callers 3

AppFunction · 0.90
JobCardComponentFunction · 0.90
useDownloaderFunction · 0.90

Calls 1

generateFilenameFunction · 0.85

Tested by

no test coverage detected