@did-space/s3-driver 0.2.141 → 0.2.143
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 +58 -23
- package/package.json +4 -3
package/dist/operator/index.js
CHANGED
|
@@ -26,6 +26,8 @@ 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 debug = (0, debug_1.default)('@did-space/s3-driver:S3SpaceOperator');
|
|
29
31
|
class S3SpaceOperator {
|
|
30
32
|
constructor(options) {
|
|
31
33
|
this.options = options;
|
|
@@ -132,45 +134,78 @@ class S3SpaceOperator {
|
|
|
132
134
|
*/
|
|
133
135
|
write(options) {
|
|
134
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
137
|
+
const key = yield this.getObjectKey(options);
|
|
138
|
+
try {
|
|
139
|
+
debug('write.before', `Bucket=${this.options.bucket} Key=${key} Body=${String(options.data)} hash=${options.hash}`);
|
|
140
|
+
const upload = new lib_storage_1.Upload({
|
|
141
|
+
client: this.s3Client,
|
|
142
|
+
params: {
|
|
143
|
+
Bucket: this.options.bucket,
|
|
144
|
+
Key: key,
|
|
145
|
+
Body: options.data,
|
|
146
|
+
// @FIXME lib-storage 暂时不支持计算部件的 MD5 https://github.com/aws/aws-sdk-js-v3/issues/2673#issuecomment-1057408451
|
|
147
|
+
// ContentMD5: 'wSunmxovn3F4x1+NV+/d1A==',
|
|
148
|
+
Metadata: {
|
|
149
|
+
'x-hash': options.hash,
|
|
150
|
+
},
|
|
145
151
|
},
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
152
|
+
});
|
|
153
|
+
upload.on('httpUploadProgress', (progress) => {
|
|
154
|
+
debug('write.progress', `Bucket=${this.options.bucket} Key=${key} Body=${String(options.data)} hash=${options.hash} progress=${JSON.stringify(progress)}`);
|
|
155
|
+
});
|
|
156
|
+
yield upload.done();
|
|
157
|
+
debug('write.after', `Bucket=${this.options.bucket} Key=${key} Body=${String(options.data)} hash=${options.hash}`);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
debug('write.error', `Bucket=${this.options.bucket} Key=${key} Body=${String(options.data)} hash=${options.hash}`, error);
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
149
163
|
});
|
|
150
164
|
}
|
|
151
165
|
delete(options) {
|
|
152
166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
-
yield this.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
167
|
+
const key = yield this.getObjectKey(options);
|
|
168
|
+
try {
|
|
169
|
+
debug('delete.before', `Bucket=${this.options.bucket} Key=${key}`);
|
|
170
|
+
yield this.s3Client.send(new client_s3_1.DeleteObjectCommand({
|
|
171
|
+
Bucket: this.options.bucket,
|
|
172
|
+
Key: yield this.getObjectKey(options),
|
|
173
|
+
}));
|
|
174
|
+
debug('delete.after', `Bucket=${this.options.bucket} Key=${key}`);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
debug('delete.error', `Bucket=${this.options.bucket} Key=${key}`, error);
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
157
180
|
});
|
|
158
181
|
}
|
|
159
182
|
read(options) {
|
|
160
183
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
184
|
+
const key = yield this.getObjectKey(options);
|
|
185
|
+
try {
|
|
186
|
+
debug('read.before', `Bucket=${this.options.bucket} Key=${key}`);
|
|
187
|
+
const output = yield this.s3Client.send(new client_s3_1.GetObjectCommand({
|
|
188
|
+
Bucket: this.options.bucket,
|
|
189
|
+
Key: key,
|
|
190
|
+
}));
|
|
191
|
+
debug('read.after', `Bucket=${this.options.bucket} Key=${key}`);
|
|
192
|
+
return output.Body;
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
debug('read.error', `Bucket=${this.options.bucket} Key=${key}`, error);
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
166
198
|
});
|
|
167
199
|
}
|
|
168
200
|
getHash(options) {
|
|
169
201
|
return __awaiter(this, void 0, void 0, function* () {
|
|
202
|
+
const key = yield this.getObjectKey(options);
|
|
203
|
+
debug('getHash.before', `Bucket=${this.options.bucket} Key=${key}`);
|
|
170
204
|
const output = yield this.s3Client.send(new client_s3_1.HeadObjectCommand({
|
|
171
205
|
Bucket: this.options.bucket,
|
|
172
|
-
Key:
|
|
206
|
+
Key: key,
|
|
173
207
|
}));
|
|
208
|
+
debug('getHash.after', `Bucket=${this.options.bucket} Key=${key}`);
|
|
174
209
|
return output.Metadata['x-hash'];
|
|
175
210
|
});
|
|
176
211
|
}
|
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.143",
|
|
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.143",
|
|
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": "bb36886cc51e916177c2a21994132ee74281fe63"
|
|
59
60
|
}
|