Passed
Pull Request — master (#56)
by
unknown
03:10 queued 01:29
created

api/src/Infrastructure/Adapter/FileUploadS3Adapter.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 35
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 28
mnd 1
bc 1
fnc 1
dl 0
loc 35
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A FileUploadS3Adapter.getEndPoint 0 19 2
1
import { Injectable } from '@nestjs/common';
2
import { ConfigService } from '@nestjs/config';
3
import { IFileUpload } from 'src/Application/IFileUpload';
4
import { S3Factory } from '../Ingestion/S3Factory';
5
6
@Injectable()
7
export class FileUploadS3Adapter implements IFileUpload {
8
  constructor(
9
    private readonly configService: ConfigService,
10
    private readonly s3Factory: S3Factory
11
  ) {}
12
13
  public getEndPoint(filePath: string): Promise<string> {
14
    const bucket = this.configService.get<string>('STORAGE_BUCKET');
15
16
    const s3Api = this.s3Factory.create();
17
18
    const s3Params = {
19
      Bucket: bucket,
20
      Key: filePath,
21
      Expires: 600,
22
      ContentType: 'application/octet-stream'
23
    };
24
25
    return new Promise<string>((resolve, reject) => {
26
      s3Api.getSignedUrl('putObject', s3Params, (err, data) => {
27
        if (err) {
28
          reject(err);
29
        }
30
        resolve(data);
31
      });
32
    });
33
  }
34
}
35