1
- import { ListResult , Reference , SettableMetadata , StringFormat , UploadMetadata } from './interfaces' ;
2
1
import { AngularFireUploadTask , createUploadTask } from './task' ;
3
2
import { from , Observable , of } from 'rxjs' ;
4
3
import { ɵAngularFireSchedulers } from '@angular/fire' ;
5
4
import { observeOn , switchMap } from 'rxjs/operators' ;
5
+ import { ListResult ,
6
+ StorageReference ,
7
+ SettableMetadata ,
8
+ StringFormat ,
9
+ UploadMetadata ,
10
+ UploadResult ,
11
+ StorageService ,
12
+ } from './interfaces' ;
13
+ import {
14
+ getDownloadURL ,
15
+ getMetadata ,
16
+ ref ,
17
+ deleteObject ,
18
+ updateMetadata ,
19
+ uploadBytesResumable as put ,
20
+ uploadString as putString ,
21
+ listAll ,
22
+ } from 'firebase/storage' ;
6
23
7
24
export interface AngularFireStorageReference {
8
25
getDownloadURL ( ) : Observable < any > ;
@@ -11,7 +28,9 @@ export interface AngularFireStorageReference {
11
28
child ( path : string ) : any ;
12
29
updateMetadata ( meta : SettableMetadata ) : Observable < any > ;
13
30
put ( data : any , metadata ?: UploadMetadata | undefined ) : AngularFireUploadTask ;
14
- putString ( data : string , format ?: string | undefined , metadata ?: UploadMetadata | undefined ) : AngularFireUploadTask ;
31
+ // MARK: Breaking change
32
+ // previous: putString(data: string, format?: string | undefined, metadata?: UploadMetadata | undefined): AngularFireUploadTask;
33
+ putString ( data : string , format ?: string | undefined , metadata ?: UploadMetadata | undefined ) : Observable < UploadResult > ;
15
34
listAll ( ) : Observable < ListResult > ;
16
35
}
17
36
@@ -20,32 +39,35 @@ export interface AngularFireStorageReference {
20
39
* creates observable methods from promise based methods.
21
40
*/
22
41
export function createStorageRef (
23
- ref : Reference ,
42
+ storage : StorageService ,
43
+ storageRef : StorageReference ,
24
44
schedulers : ɵAngularFireSchedulers ,
25
45
keepUnstableUntilFirst : < T > ( obs$ : Observable < T > ) => Observable < T >
26
46
) : AngularFireStorageReference {
27
47
return {
28
48
getDownloadURL : ( ) => of ( undefined ) . pipe (
29
49
observeOn ( schedulers . outsideAngular ) ,
30
- switchMap ( ( ) => ref . getDownloadURL ( ) ) ,
50
+ switchMap ( ( ) => getDownloadURL ( storageRef ) ) ,
31
51
keepUnstableUntilFirst
32
52
) ,
33
53
getMetadata : ( ) => of ( undefined ) . pipe (
34
54
observeOn ( schedulers . outsideAngular ) ,
35
- switchMap ( ( ) => ref . getMetadata ( ) ) ,
55
+ switchMap ( ( ) => getMetadata ( storageRef ) ) ,
36
56
keepUnstableUntilFirst
37
57
) ,
38
- delete : ( ) => from ( ref . delete ( ) ) ,
39
- child : ( path : string ) => createStorageRef ( ref . child ( path ) , schedulers , keepUnstableUntilFirst ) ,
40
- updateMetadata : ( meta : SettableMetadata ) => from ( ref . updateMetadata ( meta ) ) ,
58
+ delete : ( ) => from ( deleteObject ( storageRef ) ) ,
59
+ child : ( path : string ) => createStorageRef ( storage , ref ( storage , path ) , schedulers , keepUnstableUntilFirst ) ,
60
+ updateMetadata : ( meta : SettableMetadata ) => from ( updateMetadata ( storageRef , meta ) ) ,
41
61
put : ( data : any , metadata ?: UploadMetadata ) => {
42
- const task = ref . put ( data , metadata ) ;
62
+ const task = put ( storageRef , data , metadata ) ;
43
63
return createUploadTask ( task ) ;
44
64
} ,
45
- putString : ( data : string , format ?: StringFormat , metadata ?: UploadMetadata ) => {
46
- const task = ref . putString ( data , format , metadata ) ;
47
- return createUploadTask ( task ) ;
65
+ // MARK: Breaking change
66
+ // previous: AngularFireStorageReference.putString(data: string, format?: string, metadata?: UploadMetadata): AngularFireUploadTask
67
+ putString : ( data : string , format ?: StringFormat , metadata ?: UploadMetadata ) : Observable < UploadResult > => {
68
+ const task = putString ( storageRef , data , format , metadata ) ;
69
+ return from ( task ) ;
48
70
} ,
49
- listAll : ( ) => from ( ref . listAll ( ) )
71
+ listAll : ( ) => from ( listAll ( storageRef ) )
50
72
} ;
51
73
}
0 commit comments