import { Inject , Injectable , PLATFORM_ID } from '@angular/core' ; import { AngularFireLiteApp } from '../core.service' ; import { isPlatformBrowser } from '@angular/common' ; import { from , Observable , Subject } from 'rxjs' ; import { FirebaseStorage } from '@firebase/storage-types' ; import 'firebase/storage' ; @ Injectable ( ) export class AngularFireLiteStorage { private readonly storage : FirebaseStorage ; private readonly browser = isPlatformBrowser ( this . platformId ) ; constructor ( private app , @ Inject ( PLATFORM_ID ) private platformId ) { this . storage = app . instance ( ) . storage ( ) ; } upload ( ref , file , metadata ? ) { if ( this . browser ) { return from ( this . child ( ref ) . put ( file , metadata ) ) ; } } uploadString ( ref , string ) { if ( this . browser ) { return from ( this . child ( ref ) . putString ( string ) ) ; } } getDownloadURL ( ref ) { if ( this . browser ) { return from ( this . child ( ref ) . getDownloadURL ( ) ) ; } } remove ( ref ) { if ( this . browser ) { return from ( this . child ( ref ) . delete ( ) ) ; } } getMetadata ( ref ) { if ( this . browser ) { const META = new Subject ( ) ; this . child ( ref ) . getMetadata ( ) . then ( ( meta ) => { META . next ( meta ) ; } ) ; return META ; } } updateMetadata ( ref , metadata ) { if ( this . browser ) { return from ( this . child ( ref ) . updateMetadata ( metadata ) ) ; } } deleteMetadata ( ref ) { if ( this . browser ) { return from ( this . child ( ref ) . updateMetadata ( { customMetadata : null , cacheControl : null , contentEncoding : null , contentLanguage : null , contentType : null } ) ) ; } } private child ( ref ) { return this . storage . ref ( ) . child ( ref ) ; } }