@did-space/s3-driver 0.2.142 → 0.2.144
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/dist/operator/index.js +62 -23
- package/package.json +4 -3
package/dist/operator/index.js
CHANGED
|
@@ -26,10 +26,16 @@ const path_1 = require("path");
|
|
|
26
26
|
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
27
27
|
const mime_types_1 = __importDefault(require("mime-types"));
|
|
28
28
|
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
29
|
+
const debug_1 = __importDefault(require("debug"));
|
|
30
|
+
const { version: s3ClientVersion } = require('@aws-sdk/client-s3/package.json');
|
|
31
|
+
const { version: libStorageVersion } = require('@aws-sdk/lib-storage/package.json');
|
|
32
|
+
const debug = (0, debug_1.default)('@did-space/s3-driver:S3SpaceOperator');
|
|
29
33
|
class S3SpaceOperator {
|
|
30
34
|
constructor(options) {
|
|
31
35
|
this.options = options;
|
|
32
36
|
this.s3Client = new client_s3_1.S3Client(this.options.s3ClientConfig);
|
|
37
|
+
debug('@aws-sdk/client-s3.version', s3ClientVersion);
|
|
38
|
+
debug('@aws-sdk/lib-storage.version', libStorageVersion);
|
|
33
39
|
}
|
|
34
40
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
35
41
|
createSpace(_storageConfig) {
|
|
@@ -132,45 +138,78 @@ class S3SpaceOperator {
|
|
|
132
138
|
*/
|
|
133
139
|
write(options) {
|
|
134
140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
const key = yield this.getObjectKey(options);
|
|
142
|
+
try {
|
|
143
|
+
debug('write.before', `Bucket=${this.options.bucket} Key=${key} Body=${String(options.data)} hash=${options.hash}`);
|
|
144
|
+
const upload = new lib_storage_1.Upload({
|
|
145
|
+
client: this.s3Client,
|
|
146
|
+
params: {
|
|
147
|
+
Bucket: this.options.bucket,
|
|
148
|
+
Key: key,
|
|
149
|
+
Body: options.data,
|
|
150
|
+
// @FIXME lib-storage 暂时不支持计算部件的 MD5 https://github.com/aws/aws-sdk-js-v3/issues/2673#issuecomment-1057408451
|
|
151
|
+
// ContentMD5: 'wSunmxovn3F4x1+NV+/d1A==',
|
|
152
|
+
Metadata: {
|
|
153
|
+
'x-hash': options.hash,
|
|
154
|
+
},
|
|
145
155
|
},
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
156
|
+
});
|
|
157
|
+
upload.on('httpUploadProgress', (progress) => {
|
|
158
|
+
debug('write.progress', `Bucket=${this.options.bucket} Key=${key} Body=${String(options.data)} hash=${options.hash} progress=${JSON.stringify(progress)}`);
|
|
159
|
+
});
|
|
160
|
+
yield upload.done();
|
|
161
|
+
debug('write.after', `Bucket=${this.options.bucket} Key=${key} Body=${String(options.data)} hash=${options.hash}`);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
debug('write.error', `Bucket=${this.options.bucket} Key=${key} Body=${String(options.data)} hash=${options.hash}`, error);
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
149
167
|
});
|
|
150
168
|
}
|
|
151
169
|
delete(options) {
|
|
152
170
|
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
-
yield this.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
171
|
+
const key = yield this.getObjectKey(options);
|
|
172
|
+
try {
|
|
173
|
+
debug('delete.before', `Bucket=${this.options.bucket} Key=${key}`);
|
|
174
|
+
yield this.s3Client.send(new client_s3_1.DeleteObjectCommand({
|
|
175
|
+
Bucket: this.options.bucket,
|
|
176
|
+
Key: yield this.getObjectKey(options),
|
|
177
|
+
}));
|
|
178
|
+
debug('delete.after', `Bucket=${this.options.bucket} Key=${key}`);
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
debug('delete.error', `Bucket=${this.options.bucket} Key=${key}`, error);
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
157
184
|
});
|
|
158
185
|
}
|
|
159
186
|
read(options) {
|
|
160
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
188
|
+
const key = yield this.getObjectKey(options);
|
|
189
|
+
try {
|
|
190
|
+
debug('read.before', `Bucket=${this.options.bucket} Key=${key}`);
|
|
191
|
+
const output = yield this.s3Client.send(new client_s3_1.GetObjectCommand({
|
|
192
|
+
Bucket: this.options.bucket,
|
|
193
|
+
Key: key,
|
|
194
|
+
}));
|
|
195
|
+
debug('read.after', `Bucket=${this.options.bucket} Key=${key}`);
|
|
196
|
+
return output.Body;
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
debug('read.error', `Bucket=${this.options.bucket} Key=${key}`, error);
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
166
202
|
});
|
|
167
203
|
}
|
|
168
204
|
getHash(options) {
|
|
169
205
|
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
const key = yield this.getObjectKey(options);
|
|
207
|
+
debug('getHash.before', `Bucket=${this.options.bucket} Key=${key}`);
|
|
170
208
|
const output = yield this.s3Client.send(new client_s3_1.HeadObjectCommand({
|
|
171
209
|
Bucket: this.options.bucket,
|
|
172
|
-
Key:
|
|
210
|
+
Key: key,
|
|
173
211
|
}));
|
|
212
|
+
debug('getHash.after', `Bucket=${this.options.bucket} Key=${key}`);
|
|
174
213
|
return output.Metadata['x-hash'];
|
|
175
214
|
});
|
|
176
215
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@did-space/s3-driver",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.144",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@aws-sdk/client-s3": "^3.362.0",
|
|
36
36
|
"@aws-sdk/lib-storage": "^3.362.0",
|
|
37
|
-
"@did-space/core": "0.2.
|
|
37
|
+
"@did-space/core": "0.2.144",
|
|
38
|
+
"debug": "^4.3.4",
|
|
38
39
|
"js-yaml": "^4.1.0",
|
|
39
40
|
"lodash": "^4.17.21",
|
|
40
41
|
"mime-types": "^2.1.35"
|
|
@@ -55,5 +56,5 @@
|
|
|
55
56
|
"ts-jest": "^28.0.6",
|
|
56
57
|
"typescript": "^4.9.5"
|
|
57
58
|
},
|
|
58
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "0789527b101f681b56c2c8860fb3d60659c71aa5"
|
|
59
60
|
}
|