diff --git a/packages/core/src/storages/meta-storage.ts b/packages/core/src/storages/meta-storage.ts index 28a1e4b1..8d212230 100644 --- a/packages/core/src/storages/meta-storage.ts +++ b/packages/core/src/storages/meta-storage.ts @@ -24,8 +24,8 @@ export interface MetaStorageOptions { * Stores upload metadata */ export class MetaStorage { - prefix = '.'; - suffix = '.'; + prefix = ''; + suffix = ''; constructor(config?: MetaStorageOptions) { this.prefix = config?.prefix || ''; @@ -69,6 +69,14 @@ export class MetaStorage { async list(prefix = ''): Promise { return { items: [] }; } + + getMetaName(id: string): string { + return this.prefix + id + this.suffix; + } + + getIdFromMetaName(name: string): string { + return name.slice(this.prefix.length, -this.suffix.length); + } } /** diff --git a/packages/gcs/src/gcs-meta-storage.ts b/packages/gcs/src/gcs-meta-storage.ts index 5db7a239..03356894 100644 --- a/packages/gcs/src/gcs-meta-storage.ts +++ b/packages/gcs/src/gcs-meta-storage.ts @@ -21,8 +21,6 @@ export class GCSMetaStorage extends MetaStorage { this.authClient = new GoogleAuth(config); } - getMetaName = (id: string): string => this.prefix + id + this.suffix; - /** * Returns metafile url * @param id - upload id @@ -31,13 +29,6 @@ export class GCSMetaStorage extends MetaStorage { return `${this.storageBaseURI}/${this.getMetaName(id)}`; } - /** - * Returns upload id from metafile url - * @internal - */ - getIdFromPath = (metaFilePath: string): string => - metaFilePath.slice(`${this.prefix}`.length, -this.suffix.length); - async save(id: string, file: T): Promise { //TODO: use JSON API multipart POST? await this.authClient.request({ @@ -65,7 +56,7 @@ export class GCSMetaStorage extends MetaStorage { async list(prefix: string): Promise { const baseURL = this.storageBaseURI; const url = '/'; - const options = { baseURL, url, params: { prefix: encodeURIComponent(prefix) } }; + const options = { baseURL, url, params: { prefix: encodeURIComponent(this.prefix + prefix) } }; const { data } = await this.authClient.request<{ items: { name: string; timeCreated: string; metadata?: T }[]; }>(options); @@ -73,7 +64,7 @@ export class GCSMetaStorage extends MetaStorage { items: data.items .filter(item => item.name.endsWith(this.suffix)) .map(({ name, timeCreated }) => ({ - id: this.getIdFromPath(name), + id: this.getIdFromMetaName(name), createdAt: new Date(timeCreated) })) }; diff --git a/packages/s3/src/s3-meta-storage.ts b/packages/s3/src/s3-meta-storage.ts index fb127454..51649659 100644 --- a/packages/s3/src/s3-meta-storage.ts +++ b/packages/s3/src/s3-meta-storage.ts @@ -28,10 +28,6 @@ export class S3MetaStorage extends MetaStorage { this.client = new S3Client(config); } - getMetaName(id: string): string { - return this.prefix + id + this.suffix; - } - async get(id: string): Promise { const params = { Bucket: this.bucket, Key: this.getMetaName(id) }; const { Metadata } = await this.client.send(new HeadObjectCommand(params)); @@ -60,7 +56,7 @@ export class S3MetaStorage extends MetaStorage { async list(prefix: string): Promise { const params = { Bucket: this.bucket, - Prefix: prefix + Prefix: this.prefix + prefix }; const items = []; const response = await this.client.send(new ListObjectsV2Command(params)); @@ -70,7 +66,7 @@ export class S3MetaStorage extends MetaStorage { LastModified && Key.endsWith(this.suffix) && items.push({ - id: Key?.slice(this.prefix.length, -this.suffix.length), + id: this.getIdFromMetaName(Key), createdAt: LastModified }); }