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

FileUploadS3Adapter.getEndPoint   A

Complexity

Conditions 2

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 19
c 0
b 0
f 0
rs 9.55
cc 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