@clairejs/server 3.16.6 → 3.16.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  ## Change Log
2
2
 
3
- #### 3.16.6:
3
+ #### 3.16.8:
4
4
 
5
+ - refactor aws s3 file service
5
6
  - do not throw when fail to clean up in ModelRepository
6
7
  - fix file controllers
7
8
  - fix socket authentication, fix http error code in response
@@ -7,7 +7,7 @@ export interface S3FileServiceConfig {
7
7
  PRESIGNED_URL_EXPIRATION_S: number;
8
8
  CLOUD_FRONT_PUBLIC_DOMAIN: string;
9
9
  CLOUD_FRONT_PUBLIC_KEY_ID: string;
10
- CLOUD_FRONT_PRIVATE_KEY_BASE64: string;
10
+ CLOUD_FRONT_PRIVATE_KEY: string;
11
11
  }
12
12
  export declare class S3FileService extends AbstractFileService {
13
13
  protected readonly config: S3FileServiceConfig;
@@ -9,6 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  import { AbstractLogger, LogContext } from "@clairejs/core";
11
11
  import aws from "aws-sdk";
12
+ import { FileOperation } from "../../common/FileOperation";
12
13
  import { AbstractFileService } from "../AbstractFileService";
13
14
  let S3FileService = class S3FileService extends AbstractFileService {
14
15
  config;
@@ -23,7 +24,7 @@ let S3FileService = class S3FileService extends AbstractFileService {
23
24
  signatureVersion: "v4",
24
25
  region: this.config.S3_BUCKET_REGION,
25
26
  });
26
- this.cloudfrontSigner = new aws.CloudFront.Signer(this.config.CLOUD_FRONT_PUBLIC_KEY_ID, Buffer.from(this.config.CLOUD_FRONT_PRIVATE_KEY_BASE64, "base64").toString());
27
+ this.cloudfrontSigner = new aws.CloudFront.Signer(this.config.CLOUD_FRONT_PUBLIC_KEY_ID, this.config.CLOUD_FRONT_PRIVATE_KEY);
27
28
  }
28
29
  async getFileSize(objectKeys) {
29
30
  return await Promise.all(objectKeys.map((uri) => this.getSingleFileSize(uri)));
@@ -53,7 +54,7 @@ let S3FileService = class S3FileService extends AbstractFileService {
53
54
  getSinglePresignedUrl(_operation, objectKey) {
54
55
  return this.cloudfrontSigner.getSignedUrl({
55
56
  url: `${this.config.CLOUD_FRONT_PUBLIC_DOMAIN}/${objectKey}`,
56
- expires: Date.now() + 3600000,
57
+ expires: this.config.PRESIGNED_URL_EXPIRATION_S * 1000
57
58
  });
58
59
  }
59
60
  async copySingleObject(fromObjectKey, toObjectKey) {
@@ -82,14 +83,10 @@ let S3FileService = class S3FileService extends AbstractFileService {
82
83
  }
83
84
  }
84
85
  getSingleAccessUrl(objectKey, isPublic) {
85
- const url = `${this.config.CLOUD_FRONT_PUBLIC_DOMAIN}/${objectKey}`;
86
86
  if (isPublic) {
87
- return url;
87
+ return `${this.config.CLOUD_FRONT_PUBLIC_DOMAIN}/${objectKey}`;
88
88
  }
89
- return this.cloudfrontSigner.getSignedUrl({
90
- url,
91
- expires: Date.now() + this.config.PRESIGNED_URL_EXPIRATION_S * 1000,
92
- });
89
+ return this.getSinglePresignedUrl(FileOperation.GET, objectKey);
93
90
  }
94
91
  async removeSingleObject(objectKey) {
95
92
  await this.s3Client
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clairejs/server",
3
- "version": "3.16.6",
3
+ "version": "3.16.8",
4
4
  "description": "Claire server NodeJs framework written in Typescript.",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",