[js][storage] switch to native promises

This commit is contained in:
Salakar 2017-03-22 19:46:08 +00:00
parent dfa72c03f9
commit 00889e1a69
1 changed files with 7 additions and 37 deletions

View File

@ -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<Object> {
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<Object> {
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.<T>|*}
*/
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.<T>|*}
*/
getDownloadURL(): Promise<String> {
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.<T>|*}
*/
getMetadata(): Promise<Object> {
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.<T>|*}
*/
updateMetadata(metadata: Object = {}): Promise<Object> {
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<Object> {
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<Object> {
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);
}
}