Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
Bit-Barron committed Sep 24, 2024
1 parent 4f1bc60 commit 3faff94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 33 deletions.
22 changes: 2 additions & 20 deletions server/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,6 @@ export class AppController {
const { images, format } = payload;
console.log('Received request with format:', format);

if (format === 'original' && images.length === 1) {
// Handle single original image download
const image = images[0];
const response = await axios.get(image.url, {
responseType: 'arraybuffer',
});
const imageBuffer = Buffer.from(response.data);
const contentType = response.headers['content-type'];
const name = new URL(image.url).pathname.split('/').pop() || 'image';

reply
.header('Content-Type', contentType)
.header('Content-Disposition', `attachment; filename=${name}`)
.send(imageBuffer);

console.log('Single original image sent successfully');
return 'Image processed successfully';
}

const zip = new JSZip();

for (const image of images) {
Expand All @@ -71,6 +52,7 @@ export class AppController {
});
const imageBuffer = Buffer.from(response.data);

// Log the content type of the image
const contentType = response.headers['content-type'];
console.log(`Processing image: ${name}, Content-Type: ${contentType}`);

Expand Down Expand Up @@ -133,4 +115,4 @@ export class AppController {
})
.run();
}
}
}
16 changes: 3 additions & 13 deletions web/src/components/images/image-download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,11 @@ export const ImageDownload: React.FC = () => {
console.log("Response type:", response.data.type);

const contentDisposition = response.headers["content-disposition"];
let filename = contentDisposition
const filename = contentDisposition
? contentDisposition.split("filename=")[1].replace(/"/g, "")
: "download";
: "images.zip";

const blob = new Blob([response.data], { type: response.data.type });

// Handle different content types
if (response.data.type === "application/zip") {
filename = filename || "images.zip";
} else {
// For single file downloads (e.g., when format is 'original' and only one image)
const extension =
format === "original" ? images[0].url.split(".").pop() : format;
filename = `${filename || "image"}.${extension}`;
}
const blob = new Blob([response.data], { type: "application/zip" });

const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
Expand Down

0 comments on commit 3faff94

Please sign in to comment.