-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage): getDownloadURL pipe (#2648)
Co-authored-by: Admin Apple <adminapple@ackerlaptop.local> Co-authored-by: Admin Apple <acker.dawn.apple@gmail.com>
- Loading branch information
1 parent
1bbd3e4
commit 0d799da
Showing
6 changed files
with
158 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { AsyncPipe } from '@angular/common'; | ||
import { ChangeDetectorRef, NgModule, OnDestroy, Pipe, PipeTransform } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { AngularFireStorage } from '../storage'; | ||
|
||
/** to be used with in combination with | async */ | ||
@Pipe({ | ||
name: 'getDownloadURL', | ||
pure: false, | ||
}) | ||
export class GetDownloadURLPipe implements PipeTransform, OnDestroy { | ||
|
||
private asyncPipe: AsyncPipe; | ||
private path: string; | ||
private downloadUrl$: Observable<any>; | ||
|
||
constructor(private storage: AngularFireStorage, cdr: ChangeDetectorRef) { | ||
this.asyncPipe = new AsyncPipe(cdr); | ||
} | ||
|
||
transform(path: string) { | ||
if (path !== this.path) { | ||
this.path = path; | ||
this.downloadUrl$ = this.storage.ref(path).getDownloadURL(); | ||
} | ||
return this.asyncPipe.transform(this.downloadUrl$); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.asyncPipe.ngOnDestroy(); | ||
} | ||
|
||
} | ||
|
||
@NgModule({ | ||
declarations: [ GetDownloadURLPipe ], | ||
exports: [ GetDownloadURLPipe ], | ||
}) | ||
export class GetDownloadURLPipeModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { GetDownloadURLPipeModule } from './pipes/storageUrl.pipe'; | ||
import { AngularFireStorage } from './storage'; | ||
|
||
@NgModule({ | ||
exports: [ GetDownloadURLPipeModule ], | ||
providers: [ AngularFireStorage ] | ||
}) | ||
export class AngularFireStorageModule { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters