@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
|
@@ -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
|
-
|
|
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,
|
|
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:
|
|
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
|
|
87
|
+
return `${this.config.CLOUD_FRONT_PUBLIC_DOMAIN}/${objectKey}`;
|
|
88
88
|
}
|
|
89
|
-
return this.
|
|
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
|