aws-v3-sdk 1.0.32 → 1.0.33
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 +1 -0
- package/clients/s3R.js +170 -0
- package/es-handler/es-audits-wrapper.js +1 -1
- package/es-handler/es-wrapper.js +16 -4
- package/package.json +1 -1
package/clients/all.js
CHANGED
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/es-handler/es-wrapper.js
CHANGED
|
@@ -28,7 +28,8 @@ const getClient = async () => {
|
|
|
28
28
|
const cred = createAwsConnector(credentials, REGION)
|
|
29
29
|
return new Client({
|
|
30
30
|
...cred,
|
|
31
|
-
node: host
|
|
31
|
+
node: host,
|
|
32
|
+
maxRetries: 0
|
|
32
33
|
})
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -39,7 +40,8 @@ exports.sendReqToES = async (method, index, type, id, data) => {
|
|
|
39
40
|
const response = await client.delete({
|
|
40
41
|
index,
|
|
41
42
|
type,
|
|
42
|
-
id
|
|
43
|
+
id,
|
|
44
|
+
refresh: false
|
|
43
45
|
})
|
|
44
46
|
return response.body
|
|
45
47
|
} else if (method === 'UPDATE') {
|
|
@@ -48,7 +50,17 @@ exports.sendReqToES = async (method, index, type, id, data) => {
|
|
|
48
50
|
index,
|
|
49
51
|
type,
|
|
50
52
|
body: data,
|
|
51
|
-
refresh:
|
|
53
|
+
refresh: false,
|
|
54
|
+
retry_on_conflict: 10
|
|
55
|
+
})
|
|
56
|
+
return response.body
|
|
57
|
+
} else if (method === 'UPDATE_BY_QUERY') {
|
|
58
|
+
const response = await client.updateByQuery({
|
|
59
|
+
index,
|
|
60
|
+
type,
|
|
61
|
+
body: data,
|
|
62
|
+
refresh: false,
|
|
63
|
+
retry_on_conflict: 10
|
|
52
64
|
})
|
|
53
65
|
return response.body
|
|
54
66
|
} else {
|
|
@@ -57,7 +69,7 @@ exports.sendReqToES = async (method, index, type, id, data) => {
|
|
|
57
69
|
index,
|
|
58
70
|
type,
|
|
59
71
|
body: data,
|
|
60
|
-
refresh:
|
|
72
|
+
refresh: false
|
|
61
73
|
})
|
|
62
74
|
return response.body
|
|
63
75
|
}
|