From b020118a6afee9df9fe51dff25a62343b0f572ad Mon Sep 17 00:00:00 2001 From: Montassar Ghanmy Date: Thu, 28 Sep 2023 17:04:41 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=A3=20S3=20home=20directory=20for=20fi?= =?UTF-8?q?les?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../node/src/core/platform/services/storage/index.ts | 6 ++++++ .../node/src/core/platform/services/storage/provider.ts | 1 + tdrive/backend/node/src/services/files/services/index.ts | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tdrive/backend/node/src/core/platform/services/storage/index.ts b/tdrive/backend/node/src/core/platform/services/storage/index.ts index b3829e1d..be980b60 100644 --- a/tdrive/backend/node/src/core/platform/services/storage/index.ts +++ b/tdrive/backend/node/src/core/platform/services/storage/index.ts @@ -23,6 +23,7 @@ export default class StorageService extends TdriveService implements private encryptionOptions: EncryptionConfiguration; private algorithm = "aes-256-cbc"; + private homeDir = "tdrive"; api(): StorageAPI { return this; @@ -37,6 +38,7 @@ export default class StorageService extends TdriveService implements const type = this.getConnectorType(); if (type === "S3") { logger.info("Using 'S3' connector for storage."); + this.homeDir = this.configuration.get("S3.bucket"); return new S3ConnectorService({ bucket: this.configuration.get("S3.bucket"), region: this.configuration.get("S3.region"), @@ -56,6 +58,10 @@ export default class StorageService extends TdriveService implements return new LocalConnectorService(this.configuration.get("local")); } + getHomeDir(): string { + return this.homeDir; + } + async write(path: string, stream: Stream, options?: WriteOptions): Promise { try { if (options?.encryptionKey) { diff --git a/tdrive/backend/node/src/core/platform/services/storage/provider.ts b/tdrive/backend/node/src/core/platform/services/storage/provider.ts index 8a9c1d48..2112405f 100644 --- a/tdrive/backend/node/src/core/platform/services/storage/provider.ts +++ b/tdrive/backend/node/src/core/platform/services/storage/provider.ts @@ -54,4 +54,5 @@ export interface StorageConnectorAPI { export default interface StorageAPI extends TdriveServiceProvider, StorageConnectorAPI { getConnector(): StorageConnectorAPI; getConnectorType(): string; + getHomeDir(): string; } diff --git a/tdrive/backend/node/src/services/files/services/index.ts b/tdrive/backend/node/src/services/files/services/index.ts index 3081211f..56729d89 100644 --- a/tdrive/backend/node/src/services/files/services/index.ts +++ b/tdrive/backend/node/src/services/files/services/index.ts @@ -311,5 +311,7 @@ export class FileServiceImpl { } function getFilePath(entity: File): string { - return `/tdrive/files/${entity.company_id}/${entity.user_id || "anonymous"}/${entity.id}`; + return `/${gr.platformServices.storage.getHomeDir()}/files/${entity.company_id}/${ + entity.user_id || "anonymous" + }/${entity.id}`; }