Files
twenty/server/src/integrations/integrations.module.ts
Félix Malfait b028d9fd2a Add deploy buttons and clean environment variables (#974)
* add render.yaml

* Clean environment variables



---------

Co-authored-by: Charles Bochet <charles@twenty.com>
2023-07-31 14:36:04 -07:00

65 lines
1.8 KiB
TypeScript

import { Module } from '@nestjs/common';
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
import { EnvironmentModule } from './environment/environment.module';
import { EnvironmentService } from './environment/environment.service';
import { FileStorageModule } from './file-storage/file-storage.module';
import { FileStorageModuleOptions } from './file-storage/interfaces';
import { StorageType } from './environment/interfaces/storage.interface';
/**
* FileStorage Module factory
* @param environment
* @returns FileStorageModuleOptions
*/
const fileStorageModuleFactory = async (
environmentService: EnvironmentService,
): Promise<FileStorageModuleOptions> => {
const type = environmentService.getStorageType();
switch (type) {
case StorageType.Local: {
const storagePath = environmentService.getStorageLocalPath();
return {
type: StorageType.Local,
options: {
storagePath: process.cwd() + '/' + storagePath,
},
};
}
case StorageType.S3: {
const bucketName = environmentService.getStorageS3Name();
const region = environmentService.getStorageS3Region();
return {
type: StorageType.S3,
options: {
bucketName: bucketName ?? '',
credentials: fromNodeProviderChain({
clientConfig: { region },
}),
forcePathStyle: true,
region: region ?? '',
},
};
}
default:
throw new Error(`Invalid storage type (${type}), check your .env file`);
}
};
@Module({
imports: [
EnvironmentModule.forRoot({}),
FileStorageModule.forRootAsync({
useFactory: fileStorageModuleFactory,
inject: [EnvironmentService],
}),
],
exports: [],
providers: [],
})
export class IntegrationsModule {}