Skip to content

Commit d07525e

Browse files
committed
Add Base Path Config Options'
This allows control of the directory in which to place the files instead of at the root of the storage bucket.
1 parent e355b9b commit d07525e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/firebase.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import { join, posix, sep } from 'path';
77
interface FirebaseStorageConfig {
88
serviceAccount: string | ServiceAccount;
99
bucketName: string;
10-
basePath: string;
10+
basePath?: string;
1111
uploadOptions?: UploadOptions;
1212
}
1313

1414
export default class FirebaseStorageAdapter extends BaseAdapter {
1515
bucket: Bucket;
1616
uploadOptions?: UploadOptions;
17+
basePath: string;
1718

1819
constructor(config: FirebaseStorageConfig) {
1920
super();
@@ -23,6 +24,7 @@ export default class FirebaseStorageAdapter extends BaseAdapter {
2324
});
2425
this.bucket = app.storage().bucket();
2526
this.uploadOptions = config.uploadOptions;
27+
this.basePath = config.basePath ?? '';
2628
}
2729

2830
async exists(fileName: string, _targetDir: string): Promise<boolean> {
@@ -31,8 +33,8 @@ export default class FirebaseStorageAdapter extends BaseAdapter {
3133
return filesExists[0];
3234
}
3335

34-
async save(image: Image, targetDir?: string | undefined): Promise<string> {
35-
const targetDirectory = targetDir ?? this.getTargetDir();
36+
const targetDirectory = this.getTargetDir(this.basePath);
37+
// the typings are wrong here, getUniqueFileName returns a promise of a string
3638
const pathToSave = await this.getUniqueFileName(image, targetDirectory);
3739
return this.bucket
3840
.upload(image.path, {

0 commit comments

Comments
 (0)