Skip to content

Commit

Permalink
🪣 S3 home directory for files
Browse files Browse the repository at this point in the history
  • Loading branch information
MontaGhanmy authored Sep 28, 2023
1 parent a6fa424 commit b020118
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class StorageService extends TdriveService<StorageAPI> implements

private encryptionOptions: EncryptionConfiguration;
private algorithm = "aes-256-cbc";
private homeDir = "tdrive";

api(): StorageAPI {
return this;
Expand All @@ -37,6 +38,7 @@ export default class StorageService extends TdriveService<StorageAPI> implements
const type = this.getConnectorType();
if (type === "S3") {
logger.info("Using 'S3' connector for storage.");
this.homeDir = this.configuration.get<string>("S3.bucket");
return new S3ConnectorService({
bucket: this.configuration.get<string>("S3.bucket"),
region: this.configuration.get<string>("S3.region"),
Expand All @@ -56,6 +58,10 @@ export default class StorageService extends TdriveService<StorageAPI> implements
return new LocalConnectorService(this.configuration.get<LocalConfiguration>("local"));
}

getHomeDir(): string {
return this.homeDir;
}

async write(path: string, stream: Stream, options?: WriteOptions): Promise<WriteMetadata> {
try {
if (options?.encryptionKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ export interface StorageConnectorAPI {
export default interface StorageAPI extends TdriveServiceProvider, StorageConnectorAPI {
getConnector(): StorageConnectorAPI;
getConnectorType(): string;
getHomeDir(): string;
}
4 changes: 3 additions & 1 deletion tdrive/backend/node/src/services/files/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}

0 comments on commit b020118

Please sign in to comment.