storage list/listAll

This commit is contained in:
ehesp
2019-07-30 12:41:09 +01:00
parent f799471167
commit e3b195cbe1
6 changed files with 374 additions and 1 deletions

View File

@@ -24,12 +24,13 @@ import {
isUndefined,
getDataUrlParts,
pathLastComponent,
ReferenceBase,
ReferenceBase, isObject, hasOwnProperty, isNumber,
} from '@react-native-firebase/common';
import { validateMetadata } from './utils';
import StorageStatics from './StorageStatics';
import StorageUploadTask from './StorageUploadTask';
import StorageDownloadTask from './StorageDownloadTask';
import StorageListResult, { provideStorageReferenceClass } from './StorageListResult';
export default class StorageReference extends ReferenceBase {
constructor(storage, path) {
@@ -112,6 +113,64 @@ export default class StorageReference extends ReferenceBase {
return this._storage.native.getMetadata(this.toString());
}
/**
* @url https://firebase.google.com/docs/reference/js/firebase.storage.Reference#list
*/
list(options) {
if (!isUndefined(options) && !isObject(options)) {
throw new Error(
"firebase.storage.StorageReference.list(*) 'options' expected an object value.",
);
}
const listOptions = {
maxResults: 1000,
};
if (hasOwnProperty(options, 'maxResults')) {
if (!isNumber(options.maxResults)) {
throw new Error(
"firebase.storage.StorageReference.list(*) 'options.maxResults' expected a number value.",
);
}
// todo integer check
if (options.maxResults < 1 || options.maxResults > 1000) {
throw new Error(
"firebase.storage.StorageReference.list(*) 'options.maxResults' expected a number value between 1-1000.",
);
}
listOptions.maxResults = options.maxResults;
}
if (options.pageToken) {
if (!isString(options.pageToken)) {
throw new Error(
"firebase.storage.StorageReference.list(*) 'options.pageToken' expected a string value.",
);
}
listOptions.pageToken = options.pageToken;
}
return this._storage.native
.list(options)
.then(data => new StorageListResult(this._storage, data));
}
/**
* @url https://firebase.google.com/docs/reference/js/firebase.storage.Reference#listAll
*/
listAll() {
return this._storage.native
.listAll()
.then(data => new StorageListResult(this._storage, data));
}
/**
* @url https://firebase.google.com/docs/reference/js/firebase.storage.Reference#put
*/
@@ -244,3 +303,5 @@ export default class StorageReference extends ReferenceBase {
);
}
}
provideStorageReferenceClass(StorageReference);