From 00889e1a69e47e24466edb67491c1d5c7cc8a233 Mon Sep 17 00:00:00 2001 From: Salakar Date: Wed, 22 Mar 2017 19:46:08 +0000 Subject: [PATCH] [js][storage] switch to native promises --- lib/modules/storage/reference.js | 44 +++++--------------------------- 1 file changed, 7 insertions(+), 37 deletions(-) diff --git a/lib/modules/storage/reference.js b/lib/modules/storage/reference.js index 4e96e209..a5b8b0d5 100644 --- a/lib/modules/storage/reference.js +++ b/lib/modules/storage/reference.js @@ -1,7 +1,6 @@ /* @flow */ import { NativeModules } from 'react-native'; -import { promisify } from '../../utils'; import { ReferenceBase } from './../base'; import StorageTask, { UPLOAD_TASK, DOWNLOAD_TASK } from './task'; import Storage from './'; @@ -21,17 +20,7 @@ export default class StorageReference extends ReferenceBase { return this.path; } - // todo add support for method - put(data: Object, metadata: Object = {}): /*UploadTask*/Promise { - throw new Error('put() is not currently supported by react-native-firebase'); - } - - // todo add support for method - putString(data: string, format: String, metadata: Object = {}): /*UploadTask*/Promise { - throw new Error('putString() is not currently supported by react-native-firebase'); - } - - // todo eturn full gs://bucket/path + // todo return full gs://bucket/path toString(): String { return this.path; } @@ -50,11 +39,7 @@ export default class StorageReference extends ReferenceBase { * @returns {Promise.|*} */ delete(): Promise<*> { - return promisify('delete', FirebaseStorage)(this.path) - .catch((error) => { - this.log.error('Error deleting reference ', this.path, '. Error: ', error); - throw error; - }); + return FirebaseStorage.delete(this.path); } /** @@ -62,12 +47,7 @@ export default class StorageReference extends ReferenceBase { * @returns {Promise.|*} */ getDownloadURL(): Promise { - this.log.debug('getDownloadURL(', this.path, ')'); - return promisify('getDownloadURL', FirebaseStorage)(this.path) - .catch((err) => { - this.log.error('Error downloading URL for ', this.path, '. Error: ', err); - throw err; - }); + return FirebaseStorage.getDownloadURL(this.path); } /** @@ -75,11 +55,7 @@ export default class StorageReference extends ReferenceBase { * @returns {Promise.|*} */ getMetadata(): Promise { - return promisify('getMetadata', FirebaseStorage)(this.path) - .catch((error) => { - this.log.error('Error getting metadata for ', this.path, '. Error: ', error); - throw error; - }); + return FirebaseStorage.getMetadata(this.path); } /** @@ -88,11 +64,7 @@ export default class StorageReference extends ReferenceBase { * @returns {Promise.|*} */ updateMetadata(metadata: Object = {}): Promise { - return promisify('updateMetadata', FirebaseStorage)(this.path, metadata) - .catch((error) => { - this.log.error('Error updating metadata for ', this.path, '. Error: ', error); - throw error; - }); + return FirebaseStorage.updateMetadata(this.path, metadata); } /** @@ -101,8 +73,7 @@ export default class StorageReference extends ReferenceBase { * @return {Promise} */ downloadFile(filePath: string): Promise { - this.log.debug('download(', this.path, ') -> ', filePath); - return new StorageTask(DOWNLOAD_TASK, promisify('downloadFile', FirebaseStorage)(this.path, filePath), this); + return new StorageTask(DOWNLOAD_TASK, FirebaseStorage.downloadFile(this.path, filePath), this); } /** @@ -113,7 +84,6 @@ export default class StorageReference extends ReferenceBase { */ putFile(filePath: Object, metadata: Object = {}): Promise { const _filePath = filePath.replace('file://', ''); - this.log.debug('putFile(', _filePath, ') -> ', this.path); - return new StorageTask(UPLOAD_TASK, promisify('putFile', FirebaseStorage)(this.path, _filePath, metadata), this); + return new StorageTask(UPLOAD_TASK, FirebaseStorage.putFile(this.path, _filePath, metadata), this); } }