Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Bit-Barron committed Sep 24, 2024
1 parent 456f73c commit 054925c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion server/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ export class AppController {
);
}

const imagePath = path.join(path.resolve(), 'images');
fs.mkdirSync(imagePath, { recursive: true });

const zip = new JSZip();

for (const image of images) {
const name = new URL(image.url).pathname.split('/').slice(-1)[0];
const imageType = image.headers
?.find((header) => header.name.toLowerCase() === 'content-type')
?.value.replace('image/', '');

const response = await axios.get(image.url, {
responseType: 'arraybuffer',
Expand All @@ -74,10 +80,17 @@ export class AppController {

const zipBuffer = await zip.generateAsync({ type: 'nodebuffer' });

const zipFileName = path.join(imagePath, `images.zip`);
fs.writeFileSync(zipFileName, zipBuffer);

reply
.header('Content-Type', 'application/zip')
.header('Content-Disposition', 'attachment; filename=images.zip')
.header('Content-Disposition', `attachment; filename=images.zip`)
.send(zipBuffer);

fs.unlinkSync(zipFileName);

return zipFileName;
} catch (error) {
console.error('Error processing images:', error);
throw new HttpException(
Expand Down

0 comments on commit 054925c

Please sign in to comment.