import fs from "fs";
import https from "https";
import path from "path";

const dir = path.join(process.cwd(), "public");
if (!fs.existsSync(dir)) {
    fs.mkdirSync(dir, { recursive: true });
}

const fileUrl = "https://images.unsplash.com/photo-1530103862676-de8892bc952f?ixlib=rb-4.0.3&auto=format&fit=crop&w=1200&h=630&q=80";
const filePath = path.join(dir, "share-card.jpeg");

https.get(fileUrl, (res) => {
    const fileStream = fs.createWriteStream(filePath);
    res.pipe(fileStream);
    fileStream.on("finish", () => {
        fileStream.close();
        console.log("Image downloaded to public/share-card.jpeg");
    });
}).on("error", (err) => {
    console.error("Error downloading image:", err);
});
