Skip to content

Commit 57d1a86

Browse files
committed
Fix fallout
1 parent 2ee0f18 commit 57d1a86

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

packages/storage/src/implementation/location.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,10 @@ export class Location {
5151
return '/b/' + encode(this.bucket) + '/o';
5252
}
5353

54-
static makeFromBucketSpec(
55-
bucketString: string,
56-
customHost?: string
57-
): Location {
54+
static makeFromBucketSpec(bucketString: string, host: string): Location {
5855
let bucketLocation;
5956
try {
60-
bucketLocation = Location.makeFromUrl(bucketString, customHost);
57+
bucketLocation = Location.makeFromUrl(bucketString, host);
6158
} catch (e) {
6259
// Not valid URL, use as-is. This lets you put bare bucket names in
6360
// config.
@@ -70,7 +67,7 @@ export class Location {
7067
}
7168
}
7269

73-
static makeFromUrl(url: string, customHost?: string): Location {
70+
static makeFromUrl(url: string, host: string): Location {
7471
let location: Location | null = null;
7572
const bucketDomain = '([A-Za-z0-9.\\-_]+)';
7673

@@ -87,10 +84,7 @@ export class Location {
8784
loc.path_ = decodeURIComponent(loc.path);
8885
}
8986
const version = 'v[A-Za-z0-9_]+';
90-
const firebaseStorageHost = (customHost ?? DEFAULT_HOST).replace(
91-
/[.]/g,
92-
'\\.'
93-
);
87+
const firebaseStorageHost = host.replace(/[.]/g, '\\.');
9488
const firebaseStoragePath = '(/([^?#]*).*)?$';
9589
const firebaseStorageRegExp = new RegExp(
9690
`^https?://${firebaseStorageHost}/${version}/b/${bucketDomain}/o${firebaseStoragePath}`,
@@ -99,7 +93,9 @@ export class Location {
9993
const firebaseStorageIndices = { bucket: 1, path: 3 };
10094

10195
const cloudStorageHost =
102-
customHost ?? '(?:storage.googleapis.com|storage.cloud.google.com)';
96+
host === DEFAULT_HOST
97+
? '(?:storage.googleapis.com|storage.cloud.google.com)'
98+
: host;
10399
const cloudStoragePath = '([^?#]*)';
104100
const cloudStorageRegExp = new RegExp(
105101
`^https?://${cloudStorageHost}/${bucketDomain}/${cloudStoragePath}`,

packages/storage/src/service.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import {
4343
import { validateNumber } from './implementation/type';
4444

4545
export function isUrl(path?: string): boolean {
46-
console.log(path);
4746
return /^[A-Za-z]+:\/\//.test(path as string);
4847
}
4948

@@ -123,14 +122,14 @@ export function ref(
123122
}
124123

125124
function extractBucket(
126-
config?: FirebaseOptions,
127-
customHost?: string
125+
host: string,
126+
config?: FirebaseOptions
128127
): Location | null {
129128
const bucketString = config?.[CONFIG_STORAGE_BUCKET_KEY];
130129
if (bucketString == null) {
131130
return null;
132131
}
133-
return Location.makeFromBucketSpec(bucketString, customHost);
132+
return Location.makeFromBucketSpec(bucketString, host);
134133
}
135134

136135
export function useStorageEmulator(
@@ -169,9 +168,9 @@ export class StorageService implements _FirebaseService {
169168
this._maxUploadRetryTime = DEFAULT_MAX_UPLOAD_RETRY_TIME;
170169
this._requests = new Set();
171170
if (_url != null) {
172-
this._bucket = Location.makeFromBucketSpec(_url);
171+
this._bucket = Location.makeFromBucketSpec(_url, this._host);
173172
} else {
174-
this._bucket = extractBucket(this.app.options);
173+
this._bucket = extractBucket(this._host, this.app.options);
175174
}
176175
}
177176

@@ -188,7 +187,7 @@ export class StorageService implements _FirebaseService {
188187
if (this._url != null) {
189188
this._bucket = Location.makeFromBucketSpec(this._url, origin);
190189
} else {
191-
this._bucket = extractBucket(this.app.options, origin);
190+
this._bucket = extractBucket(origin, this.app.options);
192191
}
193192
}
194193

0 commit comments

Comments
 (0)