@react-native-firebase/storage 20.3.0 → 20.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +10 -0
- package/__tests__/storage.test.ts +120 -1
- package/android/src/main/java/io/invertase/firebase/storage/ReactNativeFirebaseStorageModule.java +2 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -25
- package/lib/modular/index.d.ts +261 -0
- package/{modular → lib/modular}/index.js +14 -1
- package/lib/version.js +1 -1
- package/lib/web/RNFBStorageModule.js +33 -21
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,16 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [20.5.0](https://github.com/invertase/react-native-firebase/compare/v20.4.0...v20.5.0) (2024-09-11)
|
7
|
+
|
8
|
+
**Note:** Version bump only for package @react-native-firebase/storage
|
9
|
+
|
10
|
+
## [20.4.0](https://github.com/invertase/react-native-firebase/compare/v20.3.0...v20.4.0) (2024-08-13)
|
11
|
+
|
12
|
+
### Features
|
13
|
+
|
14
|
+
- **firestore:** support for second database ([#7949](https://github.com/invertase/react-native-firebase/issues/7949)) ([eec08a0](https://github.com/invertase/react-native-firebase/commit/eec08a06f41dd96d13778fbed2afcaaac238fca4))
|
15
|
+
|
6
16
|
## [20.3.0](https://github.com/invertase/react-native-firebase/compare/v20.2.1...v20.3.0) (2024-07-19)
|
7
17
|
|
8
18
|
**Note:** Version bump only for package @react-native-firebase/storage
|
@@ -1,6 +1,31 @@
|
|
1
1
|
import { describe, expect, it } from '@jest/globals';
|
2
2
|
|
3
|
-
import storage, {
|
3
|
+
import storage, {
|
4
|
+
firebase,
|
5
|
+
getStorage,
|
6
|
+
connectStorageEmulator,
|
7
|
+
ref,
|
8
|
+
deleteObject,
|
9
|
+
getBlob,
|
10
|
+
getBytes,
|
11
|
+
getDownloadURL,
|
12
|
+
getMetadata,
|
13
|
+
getStream,
|
14
|
+
list,
|
15
|
+
listAll,
|
16
|
+
updateMetadata,
|
17
|
+
uploadBytes,
|
18
|
+
uploadBytesResumable,
|
19
|
+
uploadString,
|
20
|
+
refFromURL,
|
21
|
+
setMaxOperationRetryTime,
|
22
|
+
setMaxUploadRetryTime,
|
23
|
+
putFile,
|
24
|
+
writeToFile,
|
25
|
+
toString,
|
26
|
+
child,
|
27
|
+
setMaxDownloadRetryTime,
|
28
|
+
} from '../lib';
|
4
29
|
|
5
30
|
describe('Storage', function () {
|
6
31
|
describe('namespace', function () {
|
@@ -45,4 +70,98 @@ describe('Storage', function () {
|
|
45
70
|
expect(bar).toEqual(['10.0.2.2', 9000]);
|
46
71
|
});
|
47
72
|
});
|
73
|
+
|
74
|
+
describe('modular', function () {
|
75
|
+
it('`getStorage` function is properly exposed to end user', function () {
|
76
|
+
expect(getStorage).toBeDefined();
|
77
|
+
});
|
78
|
+
|
79
|
+
it('`connectStorageEmulator` function is properly exposed to end user', function () {
|
80
|
+
expect(connectStorageEmulator).toBeDefined();
|
81
|
+
});
|
82
|
+
|
83
|
+
it('`ref` function is properly exposed to end user', function () {
|
84
|
+
expect(ref).toBeDefined();
|
85
|
+
});
|
86
|
+
|
87
|
+
it('`deleteObject` function is properly exposed to end user', function () {
|
88
|
+
expect(deleteObject).toBeDefined();
|
89
|
+
});
|
90
|
+
|
91
|
+
it('`getBlob` function is properly exposed to end user', function () {
|
92
|
+
expect(getBlob).toBeDefined();
|
93
|
+
});
|
94
|
+
|
95
|
+
it('`getBytes` function is properly exposed to end user', function () {
|
96
|
+
expect(getBytes).toBeDefined();
|
97
|
+
});
|
98
|
+
|
99
|
+
it('`getDownloadURL` function is properly exposed to end user', function () {
|
100
|
+
expect(getDownloadURL).toBeDefined();
|
101
|
+
});
|
102
|
+
|
103
|
+
it('`getMetadata` function is properly exposed to end user', function () {
|
104
|
+
expect(getMetadata).toBeDefined();
|
105
|
+
});
|
106
|
+
|
107
|
+
it('`getStream` function is properly exposed to end user', function () {
|
108
|
+
expect(getStream).toBeDefined();
|
109
|
+
});
|
110
|
+
|
111
|
+
it('`list` function is properly exposed to end user', function () {
|
112
|
+
expect(list).toBeDefined();
|
113
|
+
});
|
114
|
+
|
115
|
+
it('`listAll` function is properly exposed to end user', function () {
|
116
|
+
expect(listAll).toBeDefined();
|
117
|
+
});
|
118
|
+
|
119
|
+
it('`updateMetadata` function is properly exposed to end user', function () {
|
120
|
+
expect(updateMetadata).toBeDefined();
|
121
|
+
});
|
122
|
+
|
123
|
+
it('`uploadBytes` function is properly exposed to end user', function () {
|
124
|
+
expect(uploadBytes).toBeDefined();
|
125
|
+
});
|
126
|
+
|
127
|
+
it('`uploadBytesResumable` function is properly exposed to end user', function () {
|
128
|
+
expect(uploadBytesResumable).toBeDefined();
|
129
|
+
});
|
130
|
+
|
131
|
+
it('`uploadString` function is properly exposed to end user', function () {
|
132
|
+
expect(uploadString).toBeDefined();
|
133
|
+
});
|
134
|
+
|
135
|
+
it('`refFromURL` function is properly exposed to end user', function () {
|
136
|
+
expect(refFromURL).toBeDefined();
|
137
|
+
});
|
138
|
+
|
139
|
+
it('`setMaxOperationRetryTime` function is properly exposed to end user', function () {
|
140
|
+
expect(setMaxOperationRetryTime).toBeDefined();
|
141
|
+
});
|
142
|
+
|
143
|
+
it('`setMaxUploadRetryTime` function is properly exposed to end user', function () {
|
144
|
+
expect(setMaxUploadRetryTime).toBeDefined();
|
145
|
+
});
|
146
|
+
|
147
|
+
it('`putFile` function is properly exposed to end user', function () {
|
148
|
+
expect(putFile).toBeDefined();
|
149
|
+
});
|
150
|
+
|
151
|
+
it('`writeToFile` function is properly exposed to end user', function () {
|
152
|
+
expect(writeToFile).toBeDefined();
|
153
|
+
});
|
154
|
+
|
155
|
+
it('`toString` function is properly exposed to end user', function () {
|
156
|
+
expect(toString).toBeDefined();
|
157
|
+
});
|
158
|
+
|
159
|
+
it('`child` function is properly exposed to end user', function () {
|
160
|
+
expect(child).toBeDefined();
|
161
|
+
});
|
162
|
+
|
163
|
+
it('`setMaxDownloadRetryTime` function is properly exposed to end user', function () {
|
164
|
+
expect(setMaxDownloadRetryTime).toBeDefined();
|
165
|
+
});
|
166
|
+
});
|
48
167
|
});
|
package/android/src/main/java/io/invertase/firebase/storage/ReactNativeFirebaseStorageModule.java
CHANGED
@@ -281,7 +281,8 @@ public class ReactNativeFirebaseStorageModule extends ReactNativeFirebaseModule
|
|
281
281
|
* @link https://firebase.google.com/docs/reference/js/firebase.storage.Storage#useEmulator
|
282
282
|
*/
|
283
283
|
@ReactMethod
|
284
|
-
public void useEmulator(
|
284
|
+
public void useEmulator(
|
285
|
+
String appName, String host, int port, String bucketUrl, Promise promise) {
|
285
286
|
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
286
287
|
|
287
288
|
FirebaseStorage firebaseStorage = FirebaseStorage.getInstance(firebaseApp, bucketUrl);
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
@@ -28,31 +28,6 @@ import { getGsUrlParts, getHttpUrlParts, handleStorageEvent } from './utils';
|
|
28
28
|
import version from './version';
|
29
29
|
import fallBackModule from './web/RNFBStorageModule';
|
30
30
|
|
31
|
-
export {
|
32
|
-
getStorage,
|
33
|
-
connectStorageEmulator,
|
34
|
-
ref,
|
35
|
-
deleteObject,
|
36
|
-
getBlob,
|
37
|
-
getBytes,
|
38
|
-
getDownloadURL,
|
39
|
-
getMetadata,
|
40
|
-
getStream,
|
41
|
-
list,
|
42
|
-
listAll,
|
43
|
-
updateMetadata,
|
44
|
-
putFile,
|
45
|
-
writeToFile,
|
46
|
-
toString,
|
47
|
-
child,
|
48
|
-
setMaxDownloadRetryTime,
|
49
|
-
setMaxOperationRetryTime,
|
50
|
-
setMaxUploadRetryTime,
|
51
|
-
refFromURL,
|
52
|
-
uploadString,
|
53
|
-
uploadBytesResumable,
|
54
|
-
} from '../modular/index';
|
55
|
-
|
56
31
|
const namespace = 'storage';
|
57
32
|
const nativeEvents = ['storage_event'];
|
58
33
|
const nativeModuleName = 'RNFBStorageModule';
|
@@ -233,4 +208,6 @@ export default createModuleNamespace({
|
|
233
208
|
// firebase.storage().X(...);
|
234
209
|
export const firebase = getFirebaseRoot();
|
235
210
|
|
211
|
+
export * from './modular';
|
212
|
+
|
236
213
|
setReactNativeModule(nativeModuleName, fallBackModule);
|
@@ -0,0 +1,261 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this library except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*
|
16
|
+
*/
|
17
|
+
|
18
|
+
import { FirebaseApp } from '@firebase/app-types';
|
19
|
+
import { FirebaseStorageTypes } from '../index';
|
20
|
+
|
21
|
+
import Storage = FirebaseStorageTypes.Module;
|
22
|
+
import Reference = FirebaseStorageTypes.Reference;
|
23
|
+
import FullMetadata = FirebaseStorageTypes.FullMetadata;
|
24
|
+
import ListResult = FirebaseStorageTypes.ListResult;
|
25
|
+
import TaskResult = FirebaseStorageTypes.TaskResult;
|
26
|
+
import Task = FirebaseStorageTypes.Task;
|
27
|
+
import ListOptions = FirebaseStorageTypes.ListOptions;
|
28
|
+
import SettableMetadata = FirebaseStorageTypes.SettableMetadata;
|
29
|
+
import EmulatorMockTokenOptions = FirebaseStorageTypes.EmulatorMockTokenOptions;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Returns the existing default {@link Storage} instance that is associated with the
|
33
|
+
* default {@link FirebaseApp}. The default storage bucket is used. If no instance exists, initializes a new
|
34
|
+
* instance with default settings.
|
35
|
+
*
|
36
|
+
* @returns The {@link Storage} instance of the provided app.
|
37
|
+
*/
|
38
|
+
export declare function getStorage(): Storage;
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Returns the existing default {@link Storage} instance that is associated with the
|
42
|
+
* provided {@link FirebaseApp}. The default storage bucket is used. If no instance exists, initializes a new
|
43
|
+
* instance with default settings.
|
44
|
+
*
|
45
|
+
* @param app - The {@link FirebaseApp} instance that the returned {@link Storage}
|
46
|
+
* instance is associated with.
|
47
|
+
* @returns The {@link Firestore} instance of the provided app.
|
48
|
+
*/
|
49
|
+
export declare function getStorage(app?: FirebaseApp): Storage;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Returns the existing default {@link Storage} instance that is associated with the
|
53
|
+
* provided {@link FirebaseApp}. If no instance exists, initializes a new
|
54
|
+
* instance with default settings.
|
55
|
+
*
|
56
|
+
* @param app - The {@link FirebaseApp} instance that the returned {@link Storage}
|
57
|
+
* instance is associated with. If `null` the default app is used.
|
58
|
+
* @param bucketUrl - The gs:// url to the Firebase Storage Bucket. If `null` the default bucket is used.
|
59
|
+
* @returns The {@link Firestore} instance of the provided app.
|
60
|
+
*/
|
61
|
+
export declare function getStorage(app?: FirebaseApp, bucketUrl?: string): Storage;
|
62
|
+
|
63
|
+
export function getStorage(app?: FirebaseApp, bucketUrl?: string): Storage;
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Connects a {@link Storage} instance to the Firebase Storage emulator.
|
67
|
+
* @param storage - A reference to the `Storage` instance.
|
68
|
+
* @param host - Emulator host, e.g., 'localhost'.
|
69
|
+
* @param port - Emulator port, e.g., 9199.
|
70
|
+
* @param options - Optional. {@link EmulatorMockTokenOptions} instance.
|
71
|
+
*/
|
72
|
+
export function connectStorageEmulator(
|
73
|
+
storage: Storage,
|
74
|
+
host: string,
|
75
|
+
port: number,
|
76
|
+
options?: EmulatorMockTokenOptions,
|
77
|
+
): void;
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Creates a {@link Reference} from a given path or URL.
|
81
|
+
* @param storage - The {@link Storage} instance.
|
82
|
+
* @param path - Optional. A string pointing to a location within the storage bucket.
|
83
|
+
* @returns A new {@link Reference}.
|
84
|
+
*/
|
85
|
+
export function ref(storage: Storage, path?: string): Reference;
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Deletes the object at the given reference's location.
|
89
|
+
* @param storageRef - The {@link Reference} to the object to delete.
|
90
|
+
* @returns A promise that resolves when the delete is complete.
|
91
|
+
*/
|
92
|
+
export function deleteObject(storageRef: Reference): Promise<void>;
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Retrieves the blob at the given reference's location. Throws an error if the object is not found.
|
96
|
+
* @param storageRef - The {@link Reference} to the object.
|
97
|
+
* @returns A promise resolving to the Blob.
|
98
|
+
*/
|
99
|
+
export function getBlob(storageRef: Reference): Promise<Blob>;
|
100
|
+
|
101
|
+
/**
|
102
|
+
* Retrieves bytes (up to the specified max size) from an object at the given reference's location.
|
103
|
+
* Throws an error if the object is not found or if the size exceeds the maximum allowed.
|
104
|
+
* @param storageRef - The {@link Reference} to the object.
|
105
|
+
* @param maxDownloadSizeBytes - Maximum size in bytes to retrieve.
|
106
|
+
* @returns A promise resolving to an ArrayBuffer.
|
107
|
+
*/
|
108
|
+
export function getBytes(storageRef: Reference, maxDownloadSizeBytes: number): Promise<ArrayBuffer>;
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Retrieves a long-lived download URL for the object at the given reference's location.
|
112
|
+
* @param storageRef - The {@link Reference} to the object.
|
113
|
+
* @returns A promise resolving to the URL string.
|
114
|
+
*/
|
115
|
+
export function getDownloadURL(storageRef: Reference): Promise<string>;
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Retrieves metadata for the object at the given reference's location.
|
119
|
+
* @param storageRef - The {@link Reference} to the object.
|
120
|
+
* @returns A promise resolving to the object's {@link FullMetadata}.
|
121
|
+
*/
|
122
|
+
export function getMetadata(storageRef: Reference): Promise<FullMetadata>;
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Retrieves a readable stream for the object at the given reference's location. This API is only available in Node.js.
|
126
|
+
* @param storageRef - The {@link Reference} to the object.
|
127
|
+
* @param maxDownloadSizeBytes - Maximum size in bytes to retrieve.
|
128
|
+
* @returns A NodeJS ReadableStream.
|
129
|
+
*/
|
130
|
+
export function getStream(
|
131
|
+
storageRef: Reference,
|
132
|
+
maxDownloadSizeBytes: number,
|
133
|
+
): NodeJS.ReadableStream;
|
134
|
+
|
135
|
+
/**
|
136
|
+
* Lists items and prefixes under the given reference.
|
137
|
+
* @param storageRef - The {@link Reference} under which to list items.
|
138
|
+
* @param options - Optional. Configuration for listing.
|
139
|
+
* @returns A promise resolving to a {@link ListResult}.
|
140
|
+
*/
|
141
|
+
export function list(storageRef: Reference, options?: ListOptions): Promise<ListResult>;
|
142
|
+
|
143
|
+
/**
|
144
|
+
* Lists all items and prefixes under the given reference.
|
145
|
+
* @param storageRef - The {@link Reference} under which to list items.
|
146
|
+
* @returns A promise resolving to a {@link ListResult}.
|
147
|
+
*/
|
148
|
+
export function listAll(storageRef: Reference): Promise<ListResult>;
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Updates metadata for the object at the given reference.
|
152
|
+
* @param storageRef - The {@link Reference} to the object.
|
153
|
+
* @param metadata - The metadata to update.
|
154
|
+
* @returns A promise resolving to the updated {@link FullMetadata}.
|
155
|
+
*/
|
156
|
+
export function updateMetadata(
|
157
|
+
storageRef: Reference,
|
158
|
+
metadata: SettableMetadata,
|
159
|
+
): Promise<FullMetadata>;
|
160
|
+
|
161
|
+
/**
|
162
|
+
* Uploads data to the object's location at the given reference. The upload is not resumable.
|
163
|
+
* @param storageRef - The {@link Reference} where the data should be uploaded.
|
164
|
+
* @param data - The data to upload.
|
165
|
+
* @param metadata - Optional. Metadata to associate with the uploaded object.
|
166
|
+
* @returns A promise resolving to a {@link TaskResult}.
|
167
|
+
*/
|
168
|
+
export function uploadBytes(
|
169
|
+
storageRef: Reference,
|
170
|
+
data: Blob | Uint8Array | ArrayBuffer,
|
171
|
+
metadata?: SettableMetadata,
|
172
|
+
): Promise<TaskResult>;
|
173
|
+
|
174
|
+
/**
|
175
|
+
* Initiates a resumable upload session for the data to the object's location at the given reference.
|
176
|
+
* @param storageRef - The {@link Reference} where the data should be uploaded.
|
177
|
+
* @param data - The data to upload.
|
178
|
+
* @param metadata - Optional. Metadata to associate with the uploaded object.
|
179
|
+
* @returns A {@link Task} associated with the upload process.
|
180
|
+
*/
|
181
|
+
export function uploadBytesResumable(
|
182
|
+
storageRef: Reference,
|
183
|
+
data: Blob | Uint8Array | ArrayBuffer,
|
184
|
+
metadata?: SettableMetadata,
|
185
|
+
): Task;
|
186
|
+
|
187
|
+
/**
|
188
|
+
* Uploads a string to the object's location at the given reference. The string format must be specified.
|
189
|
+
* @param storageRef - The {@link Reference} where the string should be uploaded.
|
190
|
+
* @param data - The string data to upload.
|
191
|
+
* @param format - Optional. The format of the string ('raw', 'base64', 'base64url', 'data_url').
|
192
|
+
* @param metadata - Optional. Metadata to associate with the uploaded object.
|
193
|
+
* @returns A {@link Task} associated with the upload process.
|
194
|
+
*/
|
195
|
+
export function uploadString(
|
196
|
+
storageRef: Reference,
|
197
|
+
data: string,
|
198
|
+
format?: 'raw' | 'base64' | 'base64url' | 'data_url',
|
199
|
+
metadata?: SettableMetadata,
|
200
|
+
): Task;
|
201
|
+
|
202
|
+
/**
|
203
|
+
* Creates a {@link Reference} from a storage bucket URL.
|
204
|
+
* @param storage - The {@link Storage} instance.
|
205
|
+
* @param url - A URL pointing to a file or location in a storage bucket.
|
206
|
+
* @returns A {@link Reference} pointing to the specified URL.
|
207
|
+
*/
|
208
|
+
export function refFromURL(storage: Storage, url: string): Reference;
|
209
|
+
|
210
|
+
/**
|
211
|
+
* Sets the maximum time in milliseconds to retry operations other than upload and download if a failure occurs.
|
212
|
+
* @param storage - The {@link Storage} instance.
|
213
|
+
* @param time - The new maximum operation retry time in milliseconds.
|
214
|
+
*/
|
215
|
+
export function setMaxOperationRetryTime(storage: Storage, time: number): Promise<void>;
|
216
|
+
|
217
|
+
/**
|
218
|
+
* Sets the maximum time in milliseconds to retry upload operations if a failure occurs.
|
219
|
+
* @param storage - The {@link Storage} instance.
|
220
|
+
* @param time - The new maximum upload retry time in milliseconds.
|
221
|
+
*/
|
222
|
+
export function setMaxUploadRetryTime(storage: Storage, time: number): Promise<void>;
|
223
|
+
|
224
|
+
/**
|
225
|
+
* Puts a file from a local disk onto the storage bucket at the given reference.
|
226
|
+
* @param storageRef - The {@link Reference} where the file should be uploaded.
|
227
|
+
* @param filePath - The local file path of the file to upload.
|
228
|
+
* @param metadata - Optional. Metadata to associate with the uploaded file.
|
229
|
+
* @returns A {@link Task} associated with the upload process.
|
230
|
+
*/
|
231
|
+
export function putFile(storageRef: Reference, filePath: string, metadata?: SettableMetadata): Task;
|
232
|
+
|
233
|
+
/**
|
234
|
+
* Downloads a file to the specified local file path on the device.
|
235
|
+
* @param storageRef - The {@link Reference} from which the file should be downloaded.
|
236
|
+
* @param filePath - The local file path where the file should be written.
|
237
|
+
* @returns A {@link Task} associated with the download process.
|
238
|
+
*/
|
239
|
+
export function writeToFile(storageRef: Reference, filePath: string): Task;
|
240
|
+
|
241
|
+
/**
|
242
|
+
* Returns a gs:// URL for the object at the given reference.
|
243
|
+
* @param storageRef - The {@link Reference} to the object.
|
244
|
+
* @returns The URL as a string.
|
245
|
+
*/
|
246
|
+
export function toString(storageRef: Reference): string;
|
247
|
+
|
248
|
+
/**
|
249
|
+
* Returns a reference to a relative path from the given reference.
|
250
|
+
* @param storageRef - The {@link Reference} as the base.
|
251
|
+
* @param path - The relative path from the base reference.
|
252
|
+
* @returns A new {@link Reference}.
|
253
|
+
*/
|
254
|
+
export function child(storageRef: Reference, path: string): Reference;
|
255
|
+
|
256
|
+
/**
|
257
|
+
* Sets the maximum time in milliseconds to retry download operations if a failure occurs.
|
258
|
+
* @param storage - The {@link Storage} instance.
|
259
|
+
* @param time - The new maximum download retry time in milliseconds.
|
260
|
+
*/
|
261
|
+
export function setMaxDownloadRetryTime(storage: Storage, time: number): Promise<void>;
|
@@ -14,6 +14,19 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*
|
16
16
|
*/
|
17
|
+
/**
|
18
|
+
* @typedef {import('..').FirebaseStorageTypes} FirebaseStorageTypes
|
19
|
+
* @typedef {import('..').FirebaseStorageTypes.Module} Storage
|
20
|
+
* @typedef {import('..').FirebaseStorageTypes.Reference} Reference
|
21
|
+
* @typedef {import('..').FirebaseStorageTypes.FullMetadata} FullMetadata
|
22
|
+
* @typedef {import('..').FirebaseStorageTypes.ListResult} ListResult
|
23
|
+
* @typedef {import('..').FirebaseStorageTypes.TaskResult} TaskResult
|
24
|
+
* @typedef {import('..').FirebaseStorageTypes.Task} Task
|
25
|
+
* @typedef {import('..').FirebaseStorageTypes.ListOptions} ListOptions
|
26
|
+
* @typedef {import('..').FirebaseStorageTypes.SettableMetadata} SettableMetadata
|
27
|
+
* @typedef {import('..').FirebaseStorageTypes.EmulatorMockTokenOptions} EmulatorMockTokenOptions
|
28
|
+
* @typedef {import('@firebase/app').FirebaseApp} FirebaseApp
|
29
|
+
*/
|
17
30
|
|
18
31
|
import { firebase } from '..';
|
19
32
|
|
@@ -56,7 +69,7 @@ export function connectStorageEmulator(storage, host, port, options) {
|
|
56
69
|
* @param storage - Storage instance.
|
57
70
|
* @param path An optional string pointing to a location on the storage bucket. If no path
|
58
71
|
* is provided, the returned reference will be the bucket root path. Optional.
|
59
|
-
* @returns {
|
72
|
+
* @returns {Reference}
|
60
73
|
*/
|
61
74
|
export function ref(storage, path) {
|
62
75
|
return storage.ref(path);
|
package/lib/version.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
// Generated by genversion.
|
2
|
-
module.exports = '20.
|
2
|
+
module.exports = '20.5.0';
|
@@ -120,32 +120,48 @@ const storageInstances = {};
|
|
120
120
|
const tasks = {};
|
121
121
|
|
122
122
|
function getBucketFromUrl(url) {
|
123
|
-
|
124
|
-
|
125
|
-
|
123
|
+
// Check if the URL starts with "gs://"
|
124
|
+
if (url.startsWith('gs://')) {
|
125
|
+
// Return the bucket name by extracting everything up to the first slash after "gs://"
|
126
|
+
// and removing the "gs://" prefix
|
127
|
+
return url.substring(5).split('/')[0];
|
128
|
+
} else {
|
129
|
+
// Assume the URL is a path format, strip the leading slash if it exists and extract the bucket name
|
130
|
+
const strippedUrl = url.startsWith('/') ? url.substring(1) : url;
|
131
|
+
// Extract the bucket from the path, assuming it ends at the first slash after the domain
|
132
|
+
return strippedUrl.split('/')[0];
|
133
|
+
}
|
126
134
|
}
|
127
135
|
|
128
136
|
function getCachedAppInstance(appName) {
|
129
137
|
return (appInstances[appName] ??= getApp(appName));
|
130
138
|
}
|
131
139
|
|
140
|
+
function emulatorKey(appName, url) {
|
141
|
+
const bucket = getBucketFromUrl(url);
|
142
|
+
return `${appName}|${bucket}`;
|
143
|
+
}
|
144
|
+
|
132
145
|
// Returns a cached Storage instance.
|
133
146
|
function getCachedStorageInstance(appName, url) {
|
134
147
|
let instance;
|
148
|
+
const bucket = url ? getBucketFromUrl(url) : getCachedAppInstance(appName).options.storageBucket;
|
149
|
+
|
135
150
|
if (!url) {
|
136
151
|
instance = getCachedStorageInstance(
|
137
152
|
appName,
|
138
153
|
getCachedAppInstance(appName).options.storageBucket,
|
139
154
|
);
|
140
155
|
} else {
|
141
|
-
const bucket = getBucketFromUrl(url);
|
142
156
|
instance = storageInstances[`${appName}|${bucket}`] ??= getStorage(
|
143
157
|
getCachedAppInstance(appName),
|
144
158
|
bucket,
|
145
159
|
);
|
146
160
|
}
|
147
|
-
|
148
|
-
|
161
|
+
|
162
|
+
const key = emulatorKey(appName, bucket);
|
163
|
+
if (emulatorForApp[key]) {
|
164
|
+
connectStorageEmulator(instance, emulatorForApp[key].host, emulatorForApp[key].port);
|
149
165
|
}
|
150
166
|
return instance;
|
151
167
|
}
|
@@ -296,11 +312,12 @@ export default {
|
|
296
312
|
* @param {number} port - The emulator port.
|
297
313
|
* @return {Promise<void>}
|
298
314
|
*/
|
299
|
-
useEmulator(appName, host, port) {
|
315
|
+
useEmulator(appName, host, port, url) {
|
300
316
|
return guard(async () => {
|
301
|
-
const instance = getCachedStorageInstance(appName);
|
317
|
+
const instance = getCachedStorageInstance(appName, url);
|
302
318
|
connectStorageEmulator(instance, host, port);
|
303
|
-
|
319
|
+
const key = emulatorKey(appName, url);
|
320
|
+
emulatorForApp[key] = { host, port };
|
304
321
|
});
|
305
322
|
},
|
306
323
|
|
@@ -324,28 +341,23 @@ export default {
|
|
324
341
|
putString(appName, url, string, format, metadata = {}, taskId) {
|
325
342
|
return guard(async () => {
|
326
343
|
const ref = getReferenceFromUrl(appName, url);
|
344
|
+
let decodedString = null;
|
327
345
|
|
328
|
-
|
329
|
-
|
346
|
+
// This is always either base64 or base64url
|
330
347
|
switch (format) {
|
331
348
|
case 'base64':
|
332
|
-
|
349
|
+
decodedString = Base64.atob(string);
|
333
350
|
break;
|
334
351
|
case 'base64url':
|
335
|
-
|
352
|
+
decodedString = Base64.atob(string.replace(/_/g, '/').replace(/-/g, '+'));
|
336
353
|
break;
|
337
354
|
}
|
338
355
|
|
339
|
-
const
|
356
|
+
const encoder = new TextEncoder();
|
340
357
|
|
341
|
-
|
342
|
-
for (let i = 0; i < base64String.length; i++) {
|
343
|
-
byteArray[i] = base64String.charCodeAt(i);
|
344
|
-
}
|
345
|
-
}
|
358
|
+
const arrayBuffer = encoder.encode(decodedString).buffer;
|
346
359
|
|
347
|
-
|
348
|
-
const task = uploadBytesResumable(ref, byteArray, {
|
360
|
+
const task = uploadBytesResumable(ref, arrayBuffer, {
|
349
361
|
...makeSettableMetadata(metadata),
|
350
362
|
md5Hash: metadata.md5Hash,
|
351
363
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@react-native-firebase/storage",
|
3
|
-
"version": "20.
|
3
|
+
"version": "20.5.0",
|
4
4
|
"author": "Invertase <oss@invertase.io> (http://invertase.io)",
|
5
5
|
"description": "React Native Firebase - React Native Firebase provides native integration with Cloud Storage, providing support to upload and download files directly from your device and from your Firebase Cloud Storage bucket.",
|
6
6
|
"main": "lib/index.js",
|
@@ -29,10 +29,10 @@
|
|
29
29
|
"download"
|
30
30
|
],
|
31
31
|
"peerDependencies": {
|
32
|
-
"@react-native-firebase/app": "20.
|
32
|
+
"@react-native-firebase/app": "20.5.0"
|
33
33
|
},
|
34
34
|
"publishConfig": {
|
35
35
|
"access": "public"
|
36
36
|
},
|
37
|
-
"gitHead": "
|
37
|
+
"gitHead": "daf2bc9086c14bbb0e1b02a4d4274b7060263eb1"
|
38
38
|
}
|