@@ -10,13 +10,16 @@ import { WidgetTypeEnum } from '../../../enums/widget-type.enum.js';
1010import { Messages } from '../../../exceptions/text/messages.js' ;
1111import { Encryptor } from '../../../helpers/encryption/encryptor.js' ;
1212import { isConnectionTypeAgent } from '../../../helpers/is-connection-entity-agent.js' ;
13- import { S3FileUrlResponseDs , S3GetFileUrlDs } from '../application/data-structures/s3-operation.ds.js' ;
14- import { S3WidgetParams } from '../application/data-structures/s3-widget-params.ds.js' ;
13+ import { BucketFileUrlResponseDs , GetBucketFileUrlDs } from '../application/data-structures/s3-operation.ds.js' ;
14+ import { BucketWidgetParams } from '../application/data-structures/s3-widget-params.ds.js' ;
1515import { S3HelperService } from '../s3-helper.service.js' ;
1616import { IGetS3FileUrl } from './s3-use-cases.interface.js' ;
1717
1818@Injectable ( )
19- export class GetS3FileUrlUseCase extends AbstractUseCase < S3GetFileUrlDs , S3FileUrlResponseDs > implements IGetS3FileUrl {
19+ export class GetS3FileUrlUseCase
20+ extends AbstractUseCase < GetBucketFileUrlDs , BucketFileUrlResponseDs >
21+ implements IGetS3FileUrl
22+ {
2023 constructor (
2124 @Inject ( BaseType . GLOBAL_DB_CONTEXT )
2225 protected _dbContext : IGlobalDatabaseContext ,
@@ -25,7 +28,7 @@ export class GetS3FileUrlUseCase extends AbstractUseCase<S3GetFileUrlDs, S3FileU
2528 super ( ) ;
2629 }
2730
28- protected async implementation ( inputData : S3GetFileUrlDs ) : Promise < S3FileUrlResponseDs > {
31+ protected async implementation ( inputData : GetBucketFileUrlDs ) : Promise < BucketFileUrlResponseDs > {
2932 const { connectionId, tableName, fieldName, rowPrimaryKey, userId, masterPwd } = inputData ;
3033
3134 const user = await this . _dbContext . userRepository . findOneUserByIdWithCompany ( userId ) ;
@@ -45,7 +48,7 @@ export class GetS3FileUrlUseCase extends AbstractUseCase<S3GetFileUrlDs, S3FileU
4548 throw new HttpException ( { message : 'S3 widget not configured for this field' } , HttpStatus . BAD_REQUEST ) ;
4649 }
4750
48- const params : S3WidgetParams =
51+ const params : BucketWidgetParams =
4952 typeof widget . widget_params === 'string' ? JSON5 . parse ( widget . widget_params ) : widget . widget_params ;
5053
5154 // Fetch the row from database to get the actual file key
@@ -78,17 +81,17 @@ export class GetS3FileUrlUseCase extends AbstractUseCase<S3GetFileUrlDs, S3FileU
7881 }
7982
8083 const accessKeySecret = await this . _dbContext . userSecretRepository . findSecretBySlugAndCompanyId (
81- params . aws_access_key_id_secret_name ,
84+ params . access_key_id_secret_name ,
8285 user . company . id ,
8386 ) ;
8487
8588 const secretKeySecret = await this . _dbContext . userSecretRepository . findSecretBySlugAndCompanyId (
86- params . aws_secret_access_key_secret_name ,
89+ params . secret_access_key_secret_name ,
8790 user . company . id ,
8891 ) ;
8992
9093 if ( ! accessKeySecret || ! secretKeySecret ) {
91- throw new HttpException ( { message : 'AWS credentials secrets not found' } , HttpStatus . NOT_FOUND ) ;
94+ throw new HttpException ( { message : 'Bucket credentials secrets not found' } , HttpStatus . NOT_FOUND ) ;
9295 }
9396
9497 let accessKeyId = Encryptor . decryptData ( accessKeySecret . encryptedValue ) ;
@@ -101,7 +104,13 @@ export class GetS3FileUrlUseCase extends AbstractUseCase<S3GetFileUrlDs, S3FileU
101104 secretAccessKey = Encryptor . decryptDataMasterPwd ( secretAccessKey , masterPwd ) ;
102105 }
103106
104- const client = this . s3Helper . createS3Client ( accessKeyId , secretAccessKey , params . region || 'us-east-1' ) ;
107+ const client = this . s3Helper . createS3Client ( {
108+ accessKeyId,
109+ secretAccessKey,
110+ provider : params . provider ,
111+ region : params . region ,
112+ accountId : params . account_id ,
113+ } ) ;
105114
106115 const expiresIn = 3600 ;
107116 const url = await this . s3Helper . getSignedGetUrl ( client , params . bucket , fileKey , expiresIn ) ;
0 commit comments