Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/aws_s3/src/models/ drwxr-xr-x | |
| Viewing file: Select action/file-type: import { PutObjectCommand } from "@aws-sdk/client-s3";
import { s3Client } from "../config/s3Client.js";
import { chromium } from "playwright";
// S3 Upload Function
export const insertIntoS3 = async (bucketParams) => {
try {
const data = await s3Client.send(new PutObjectCommand(bucketParams));
console.log(`Successfully uploaded: ${bucketParams.Bucket}/${bucketParams.Key}`);
return data;
} catch (err) {
console.error("S3 Upload Error:", err.message);
return "error";
}
};
// Generate Invoice (Screenshot + PDF)
export const generateInvoice = async (folder_name, invoice_no, sale_id) => {
try {
const browser = await chromium.launch({
executablePath: "/usr/bin/chromium-browser",
});
const page = await browser.newPage();
await page.goto(`https://jiff.businesscloud.xyz/jiff_dashboard/generate-pdf/${sale_id}`, {
waitUntil: "networkidle",
});
const image_file = await page.screenshot({ fullPage: true });
const pdf_file = await page.pdf({ format: "a4" });
await browser.close();
// Upload PDF
await insertIntoS3({
Bucket: "jiffp",
Key: `${folder_name}/invoice/pdf/${invoice_no}.pdf`,
Body: pdf_file,
ContentType: "application/pdf",
ACL: "public-read",
});
// Upload Image
await insertIntoS3({
Bucket: "jiffp",
Key: `${folder_name}/invoice/images/${invoice_no}.webp`,
Body: image_file,
ContentType: "image/png",
ACL: "public-read",
});
return "success";
} catch (error) {
console.error("Invoice Generation Error:", error.message);
return "error";
}
};
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0055 ]-- |