Skip to content

Commit ba03e52

Browse files
committed
Add Domain Name Option For Return Url
This allows you to pass a custom url such as one linked to cloud functions that will be used to serve images instead of the storage bucket url.
1 parent cf965b4 commit ba03e52

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/firebase.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ interface FirebaseStorageConfig {
99
bucketName: string;
1010
basePath?: string;
1111
uploadOptions?: UploadOptions;
12+
domainName?: string;
1213
}
1314

1415
export default class FirebaseStorageAdapter extends BaseAdapter {
1516
bucket: Bucket;
1617
uploadOptions?: UploadOptions;
1718
basePath: string;
19+
domainName?: string;
1820

1921
constructor(config: FirebaseStorageConfig) {
2022
super();
@@ -25,6 +27,7 @@ export default class FirebaseStorageAdapter extends BaseAdapter {
2527
this.bucket = app.storage().bucket();
2628
this.uploadOptions = config.uploadOptions;
2729
this.basePath = config.basePath ?? '';
30+
this.domainName = config.domainName;
2831
}
2932

3033
async exists(fileName: string, _targetDir: string): Promise<boolean> {
@@ -47,6 +50,16 @@ export default class FirebaseStorageAdapter extends BaseAdapter {
4750
...(this.uploadOptions ? this.uploadOptions : defaultUploadOptions),
4851
destination: pathToSave.split(sep).join(posix.sep),
4952
};
53+
const data = await this.bucket.upload(image.path, uploadOptions);
54+
if (this.domainName) {
55+
const domainName = new URL(this.domainName);
56+
const downloadPath = new URL(data[1].name, domainName).toString();
57+
console.log({ downloadPath });
58+
return downloadPath;
59+
}
60+
const link = data[1].mediaLink;
61+
console.log({ link });
62+
return link;
5063
}
5164

5265
serve() {

0 commit comments

Comments
 (0)