Skip to content

Commit 467806c

Browse files
committed
Fix fallout
1 parent 27557ba commit 467806c

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
@@ -42,7 +42,6 @@ import {
4242
import { validateNumber } from './implementation/type';
4343

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

@@ -122,14 +121,14 @@ export function ref(
122121
}
123122

124123
function extractBucket(
125-
config?: FirebaseOptions,
126-
customHost?: string
124+
host: string,
125+
config?: FirebaseOptions
127126
): Location | null {
128127
const bucketString = config?.[CONFIG_STORAGE_BUCKET_KEY];
129128
if (bucketString == null) {
130129
return null;
131130
}
132-
return Location.makeFromBucketSpec(bucketString, customHost);
131+
return Location.makeFromBucketSpec(bucketString, host);
133132
}
134133

135134
export function useStorageEmulator(
@@ -168,9 +167,9 @@ export class StorageService implements _FirebaseService {
168167
this._maxUploadRetryTime = DEFAULT_MAX_UPLOAD_RETRY_TIME;
169168
this._requests = new Set();
170169
if (_url != null) {
171-
this._bucket = Location.makeFromBucketSpec(_url);
170+
this._bucket = Location.makeFromBucketSpec(_url, this._host);
172171
} else {
173-
this._bucket = extractBucket(this.app.options);
172+
this._bucket = extractBucket(this._host, this.app.options);
174173
}
175174
}
176175

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

0 commit comments

Comments
 (0)