diff --git a/server/media/imgproxy-media.js b/server/media/imgproxy-media.js index d26b572ce..6bee7a6bc 100644 --- a/server/media/imgproxy-media.js +++ b/server/media/imgproxy-media.js @@ -50,17 +50,19 @@ const generateSignedUploadUrls = async (req, res) => { } logger.log("imgproxy-upload-success", "DEBUG", req.user?.email, jobid, { signedUrls }); - res.json({ + + return res.json({ success: true, signedUrls }); } catch (error) { - res.status(400).json({ - success: false, + logger.log("imgproxy-upload-error", "ERROR", req.user?.email, jobid, { message: error.message, stack: error.stack }); - logger.log("imgproxy-upload-error", "ERROR", req.user?.email, jobid, { + + return res.status(400).json({ + success: false, message: error.message, stack: error.stack }); @@ -134,7 +136,7 @@ const getThumbnailUrls = async (req, res) => { }); } - res.json(proxiedUrls); + return res.json(proxiedUrls); //Iterate over them, build the link based on the media type, and return the array. } catch (error) { logger.log("imgproxy-thumbnails-error", "ERROR", req.user?.email, jobid, { @@ -143,7 +145,8 @@ const getThumbnailUrls = async (req, res) => { message: error.message, stack: error.stack }); - res.status(400).json({ message: error.message, stack: error.stack }); + + return res.status(400).json({ message: error.message, stack: error.stack }); } }; @@ -169,9 +172,9 @@ const downloadFiles = async (req, res) => { throw new Error(error); }); - const passthrough = new stream.PassThrough(); + const passThrough = new stream.PassThrough(); - archiveStream.pipe(passthrough); + archiveStream.pipe(passThrough); for (const key of data.documents.map((d) => d.key)) { const response = await s3client.send( @@ -192,7 +195,7 @@ const downloadFiles = async (req, res) => { client: s3client, queueSize: 4, // optional concurrency configuration leavePartsOnError: false, // optional manually handle dropped parts - params: { Bucket: imgproxyDestinationBucket, Key: archiveKey, Body: passthrough } + params: { Bucket: imgproxyDestinationBucket, Key: archiveKey, Body: passThrough } }); parallelUploads3.on("httpUploadProgress", (progress) => { @@ -200,6 +203,7 @@ const downloadFiles = async (req, res) => { }); await parallelUploads3.done(); + //Generate the presigned URL to download it. const presignedUrl = await getSignedUrl( s3client, @@ -207,7 +211,7 @@ const downloadFiles = async (req, res) => { { expiresIn: 360 } ); - res.json({ success: true, url: presignedUrl }); + return res.json({ success: true, url: presignedUrl }); //Iterate over them, build the link based on the media type, and return the array. } catch (error) { logger.log("imgproxy-thumbnails-error", "ERROR", req.user?.email, jobId, { @@ -216,7 +220,8 @@ const downloadFiles = async (req, res) => { message: error.message, stack: error.stack }); - res.status(400).json({ message: error.message, stack: error.stack }); + + return res.status(400).json({ message: error.message, stack: error.stack }); } }; @@ -262,14 +267,15 @@ const deleteFiles = async (req, res) => { ids: result.filter((t) => !t.error).map((d) => d.id) }); - res.json({ errors, deleteMutationResult }); + return res.json({ errors, deleteMutationResult }); } catch (error) { logger.log("imgproxy-delete-files-error", "ERROR", req.user.email, null, { ids, message: error.message, stack: error.stack }); - res.status(400).json({ message: error.message, stack: error.stack }); + + return res.status(400).json({ message: error.message, stack: error.stack }); } }; @@ -334,14 +340,16 @@ const moveFiles = async (req, res) => { }); const client = req.userGraphQLClient; + if (mutations !== "") { const mutationResult = await client.request(`mutation { ${mutations} }`); - res.json({ errors, mutationResult }); - } else { - res.json({ errors: "No images were successfully moved on remote server. " }); + + return res.json({ errors, mutationResult }); } + + return res.json({ errors: "No images were successfully moved on remote server. " }); } catch (error) { logger.log("imgproxy-move-files-error", "ERROR", req.user.email, null, { documents, @@ -349,7 +357,8 @@ const moveFiles = async (req, res) => { message: error.message, stack: error.stack }); - res.status(400).json({ message: error.message, stack: error.stack }); + + return res.status(400).json({ message: error.message, stack: error.stack }); } };