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 703f12a commit 1980069
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 50 deletions.
16 changes: 11 additions & 5 deletions server/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ interface Image {
headers?: { name: string; value: string }[];
}

interface Video {
// Add properties for Video interface if needed
}

@Controller('api')
export class AppController {
constructor(private readonly appService: AppService) {}
Expand All @@ -37,7 +41,7 @@ export class AppController {
) {
try {
const { images, format } = payload;
console.log(images, format);
console.log("Received request with format:", format);

if (format !== 'original' && !this.isValidFormat(format)) {
throw new HttpException(
Expand All @@ -56,8 +60,9 @@ export class AppController {
const imageBuffer = Buffer.from(response.data);

if (format === 'original') {
const contentType = response.headers['content-type'];
zip.file(name, imageBuffer, { binary: true });
const contentType = response.headers['content-type'] as string;
console.log(`Adding original image: ${name}, type: ${contentType}`);
zip.file(name, imageBuffer, { binary: true, comment: contentType });
} else {
let sharpInstance = sharp(imageBuffer);

Expand All @@ -73,12 +78,14 @@ export class AppController {
}

const zipBuffer = await zip.generateAsync({ type: 'nodebuffer' });
console.log("ZIP file size:", zipBuffer.length);

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

console.log("Response sent successfully");
return 'Images processed successfully';
} catch (error) {
console.error('Error processing images:', error);
Expand All @@ -91,7 +98,6 @@ export class AppController {

private isValidFormat(format: string): boolean {
const validFormats = [
'original',
'jpeg',
'png',
'webp',
Expand Down Expand Up @@ -130,4 +136,4 @@ export class AppController {
})
.run();
}
}
}
38 changes: 2 additions & 36 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,2 @@
import { ImageStore } from "@/store/ImageStore";
import "./App.css";
import { Images } from "./components/images";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "./components/ui/tabs";
import { Videos } from "./components/videos";
import { ImageDownload } from "./components/images/image-download";

const App = () => {
const { selectedImages } = ImageStore();

return (
<section className="relative min-h-screen">
<div className="flex justify-between mb-4">
<Tabs defaultValue="images" className="w-full">
<TabsList className="grid w-full grid-cols-2">
<TabsTrigger value="images">Images</TabsTrigger>
<TabsTrigger value="videos">Videos</TabsTrigger>
</TabsList>
<TabsContent value="images">
<Images />
{selectedImages.length > 0 && (
<div className="fixed bottom-4 right-4 z-50">
<ImageDownload />
</div>
)}
</TabsContent>
<TabsContent value="videos">
<Videos />
</TabsContent>
</Tabs>
</div>
</section>
);
};

export default App;
import { ImageStore } from "../../store/ImageStore";
import { Button } from "../ui/button";
28 changes: 19 additions & 9 deletions web/src/components/images/image-download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const ImageDownload: React.FC = () => {

const sendImages = async (images: Image[]): Promise<void> => {
try {
console.log("Sending request with format:", format);
const response = await axios.post(
`https://downconvert-server.barron.agency/api/imgs`,
{
Expand All @@ -28,20 +29,29 @@ export const ImageDownload: React.FC = () => {
responseType: "blob",
}
);
const contentdisposition =
response.headers["content-disposition"].split("=")[1];

console.log("Response headers:", response.headers);
console.log("Response type:", response.data.type);

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

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

if (downloadLinkRef.current) {
downloadLinkRef.current.href = URL.createObjectURL(blob);
downloadLinkRef.current.download = contentdisposition;
downloadLinkRef.current.click();
URL.revokeObjectURL(downloadLinkRef.current.href);
}
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);

toast.success("Images downloaded successfully");
} catch (err) {
console.error(err);
console.error("Error downloading images:", err);
toast.error("Error downloading images");
}
};
Expand Down

0 comments on commit 1980069

Please sign in to comment.