Skip to content

Commit

Permalink
feat: digital ocean s3 provider improvment
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-rocket committed Mar 27, 2024
1 parent 19e44da commit 416c959
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 59 deletions.
10 changes: 10 additions & 0 deletions packages/contracts/src/file-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,13 @@ export interface ICloudinaryFileStorageProviderConfig {
cloudinary_api_key?: string;
cloudinary_api_secret?: string;
}

export interface IDigitalOceanFileStorageProviderConfig {
digitalocean_access_key_id?: string;
digitalocean_secret_access_key?: string;
digitalocean_default_region?: string;
digitalocean_service_url?: string;
digitalocean_cdn_url?: string;
digitalocean_s3_bucket?: string;
digitalocean_s3_force_path_style?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class DigitalOceanS3Provider extends Provider<DigitalOceanS3Provider> {
digitalocean_secret_access_key: digitalOcean.secretAccessKey,
digitalocean_default_region: digitalOcean.region,
digitalocean_service_url: digitalOcean.serviceUrl,
digitalocean_cdn_url: digitalOcean.cdn,
digitalocean_cdn_url: digitalOcean.cdnUrl,
digitalocean_s3_bucket: digitalOcean.s3.bucket,
digitalocean_s3_force_path_style: digitalOcean.s3.forcePathStyle,
};
Expand Down Expand Up @@ -140,13 +140,9 @@ export class DigitalOceanS3Provider extends Provider<DigitalOceanS3Provider> {
}
}

// Assuming trimAndGetValue() function trims and retrieves the value from settings
const forcePathStyle = trimAndGetValue(settings.digitalocean_s3_force_path_style);

if (forcePathStyle) {
this.config.digitalocean_s3_force_path_style = forcePathStyle === 'true' || forcePathStyle === '1';
} else {
this.config.digitalocean_s3_force_path_style = false;
}
this.config.digitalocean_s3_force_path_style = forcePathStyle === 'true' || forcePathStyle === '1';

if (this._detailedloggingEnabled) {
console.log('setDigitalOceanConfiguration this.config.digitalocean_s3_force_path_style value: ', this.config.digitalocean_s3_force_path_style);
Expand Down
74 changes: 27 additions & 47 deletions packages/core/src/core/file-storage/providers/wasabi-s3.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,74 +157,57 @@ export class WasabiS3Provider extends Provider<WasabiS3Provider> {
const settings = request['tenantSettings'];

if (settings) {
if (this._detailedloggingEnabled)
console.log(`setWasabiConfiguration Tenant Settings value: ${JSON.stringify(settings)}`);
if (this._detailedloggingEnabled) {
console.log(`setWasabiConfiguration Tenant Settings Value: ${JSON.stringify(settings)}`);
}

if (trimAndGetValue(settings.wasabi_aws_access_key_id)) {
this.config.wasabi_aws_access_key_id = trimAndGetValue(settings.wasabi_aws_access_key_id);

if (this._detailedloggingEnabled)
console.log(
`setWasabiConfiguration this.config.wasabi_aws_access_key_id value: ${this.config.wasabi_aws_access_key_id}`
);
if (this._detailedloggingEnabled) {
console.log(`setWasabiConfiguration this.config.wasabi_aws_access_key_id value: ${this.config.wasabi_aws_access_key_id}`);
}
}

if (trimAndGetValue(settings.wasabi_aws_secret_access_key)) {
this.config.wasabi_aws_secret_access_key = trimAndGetValue(
settings.wasabi_aws_secret_access_key
);

if (this._detailedloggingEnabled)
console.log(
`setWasabiConfiguration this.config.wasabi_aws_secret_access_key value: ${this.config.wasabi_aws_secret_access_key}`
);
this.config.wasabi_aws_secret_access_key = trimAndGetValue(settings.wasabi_aws_secret_access_key);

if (this._detailedloggingEnabled) {
console.log(`setWasabiConfiguration this.config.wasabi_aws_secret_access_key value: ${this.config.wasabi_aws_secret_access_key}`);
}
}

if (trimAndGetValue(settings.wasabi_aws_service_url)) {
this.config.wasabi_aws_service_url = addHttpsPrefix(
trimAndGetValue(settings.wasabi_aws_service_url)
);

if (this._detailedloggingEnabled)
console.log(
'setWasabiConfiguration this.config.wasabi_aws_service_url value: ',
this.config.wasabi_aws_service_url
);
this.config.wasabi_aws_service_url = addHttpsPrefix(trimAndGetValue(settings.wasabi_aws_service_url));

if (this._detailedloggingEnabled) {
console.log('setWasabiConfiguration this.config.wasabi_aws_service_url value: ', this.config.wasabi_aws_service_url);
}
}

if (trimAndGetValue(settings.wasabi_aws_default_region)) {
this.config.wasabi_aws_default_region = trimAndGetValue(settings.wasabi_aws_default_region);

if (this._detailedloggingEnabled)
console.log(
'setWasabiConfiguration this.config.wasabi_aws_default_region value: ',
this.config.wasabi_aws_default_region
);
if (this._detailedloggingEnabled) {
console.log('setWasabiConfiguration this.config.wasabi_aws_default_region value: ', this.config.wasabi_aws_default_region);
}
}

if (trimAndGetValue(settings.wasabi_aws_bucket)) {
this.config.wasabi_aws_bucket = trimAndGetValue(settings.wasabi_aws_bucket);

if (this._detailedloggingEnabled)
console.log(
'setWasabiConfiguration this.config.wasabi_aws_bucket value: ',
this.config.wasabi_aws_bucket
);
if (this._detailedloggingEnabled) {
console.log('setWasabiConfiguration this.config.wasabi_aws_bucket value: ', this.config.wasabi_aws_bucket);
}
}

// Assuming trimAndGetValue() function trims and retrieves the value from settings
const forcePathStyle = trimAndGetValue(settings.wasabi_aws_force_path_style);
this.config.wasabi_aws_force_path_style = forcePathStyle === 'true' || forcePathStyle === '1';

if (forcePathStyle) {
this.config.wasabi_aws_force_path_style = forcePathStyle === 'true' || forcePathStyle === '1';
} else {
this.config.wasabi_aws_force_path_style = false;
if (this._detailedloggingEnabled) {
console.log('setWasabiConfiguration this.config.wasabi_aws_force_path_style value: ', this.config.wasabi_aws_force_path_style);
}

if (this._detailedloggingEnabled)
console.log(
'setWasabiConfiguration this.config.wasabi_aws_force_path_style value: ',
this.config.wasabi_aws_force_path_style
);
}
}
} catch (error) {
Expand Down Expand Up @@ -313,10 +296,7 @@ export class WasabiS3Provider extends Provider<WasabiS3Provider> {
if (filename) {
fileName = typeof filename === 'string' ? filename : filename(file, extension);
} else {
fileName = `${prefix}-${moment().unix()}-${parseInt(
'' + Math.random() * 1000,
10
)}.${extension}`;
fileName = `${prefix}-${moment().unix()}-${parseInt('' + Math.random() * 1000, 10)}.${extension}`;
}

// Replace double backslashes with single forward slashes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { RequestContext } from './../../../../core/context';
import { TenantSettingGetCommand } from '../tenant-setting.get.command';
import { TenantSettingService } from './../../tenant-setting.service';
import { WrapSecrets } from './../../../../core/decorators';
import { AwsS3ProviderConfigDTO, CloudinaryProviderConfigDTO, WasabiS3ProviderConfigDTO } from './../../dto';
import {
AwsS3ProviderConfigDTO,
CloudinaryProviderConfigDTO,
DigitalOceanS3ProviderConfigDTO,
WasabiS3ProviderConfigDTO
} from './../../dto';

@CommandHandler(TenantSettingGetCommand)
export class TenantSettingGetHandler
Expand All @@ -13,7 +18,7 @@ export class TenantSettingGetHandler
constructor(
@Inject(forwardRef(() => TenantSettingService))
private readonly _tenantSettingService: TenantSettingService
) {}
) { }

public async execute() {
const tenantId = RequestContext.currentTenantId();
Expand All @@ -27,6 +32,7 @@ export class TenantSettingGetHandler
WrapSecrets(settings, new WasabiS3ProviderConfigDTO()),
WrapSecrets(settings, new AwsS3ProviderConfigDTO()),
WrapSecrets(settings, new CloudinaryProviderConfigDTO()),
WrapSecrets(settings, new DigitalOceanS3ProviderConfigDTO()),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { FileStorageProviderEnum } from "@gauzy/contracts";
import { AwsS3ProviderConfigDTO } from "./aws-s3-provider-config.dto";
import { WasabiS3ProviderConfigDTO } from "./wasabi-s3-provider-config.dto";
import { CloudinaryProviderConfigDTO } from "./cloudinary-provider-config.dto";
import { DigitalOceanS3ProviderConfigDTO } from './digitalocean-s3.provider-config.dto';

/**
* Tenant Setting Save Request DTO validation
*/
export class CreateTenantSettingDTO extends IntersectionType(
WasabiS3ProviderConfigDTO,
IntersectionType(WasabiS3ProviderConfigDTO, DigitalOceanS3ProviderConfigDTO),
IntersectionType(AwsS3ProviderConfigDTO, CloudinaryProviderConfigDTO)
) {

/**
* FileStorage Provider Configuration
*/
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/tenant/tenant-setting/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './create-tenant-setting.dto';
export * from './aws-s3-provider-config.dto';
export * from './wasabi-s3-provider-config.dto';
export * from './cloudinary-provider-config.dto';
export * from './digitalocean-s3.provider-config.dto';
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ITenantSetting, PermissionsEnum } from '@gauzy/contracts';
import {
Body,
Controller,
Expand All @@ -12,6 +11,7 @@ import {
} from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { CommandBus } from '@nestjs/cqrs';
import { ITenantSetting, PermissionsEnum } from '@gauzy/contracts';
import { CrudController } from '../../core/crud';
import { Permissions } from './../../shared/decorators';
import { PermissionGuard, TenantPermissionGuard } from './../../shared/guards';
Expand Down

0 comments on commit 416c959

Please sign in to comment.