From 2b6ef23ab96af2e2de5590698e34ada33f96e4c2 Mon Sep 17 00:00:00 2001 From: AYM1607 Date: Sun, 7 Apr 2019 19:08:18 -0500 Subject: [PATCH] Fixed a bug where all the thumnails where the same as the first one in the firebase function --- functions/src/index.ts | 11 ++++++++--- lib/src/resources/firebase_storage_provider.dart | 2 +- lib/src/screens/new_image_screen.dart | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/functions/src/index.ts b/functions/src/index.ts index 4f29223..1612904 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -10,17 +10,22 @@ import * as sharp from 'sharp'; import * as fs from 'fs-extra'; export const generateThumb = functions.storage.object().onFinalize(async object => { - // Find the bucket where the uploaded dile resides. + // Find the bucket where the uploaded file resides. const bucket = gcs.bucket(object.bucket); + + // Find the path of the file inside the bucket. const filePathGcs = object.name; + + // Save the name of the file. const fileName = filePathGcs!.split('/').pop(); + // Directory where the file is stored inside the bucket. const bucketDirectory = dirname(filePathGcs!); const workingDirectory = join(tmpdir(), 'thumbnails'); - const tmpFilePath = join(workingDirectory, 'source.png'); + const tmpFilePath = join(workingDirectory, fileName!); if (fileName!.includes('thumb@') || !object.contentType!.includes('image')) { - console.log('Exiting function'); + console.log('Exiting function, already compressed or no image.'); return false; } diff --git a/lib/src/resources/firebase_storage_provider.dart b/lib/src/resources/firebase_storage_provider.dart index 1715302..d4ffc24 100644 --- a/lib/src/resources/firebase_storage_provider.dart +++ b/lib/src/resources/firebase_storage_provider.dart @@ -34,7 +34,7 @@ class FirebaseStorageProvider { _storage.child('$folder$fileId.$type'); return fileReference.putFile( file, - StorageMetadata(contentType: 'image'), + StorageMetadata(contentType: 'image/png'), ); } diff --git a/lib/src/screens/new_image_screen.dart b/lib/src/screens/new_image_screen.dart index bae5e78..7f9c678 100644 --- a/lib/src/screens/new_image_screen.dart +++ b/lib/src/screens/new_image_screen.dart @@ -140,12 +140,14 @@ class _NewImageScreenState extends State { Navigator.of(context).pop(); } + // TODO: Pro users can save their pictures in full res. /// Prompts the user to take a picture. /// /// Updates the file in the bloc. Future takePicture() async { final File imgFile = await ImagePicker.pickImage( source: ImageSource.camera, + maxWidth: 1500, ); bloc.changePicture(imgFile); }