Skip to content

Commit 307e8b9

Browse files
committed
fix: remove ImageMagick comments and resolve linting issues
1 parent de4a9c5 commit 307e8b9

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

functions/imagemagick/index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ const {BLURRED_BUCKET_NAME} = process.env;
3232
exports.blurOffensiveImages = async event => {
3333
// This event represents the triggering Cloud Storage object.
3434
const object = event;
35+
if (object.bucket === BLURRED_BUCKET_NAME) {
36+
console.log(
37+
'Event triggered by the blurred bucket; skip to avoid recursion'
38+
);
39+
return;
40+
}
3541

3642
const file = storage.bucket(object.bucket).file(object.name);
3743
const filePath = `gs://${object.bucket}/${object.name}`;
@@ -60,7 +66,7 @@ exports.blurOffensiveImages = async event => {
6066
// [END functions_imagemagick_analyze]
6167

6268
// [START functions_imagemagick_blur]
63-
// Blurs the given file using ImageMagick, and uploads it to another bucket.
69+
// Blurs the given file using sharp, and uploads it to another bucket.
6470
const blurImage = async (file, blurredBucketName) => {
6571
const tempLocalPath = `/tmp/${path.parse(file.name).base}`;
6672
const tempLocalBlurredPath = `/tmp/blurred-${path.parse(file.name).base}`;
@@ -92,10 +98,12 @@ const blurImage = async (file, blurredBucketName) => {
9298
console.log(`Uploaded blurred image to: ${gcsPath}`);
9399
} catch (err) {
94100
throw new Error(`Unable to upload blurred image to ${gcsPath}: ${err}`);
101+
} finally {
102+
// Delete the temporary file.
103+
await Promise.allSettled([
104+
fs.unlink(tempLocalPath),
105+
fs.unlink(tempLocalBlurredPath),
106+
]);
95107
}
96-
97-
// Delete the temporary file.
98-
await fs.unlink(tempLocalPath);
99-
return await fs.unlink(tempLocalBlurredPath);
100108
};
101109
// [END functions_imagemagick_blur]

functions/imagemagick/test/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('functions/imagemagick tests', () => {
101101
});
102102
} catch (err) {
103103
console.error(
104-
`[Cloud Function Error]: ${err.response?.data || err.message}`
104+
`Cloud Function Error: ${err.response?.data || err.message}`
105105
);
106106
throw err;
107107
} finally {
@@ -128,7 +128,7 @@ describe('functions/imagemagick tests', () => {
128128
});
129129
} catch (err) {
130130
console.error(
131-
`[Cloud Function Error]: ${err.response?.data || err.message}`
131+
`Cloud Function Error: ${err.response?.data || err.message}`
132132
);
133133
throw err;
134134
} finally {

0 commit comments

Comments
 (0)