Merged in hotfix/2025-06-25 (pull request #2380)

Hotfix/2025 06 25 - IO-3279 IO-3281
This commit is contained in:
Patrick Fic
2025-06-25 17:08:57 +00:00
7 changed files with 57 additions and 62 deletions

View File

@@ -56,22 +56,25 @@ export function JobsDocumentsImgproxyDownloadButton({ bodyshop, galleryImages, i
const handleDownload = async () => { const handleDownload = async () => {
logImEXEvent("jobs_documents_download"); logImEXEvent("jobs_documents_download");
setLoading(true); setLoading(true);
const zipUrl = await axios({ try {
url: "/media/imgproxy/download", const response = await axios({
method: "POST", url: "/media/imgproxy/download",
data: { jobId, documentids: imagesToDownload.map((_) => _.id) } method: "POST",
}); responseType: "blob",
data: { jobId, documentids: imagesToDownload.map((_) => _.id) },
onDownloadProgress: downloadProgress
});
const theDownloadedZip = await cleanAxios({ setLoading(false);
url: zipUrl.data.url, setDownload(null);
method: "GET",
responseType: "arraybuffer",
onDownloadProgress: downloadProgress
});
setLoading(false);
setDownload(null);
standardMediaDownload(theDownloadedZip.data); // Use the response data (Blob) to trigger download
standardMediaDownload(response.data);
} catch (error) {
setLoading(false);
setDownload(null);
// handle error (optional)
}
}; };
return ( return (

View File

@@ -98,7 +98,13 @@ function JobsDocumentsImgproxyComponent({
jobId={jobId} jobId={jobId}
totalSize={totalSize} totalSize={totalSize}
billId={billId} billId={billId}
callbackAfterUpload={billsCallback || fetchThumbnails || refetch} callbackAfterUpload={
billsCallback ||
function () {
isFunction(refetch) && refetch();
isFunction(fetchThumbnails) && fetchThumbnails();
}
}
ignoreSizeLimit={ignoreSizeLimit} ignoreSizeLimit={ignoreSizeLimit}
/> />
</Card> </Card>

View File

@@ -383,7 +383,7 @@ export function ShopEmployeesFormComponent({ bodyshop }) {
title={() => <ShopEmployeeAddVacation employee={data && data.employees_by_pk} />} title={() => <ShopEmployeeAddVacation employee={data && data.employees_by_pk} />}
columns={columns} columns={columns}
rowKey={"id"} rowKey={"id"}
dataSource={data ? data.employees_by_pk.employee_vacations : []} dataSource={data?.employees_by_pk?.employee_vacations ?? []}
/> />
</Card> </Card>
); );

12
package-lock.json generated
View File

@@ -63,7 +63,8 @@
"winston": "^3.17.0", "winston": "^3.17.0",
"winston-cloudwatch": "^6.3.0", "winston-cloudwatch": "^6.3.0",
"xml2js": "^0.6.2", "xml2js": "^0.6.2",
"xmlbuilder2": "^3.1.1" "xmlbuilder2": "^3.1.1",
"yazl": "^3.3.1"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.28.0", "@eslint/js": "^9.28.0",
@@ -13057,6 +13058,15 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/yazl": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/yazl/-/yazl-3.3.1.tgz",
"integrity": "sha512-BbETDVWG+VcMUle37k5Fqp//7SDOK2/1+T7X8TD96M3D9G8jK5VLUdQVdVjGi8im7FGkazX7kk5hkU8X4L5Bng==",
"license": "MIT",
"dependencies": {
"buffer-crc32": "^1.0.0"
}
},
"node_modules/yocto-queue": { "node_modules/yocto-queue": {
"version": "0.1.0", "version": "0.1.0",
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",

View File

@@ -70,7 +70,8 @@
"winston": "^3.17.0", "winston": "^3.17.0",
"winston-cloudwatch": "^6.3.0", "winston-cloudwatch": "^6.3.0",
"xml2js": "^0.6.2", "xml2js": "^0.6.2",
"xmlbuilder2": "^3.1.1" "xmlbuilder2": "^3.1.1",
"yazl": "^3.3.1"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.28.0", "@eslint/js": "^9.28.0",

View File

@@ -35,7 +35,7 @@ exports.default = async (req, res) => {
//Query the usage data. //Query the usage data.
const queryResults = await client.request(queries.STATUS_UPDATE, { const queryResults = await client.request(queries.STATUS_UPDATE, {
today: moment().startOf("day").subtract(7, "days"), today: moment().startOf("day").subtract(7, "days"),
period: moment().subtract(90, "days").startOf("day") period: moment().subtract(365, "days").startOf("day")
}); });
//Massage the data. //Massage the data.
@@ -66,7 +66,7 @@ exports.default = async (req, res) => {
Usage Report for ${moment().format("MM/DD/YYYY")} for Rome Online Customers. Usage Report for ${moment().format("MM/DD/YYYY")} for Rome Online Customers.
Notes: Notes:
- Days Since Creation: The number of days since the shop was created. Only shops created in the last 90 days are included. - Days Since Creation: The number of days since the shop was created. Only shops created in the last 365 days are included.
- Updated values should be higher than created values. - Updated values should be higher than created values.
- Counts are inclusive of the last 7 days of data. - Counts are inclusive of the last 7 days of data.
`, `,

View File

@@ -20,6 +20,7 @@ const {
GET_DOCUMENTS_BY_IDS, GET_DOCUMENTS_BY_IDS,
DELETE_MEDIA_DOCUMENTS DELETE_MEDIA_DOCUMENTS
} = require("../graphql-client/queries"); } = require("../graphql-client/queries");
const yazl = require("yazl");
const imgproxyBaseUrl = process.env.IMGPROXY_BASE_URL; // `https://u4gzpp5wm437dnm75qa42tvza40fguqr.lambda-url.ca-central-1.on.aws` //Direct Lambda function access to bypass CDN. const imgproxyBaseUrl = process.env.IMGPROXY_BASE_URL; // `https://u4gzpp5wm437dnm75qa42tvza40fguqr.lambda-url.ca-central-1.on.aws` //Direct Lambda function access to bypass CDN.
const imgproxySalt = process.env.IMGPROXY_SALT; const imgproxySalt = process.env.IMGPROXY_SALT;
@@ -174,65 +175,39 @@ const downloadFiles = async (req, res) => {
try { try {
logger.log("imgproxy-download", "DEBUG", req.user?.email, jobId, { billid, jobId, documentids }); logger.log("imgproxy-download", "DEBUG", req.user?.email, jobId, { billid, jobId, documentids });
//Delayed as the key structure may change slightly from what it is currently and will require evaluating mobile components.
const client = req.userGraphQLClient; const client = req.userGraphQLClient;
//Query for the keys of the document IDs
const data = await client.request(GET_DOCUMENTS_BY_IDS, { documentIds: documentids }); const data = await client.request(GET_DOCUMENTS_BY_IDS, { documentIds: documentids });
//Using the Keys, get all the S3 links, zip them, and send back to the client.
const s3client = new S3Client({ region: InstanceRegion() }); const s3client = new S3Client({ region: InstanceRegion() });
const archiveStream = archiver("zip"); const zipfile = new yazl.ZipFile();
archiveStream.on("error", (error) => { // Set response headers for zip download
console.error("Archival encountered an error:", error); const filename = `archive-${jobId || "na"}-${new Date().toISOString().replace(/[:.]/g, "-")}.zip`;
throw new Error(error); res.setHeader("Content-Type", "application/zip");
}); res.setHeader("Content-Disposition", `attachment; filename="${filename}"`);
const passThrough = new stream.PassThrough(); // Pipe the zipfile output directly to the response
zipfile.outputStream.pipe(res);
archiveStream.pipe(passThrough); // Add each file to the zip as a stream
for (const doc of data.documents) {
for (const key of data.documents.map((d) => d.key)) { const key = doc.key;
const response = await s3client.send( const response = await s3client.send(
new GetObjectCommand({ new GetObjectCommand({
Bucket: imgproxyDestinationBucket, Bucket: imgproxyDestinationBucket,
Key: key Key: key
}) })
); );
// response.Body is a readable stream
archiveStream.append(response.Body, { name: path.basename(key) }); zipfile.addReadStream(response.Body, path.basename(key));
} }
await archiveStream.finalize(); // Finalize the zip after all files are added
zipfile.end();
// No need to send a JSON response, as the zip is streamed directly
const archiveKey = `archives/${jobId || "na"}/archive-${new Date().toISOString()}.zip`;
const parallelUploads3 = new Upload({
client: s3client,
queueSize: 4, // optional concurrency configuration
leavePartsOnError: false, // optional manually handle dropped parts
params: { Bucket: imgproxyDestinationBucket, Key: archiveKey, Body: passThrough }
});
// Disabled progress logging for upload, uncomment if needed
// parallelUploads3.on("httpUploadProgress", (progress) => {
// console.log(progress);
// });
await parallelUploads3.done();
//Generate the presigned URL to download it.
const presignedUrl = await getSignedUrl(
s3client,
new GetObjectCommand({ Bucket: imgproxyDestinationBucket, Key: archiveKey }),
{ expiresIn: 360 }
);
return res.json({ success: true, url: presignedUrl });
//Iterate over them, build the link based on the media type, and return the array.
} catch (error) { } catch (error) {
logger.log("imgproxy-thumbnails-error", "ERROR", req.user?.email, jobId, { logger.log("imgproxy-download-error", "ERROR", req.user?.email, jobId, {
jobId, jobId,
billid, billid,
message: error.message, message: error.message,