@react-native-firebase/storage 20.4.0 → 20.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- 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,10 @@
|
|
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
|
+
|
6
10
|
## [20.4.0](https://github.com/invertase/react-native-firebase/compare/v20.3.0...v20.4.0) (2024-08-13)
|
7
11
|
|
8
12
|
### Features
|
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
|
}
|