Browse Source

Changing `return null;` to `return;`

Change-Id: I484657762ff1a73192b6d942efcd9f13c9c2f87d
ryanpbrewster-patch-1
Nicolas Garnier 8 years ago
parent
commit
1e7da02a75
  1. 6
      convert-images/functions/index.js
  2. 4
      exif-images/functions/index.js
  3. 6
      generate-thumbnail/functions/index.js
  4. 20
      quickstarts/thumbnails/functions/index.js

6
convert-images/functions/index.js

@ -44,19 +44,19 @@ exports.imageToJPG = functions.storage().onChange(event => {
// Exit if this is triggered on a file that is not an image.
if (!event.data.contentType.startsWith('image/')) {
console.log('This is not an image.');
return null;
return;
}
// Exit if the image is already a JPEG.
if (event.data.contentType.startsWith('image/jpeg')) {
console.log('Already a JPEG.');
return null;
return;
}
// Exit if this is a move or deletion event.
if (event.data.resourceState === 'not_exists') {
console.log('This is a deletion event.');
return null;
return;
}
// Create the temp directory where the storage file will be downloaded.

4
exif-images/functions/index.js

@ -34,13 +34,13 @@ exports.metadata = functions.storage().onChange(event => {
// Exit if this is triggered on a file that is not an image.
if (!event.data.contentType.startsWith('image/')) {
console.log('This is not an image.');
return null;
return;
}
// Exit if this is a move or deletion event.
if (event.data.resourceState === 'not_exists') {
console.log('This is a deletion event.');
return null;
return;
}
// Download file from bucket.

6
generate-thumbnail/functions/index.js

@ -44,19 +44,19 @@ exports.generateThumbnail = functions.storage().onChange(event => {
// Exit if this is triggered on a file that is not an image.
if (!event.data.contentType.startsWith('image/')) {
console.log('This is not an image.');
return null;
return;
}
// Exit if the image is already a thumbnail.
if (fileName.startsWith(THUMB_PREFIX)) {
console.log('Already a Thumbnail.');
return null;
return;
}
// Exit if this is a move or deletion event.
if (event.data.resourceState === 'not_exists') {
console.log('This is a deletion event.');
return null;
return;
}
// Create the temp directory where the storage file will be downloaded.

20
quickstarts/thumbnails/functions/index.js

@ -40,7 +40,7 @@ exports.generateThumbnail = functions.storage().onChange(event => {
// Exit if this is triggered on a file that is not an image.
if (!contentType.startsWith('image/')) {
console.log('This is not an image.');
return null;
return;
}
// Get the file name.
@ -48,31 +48,31 @@ exports.generateThumbnail = functions.storage().onChange(event => {
// Exit if the image is already a thumbnail.
if (fileName.startsWith('thumb_')) {
console.log('Already a Thumbnail.');
return null;
return;
}
// Exit if this is a move or deletion event.
if (resourceState === 'not_exists') {
console.log('This is a deletion event.');
return null;
return;
}
// [END stopConditions]
// [START thumbnailGeneration]
// Download file from bucket.
const bucket = gcs.bucket(fileBucket);
const tempLocalFilePath = `/tmp/${fileName}`;
const tempFilePath = `/tmp/${fileName}`;
return bucket.file(filePath).download({
destination: tempLocalFilePath
destination: tempFilePath
}).then(() => {
console.log('Image downloaded locally to', tempLocalFilePath);
console.log('Image downloaded locally to', tempFilePath);
// Generate a thumbnail using ImageMagick.
return exec(`convert "${tempLocalFilePath}" -thumbnail '200x200>' "${tempLocalFilePath}"`).then(() => {
console.log('Thumbnail created at', tempLocalFilePath);
// We add a 'thumb_' prefix to thumbnails. That's where we'll upload the thumbnail.
return exec(`convert "${tempFilePath}" -thumbnail '200x200>' "${tempFilePath}"`).then(() => {
console.log('Thumbnail created at', tempFilePath);
// We add a 'thumb_' prefix to thumbnails file name. That's where we'll upload the thumbnail.
const thumbFilePath = filePath.replace(/(\/)?([^\/]*)$/, `$1thumb_$2`);
// Uploading the thumbnail.
return bucket.upload(tempLocalFilePath, {
return bucket.upload(tempFilePath, {
destination: thumbFilePath
});
});

Loading…
Cancel
Save