@clairejs/server 3.16.18 → 3.17.0

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,12 @@
1
1
  ## Change Log
2
2
 
3
- #### 3.16.18:
3
+ #### 3.17.0:
4
4
 
5
+ - add putFile in AbstractFileService
6
+
7
+ #### 3.16.19:
8
+
9
+ - fix dependency
5
10
  - allow file service to resolve empty uri to empty string
6
11
  - fix job param type from any[] to any
7
12
  - fix CRUD order
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { FileOperation } from "../common/FileOperation";
2
3
  import { GetUploadUrlResponseBody } from "../controllers/dto/upload";
3
4
  export declare abstract class AbstractFileService {
@@ -13,5 +14,6 @@ export declare abstract class AbstractFileService {
13
14
  toURI: string;
14
15
  }[]): Promise<void>;
15
16
  abstract removeObject(uris: string[]): Promise<void>;
17
+ abstract putFile(uri: string, data: Buffer, headers?: Record<string, string>): Promise<void>;
16
18
  getUploadUrlForTempUri(temporaryUri: string): Promise<GetUploadUrlResponseBody>;
17
19
  }
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { FileOperation } from "../../common/FileOperation";
2
3
  import { AbstractFileService } from "../AbstractFileService";
3
4
  export declare class LocalFileService extends AbstractFileService {
@@ -6,6 +7,7 @@ export declare class LocalFileService extends AbstractFileService {
6
7
  getFileSize(objectKeys: string[]): Promise<number[]>;
7
8
  getAccessUrls(uris: (string | undefined)[], _isPublic: boolean): Promise<string[]>;
8
9
  getPresignedUrl(operation: FileOperation, uris: string[]): Promise<string[]>;
10
+ putFile(uri: string, data: Buffer, headers?: Record<string, string>): Promise<void>;
9
11
  moveObject(uris: {
10
12
  fromURI: string;
11
13
  toURI: string;
@@ -23,6 +23,15 @@ export class LocalFileService extends AbstractFileService {
23
23
  }
24
24
  return uris.map((uri) => `${this.fileServerUrl}/?objectKey="/${uri}"`);
25
25
  }
26
+ async putFile(uri, data, headers) {
27
+ const [url] = await this.getPresignedUrl(FileOperation.PUT, [uri]);
28
+ await axios({
29
+ method: 'PUT',
30
+ url,
31
+ data,
32
+ headers,
33
+ });
34
+ }
26
35
  async moveObject(uris) {
27
36
  await Promise.all(uris.map((uri) => axios.post(`${this.fileServerUrl}/`, {
28
37
  from: uri.fromURI,
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { AbstractLogger } from "@clairejs/core";
2
3
  import { FileOperation } from "../../common/FileOperation";
3
4
  import { AbstractFileService } from "../AbstractFileService";
@@ -13,8 +14,9 @@ export declare class S3FileService extends AbstractFileService {
13
14
  protected readonly config: S3FileServiceConfig;
14
15
  protected readonly logger: AbstractLogger;
15
16
  private readonly s3Client;
16
- private readonly cloudfrontSigner;
17
+ private readonly cloudfrontSigner?;
17
18
  constructor(config: S3FileServiceConfig, logger: AbstractLogger);
19
+ putFile(uri: string, data: Buffer, headers?: Record<string, string>): Promise<void>;
18
20
  getFileSize(objectKeys: string[]): Promise<number[]>;
19
21
  getAccessUrls(uris: (string | undefined)[], isPublic: boolean): Promise<string[]>;
20
22
  getPresignedUrl(operation: FileOperation, uris: string[]): Promise<string[]>;
@@ -24,7 +24,17 @@ let S3FileService = class S3FileService extends AbstractFileService {
24
24
  signatureVersion: "v4",
25
25
  region: this.config.S3_BUCKET_REGION,
26
26
  });
27
- this.cloudfrontSigner = new aws.CloudFront.Signer(this.config.CLOUD_FRONT_PUBLIC_KEY_ID, this.config.CLOUD_FRONT_PRIVATE_KEY);
27
+ if (this.config.CLOUD_FRONT_PUBLIC_DOMAIN && this.config.CLOUD_FRONT_PRIVATE_KEY && this.config.CLOUD_FRONT_PUBLIC_KEY_ID) {
28
+ this.cloudfrontSigner = new aws.CloudFront.Signer(this.config.CLOUD_FRONT_PUBLIC_KEY_ID, this.config.CLOUD_FRONT_PRIVATE_KEY);
29
+ }
30
+ }
31
+ async putFile(uri, data, headers) {
32
+ await this.s3Client.putObject({
33
+ Key: uri,
34
+ Bucket: this.config.S3_BUCKET_NAME,
35
+ Body: data,
36
+ Metadata: headers,
37
+ }).promise();
28
38
  }
29
39
  async getFileSize(objectKeys) {
30
40
  return await Promise.all(objectKeys.map((uri) => this.getSingleFileSize(uri)));
@@ -51,10 +61,17 @@ let S3FileService = class S3FileService extends AbstractFileService {
51
61
  .then((res) => res.ContentLength);
52
62
  return size || 0;
53
63
  }
54
- getSinglePresignedUrl(_operation, objectKey) {
55
- return this.cloudfrontSigner.getSignedUrl({
56
- url: `${this.config.CLOUD_FRONT_PUBLIC_DOMAIN}/${objectKey}`,
57
- expires: Date.now() + this.config.PRESIGNED_URL_EXPIRATION_S * 1000,
64
+ getSinglePresignedUrl(operation, objectKey) {
65
+ if (this.cloudfrontSigner) {
66
+ return this.cloudfrontSigner.getSignedUrl({
67
+ url: `${this.config.CLOUD_FRONT_PUBLIC_DOMAIN}/${objectKey}`,
68
+ expires: Date.now() + this.config.PRESIGNED_URL_EXPIRATION_S * 1000,
69
+ });
70
+ }
71
+ return this.s3Client.getSignedUrl(operation, {
72
+ Bucket: this.config.S3_BUCKET_NAME,
73
+ Key: objectKey,
74
+ Expires: this.config.PRESIGNED_URL_EXPIRATION_S
58
75
  });
59
76
  }
60
77
  async copySingleObject(fromObjectKey, toObjectKey) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clairejs/server",
3
- "version": "3.16.18",
3
+ "version": "3.17.0",
4
4
  "description": "Claire server NodeJs framework written in Typescript.",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
@@ -28,12 +28,13 @@
28
28
  "randomstring": "^1.2.2",
29
29
  "redlock": "^5.0.0-beta.2",
30
30
  "reflect-metadata": "^0.1.13",
31
- "ws": "^7.5.5"
31
+ "ws": "^7.5.5",
32
+ "ioredis": "^5.2.0",
33
+ "axios": "^0.21.4"
32
34
  },
33
35
  "peerDependencies": {
34
36
  "@clairejs/core": "^3.6.1",
35
- "@clairejs/orm": "^3.11.0",
36
- "ioredis": "^5.2.0"
37
+ "@clairejs/orm": "^3.11.0"
37
38
  },
38
39
  "devDependencies": {
39
40
  "@types/cookie-parser": "^1.4.3",
@@ -47,7 +48,6 @@
47
48
  "@types/randomstring": "^1.1.8",
48
49
  "@types/uuid": "^9.0.0",
49
50
  "@types/ws": "^7.4.0",
50
- "axios": "^0.21.1",
51
51
  "mocha": "^10.2.0",
52
52
  "ts-node": "^10.9.1",
53
53
  "typescript": "^5.0.4",