aws-v3-sdk 1.0.31 → 2.0.1

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/clients/all.js CHANGED
@@ -3,6 +3,7 @@ module.exports = {
3
3
  DynamoDB: require('./dynamoDB'),
4
4
  EnvironmentCredentials: require('./credential'),
5
5
  S3: require('./s3'),
6
+ S3R: require('./s3R'),
6
7
  STS: require('./sts'),
7
8
  SQS: require('./sqs'),
8
9
  SNS: require('./sns'),
package/clients/s3R.js ADDED
@@ -0,0 +1,170 @@
1
+ const { S3Client, GetObjectCommand, PutObjectCommand, ListObjectsCommand, DeleteObjectsCommand, CreateMultipartUploadCommand, CompleteMultipartUploadCommand, UploadPartCommand, ListObjectsV2Command } = require('@aws-sdk/client-s3')
2
+ const { getSignedUrl } = require('@aws-sdk/s3-request-presigner')
3
+ class S3R {
4
+ constructor (params) {
5
+ this.client = new S3Client(params)
6
+ }
7
+
8
+ getSignedUrl (type, params, callback) {
9
+ return new Promise((resolve, reject) => {
10
+ if (type === 'getObject') {
11
+ const Expires = params.Expires
12
+ delete params.Expires
13
+ const command = new GetObjectCommand(params)
14
+ getSignedUrl(this.client, command, { expiresIn: Expires }).then(url => {
15
+ resolve(url)
16
+ }).catch(err => {
17
+ resolve(err)
18
+ })
19
+ } else if (type === 'putObject') {
20
+ const Expires = params.Expires
21
+ delete params.Expires
22
+ const command = new PutObjectCommand(params)
23
+ getSignedUrl(this.client, command, { expiresIn: Expires }).then(url => {
24
+ resolve(url)
25
+ }).catch(err => {
26
+ resolve(err)
27
+ })
28
+ } else if (type === 'uploadPart') {
29
+ const Expires = params.Expires
30
+ delete params.Expires
31
+ const command = new UploadPartCommand(params)
32
+ getSignedUrl(this.client, command, { expiresIn: Expires }).then(url => {
33
+ resolve(url)
34
+ }).catch(err => {
35
+ resolve(err)
36
+ })
37
+ }
38
+ }).then(result => {
39
+ if (callback && typeof callback === 'function') {
40
+ callback(null, result)
41
+ }
42
+ return result
43
+ }).catch(error => {
44
+ if (callback && typeof callback === 'function') {
45
+ callback(error, null)
46
+ }
47
+ return Promise.reject(error)
48
+ })
49
+ }
50
+
51
+ createMultipartUpload (params, callback) {
52
+ return new Promise((resolve, reject) => {
53
+ const command = new CreateMultipartUploadCommand(params)
54
+ this.client.send(command).then(response => {
55
+ resolve(response)
56
+ }).catch(err => {
57
+ reject(err)
58
+ })
59
+ }).then(result => {
60
+ if (callback && typeof callback === 'function') {
61
+ callback(null, result)
62
+ }
63
+ return result
64
+ }).catch(error => {
65
+ if (callback && typeof callback === 'function') {
66
+ callback(error, null)
67
+ }
68
+ return Promise.reject(error)
69
+ })
70
+ }
71
+
72
+ completeMultipartUpload (params, callback) {
73
+ return new Promise((resolve, reject) => {
74
+ const command = new CompleteMultipartUploadCommand(params)
75
+ this.client.send(command).then(response => {
76
+ resolve(response)
77
+ }).catch(err => {
78
+ resolve(err)
79
+ })
80
+ }).then(result => {
81
+ if (callback && typeof callback === 'function') {
82
+ callback(null, result)
83
+ }
84
+ return result
85
+ }).catch(error => {
86
+ if (callback && typeof callback === 'function') {
87
+ callback(error, null)
88
+ }
89
+ return Promise.reject(error)
90
+ })
91
+ }
92
+
93
+ getObject (params, callback) {
94
+ return new Promise((resolve, reject) => {
95
+ const getObject = new GetObjectCommand(params)
96
+ this.client.send(getObject).then(response => {
97
+ const chunks = []
98
+ const stream = response.Body
99
+ stream.on('data', chunk => chunks.push(chunk))
100
+ stream.on('end', () => {
101
+ const imageBuffer = Buffer.concat(chunks)
102
+ response.Body = imageBuffer
103
+ resolve(response)
104
+ })
105
+ }).catch(err => {
106
+ resolve(err)
107
+ })
108
+ }).then(result => {
109
+ if (callback && typeof callback === 'function') {
110
+ callback(null, result)
111
+ }
112
+ return result
113
+ }).catch(error => {
114
+ if (callback && typeof callback === 'function') {
115
+ callback(error, null)
116
+ }
117
+ return Promise.reject(error)
118
+ })
119
+ }
120
+
121
+ putObject (params, callback) {
122
+ return new Promise((resolve, reject) => {
123
+ const putObject = new PutObjectCommand(params)
124
+ this.client.send(putObject, (err, data) => {
125
+ if (err || !data) {
126
+ resolve(err)
127
+ }
128
+ if (data) {
129
+ resolve(data)
130
+ }
131
+ })
132
+ }).then(result => {
133
+ if (callback && typeof callback === 'function') {
134
+ callback(null, result)
135
+ }
136
+ return result
137
+ }).catch(error => {
138
+ if (callback && typeof callback === 'function') {
139
+ callback(error, null)
140
+ }
141
+ return Promise.reject(error)
142
+ })
143
+ }
144
+
145
+ listObjectsV2 (params, callback) {
146
+ return new Promise((resolve, reject) => {
147
+ const command = new ListObjectsV2Command(params)
148
+ this.client.send(command, (err, data) => {
149
+ if (err || !data) {
150
+ resolve(err)
151
+ }
152
+ if (data) {
153
+ resolve(data)
154
+ }
155
+ })
156
+ }).then(result => {
157
+ if (callback && typeof callback === 'function') {
158
+ callback(null, result)
159
+ }
160
+ return result
161
+ }).catch(error => {
162
+ if (callback && typeof callback === 'function') {
163
+ callback(error, null)
164
+ }
165
+ return Promise.reject(error)
166
+ })
167
+ }
168
+ }
169
+
170
+ module.exports = S3R
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-v3-sdk",
3
- "version": "1.0.31",
3
+ "version": "2.0.1",
4
4
  "description": "AWS v3 SDK Utils",
5
5
  "main": "index.js",
6
6
  "scripts": {