clhq-s3-module 1.1.0-alpha.130 → 1.1.0-alpha.131

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.
@@ -26,23 +26,34 @@ let AwsService = AwsService_1 = class AwsService {
26
26
  this.configService = configService;
27
27
  this.awsUserKey = this.configService.get('CLIPPY_AWS_USER_KEY');
28
28
  this.awsUserPassword = this.configService.get('CLIPPY_AWS_USER_SECRET');
29
- this.region = this.configService.get('CLIPPY_AWS_DEFAULT_REGION');
29
+ this.region =
30
+ this.configService.get('CLIPPY_AWS_DEFAULT_REGION') ||
31
+ 'us-east-1';
30
32
  this.bucket = this.configService.get('CLIPPY_S3_BUCKET');
31
33
  if (!this.bucket) {
32
34
  this.logger.error('CLIPPY_S3_BUCKET is not set in environment variables');
33
35
  throw new Error('CLIPPY_S3_BUCKET environment variable is required');
34
36
  }
35
37
  this.logger.debug(`S3 Bucket configured: ${this.bucket}`);
38
+ this.logger.debug(`S3 Region configured: ${this.region}`);
36
39
  }
37
40
  getS3Client() {
38
- const region = this.configService.get('CLIPPY_AWS_DEFAULT_REGION');
39
- const client = new client_s3_1.S3Client({
40
- region: region,
41
+ const s3Endpoint = this.configService.get('S3_ENDPOINT');
42
+ const clientConfig = {
41
43
  credentials: {
42
44
  accessKeyId: this.awsUserKey,
43
45
  secretAccessKey: this.awsUserPassword,
44
46
  },
45
- });
47
+ };
48
+ if (s3Endpoint) {
49
+ clientConfig.endpoint = s3Endpoint;
50
+ clientConfig.forcePathStyle = true;
51
+ clientConfig.region = 'us-east-1';
52
+ }
53
+ else {
54
+ clientConfig.region = this.region || 'us-east-1';
55
+ }
56
+ const client = new client_s3_1.S3Client(clientConfig);
46
57
  return client;
47
58
  }
48
59
  async uploadPublicFile(dataBuffer, filename, mimetype) {
@@ -62,17 +62,29 @@ let S3Service = S3Service_1 = class S3Service {
62
62
  this.configService = configService;
63
63
  this.awsUserKey = this.configService.get('CLIPPY_AWS_USER_KEY');
64
64
  this.awsUserPassword = this.configService.get('CLIPPY_AWS_USER_SECRET');
65
- this.region = this.configService.get('CLIPPY_AWS_DEFAULT_REGION');
65
+ this.region =
66
+ this.configService.get('CLIPPY_AWS_DEFAULT_REGION') ||
67
+ 'us-east-1';
66
68
  this.bucket = this.configService.get('CLIPPY_S3_BUCKET');
69
+ this.logger.debug(`S3 Service initialized with region: ${this.region}`);
67
70
  }
68
71
  getS3Client() {
69
- const client = new S3.S3Client({
70
- region: this.region,
72
+ const s3Endpoint = this.configService.get('S3_ENDPOINT');
73
+ const clientConfig = {
71
74
  credentials: {
72
75
  accessKeyId: this.awsUserKey,
73
76
  secretAccessKey: this.awsUserPassword,
74
77
  },
75
- });
78
+ };
79
+ if (s3Endpoint) {
80
+ clientConfig.endpoint = s3Endpoint;
81
+ clientConfig.forcePathStyle = true;
82
+ clientConfig.region = 'us-east-1';
83
+ }
84
+ else {
85
+ clientConfig.region = this.region || 'us-east-1';
86
+ }
87
+ const client = new S3.S3Client(clientConfig);
76
88
  return client;
77
89
  }
78
90
  getBucketDetails() {
@@ -122,20 +134,23 @@ let S3Service = S3Service_1 = class S3Service {
122
134
  this.logger.debug(progress);
123
135
  });
124
136
  const response = await parallelUploadS3.done();
125
- const newParams = {
126
- ...params,
127
- ACL: 'public-read',
128
- };
129
- try {
130
- const aclUpdate = new S3.PutObjectAclCommand(newParams);
131
- const putAclResposne = await client.send(aclUpdate);
132
- this.logger.debug('putAclResponse');
133
- this.logger.debug(putAclResposne);
134
- }
135
- catch (err) {
136
- this.logger.debug('Acl Update failed');
137
- this.logger.error(err);
138
- this.logger.error(err?.message);
137
+ const s3Endpoint = this.configService.get('S3_ENDPOINT');
138
+ if (!s3Endpoint) {
139
+ const newParams = {
140
+ ...params,
141
+ ACL: 'public-read',
142
+ };
143
+ try {
144
+ const aclUpdate = new S3.PutObjectAclCommand(newParams);
145
+ const putAclResposne = await client.send(aclUpdate);
146
+ this.logger.debug('putAclResponse');
147
+ this.logger.debug(putAclResposne);
148
+ }
149
+ catch (err) {
150
+ this.logger.debug('Acl Update failed');
151
+ this.logger.error(err);
152
+ this.logger.error(err?.message);
153
+ }
139
154
  }
140
155
  return response;
141
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clhq-s3-module",
3
- "version": "1.1.0-alpha.130",
3
+ "version": "1.1.0-alpha.131",
4
4
  "description": "Reusable S3 service module for NestJS.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",