@spinajs/fs-s3 2.0.180 → 2.0.182
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/lib/cjs/config.d.ts +13 -0
- package/lib/cjs/config.d.ts.map +1 -0
- package/lib/cjs/config.js +26 -0
- package/lib/cjs/config.js.map +1 -0
- package/lib/cjs/index.d.ts +136 -110
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +381 -344
- package/lib/cjs/index.js.map +1 -1
- package/lib/mjs/config.d.ts +13 -0
- package/lib/mjs/config.d.ts.map +1 -0
- package/lib/mjs/config.js +24 -0
- package/lib/mjs/config.js.map +1 -0
- package/lib/mjs/index.d.ts +136 -110
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +352 -338
- package/lib/mjs/index.js.map +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +9 -8
package/lib/cjs/index.js
CHANGED
|
@@ -1,345 +1,382 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Object.defineProperty(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
Body
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
await this.
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
*
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
*
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
async
|
|
297
|
-
throw new
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
//
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
(
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
32
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.fsS3 = void 0;
|
|
39
|
+
const di_1 = require("@spinajs/di");
|
|
40
|
+
const log_common_1 = require("@spinajs/log-common");
|
|
41
|
+
const fs_1 = require("@spinajs/fs");
|
|
42
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
43
|
+
const lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
44
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
45
|
+
const path_1 = __importStar(require("path"));
|
|
46
|
+
const exceptions_1 = require("@spinajs/exceptions");
|
|
47
|
+
const fs_2 = require("fs");
|
|
48
|
+
const luxon_1 = require("luxon");
|
|
49
|
+
const stream_1 = require("stream");
|
|
50
|
+
const iconv_lite_1 = __importDefault(require("iconv-lite"));
|
|
51
|
+
/**
|
|
52
|
+
* Abstract layer for file operations.
|
|
53
|
+
* Basic implementation is just wrapper for native node fs functions
|
|
54
|
+
*
|
|
55
|
+
* It allows to wrap other libs eg. aws s3, ftp
|
|
56
|
+
* and inject it into code without changing logic that use them.
|
|
57
|
+
*
|
|
58
|
+
* TODO: map errors to some kind of common errors shared with other implementations
|
|
59
|
+
*/
|
|
60
|
+
let fsS3 = class fsS3 extends fs_1.fs {
|
|
61
|
+
/**
|
|
62
|
+
* Name of provider. We can have multiple providers of the same type but with different options.
|
|
63
|
+
* Also used in InjectService decorator for mapping
|
|
64
|
+
*/
|
|
65
|
+
get Name() {
|
|
66
|
+
return this.Options.name;
|
|
67
|
+
}
|
|
68
|
+
constructor(Options) {
|
|
69
|
+
super();
|
|
70
|
+
this.Options = Options;
|
|
71
|
+
}
|
|
72
|
+
async resolve() {
|
|
73
|
+
this.S3 = new client_s3_1.S3Client(Object.assign({}, this.AwsConfig, {
|
|
74
|
+
endpoint: this.AwsConfig.endpoint ?? undefined,
|
|
75
|
+
logger: {
|
|
76
|
+
trace: (msg) => this.Logger.trace(msg),
|
|
77
|
+
debug: (msg) => this.Logger.debug(msg),
|
|
78
|
+
info: (msg) => this.Logger.info(msg),
|
|
79
|
+
warn: (msg) => this.Logger.warn(msg),
|
|
80
|
+
error: (msg) => this.Logger.error(msg),
|
|
81
|
+
},
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* Tries to download file to local filesystem, then returns local filesystem path.
|
|
87
|
+
* Native implementation simply returns local path and does nothing.
|
|
88
|
+
*
|
|
89
|
+
* @param path - file to download
|
|
90
|
+
*/
|
|
91
|
+
async download(path) {
|
|
92
|
+
const tmpName = this.TempFs.tmppath();
|
|
93
|
+
const wStream = await this.TempFs.writeStream(tmpName);
|
|
94
|
+
const command = new client_s3_1.GetObjectCommand({
|
|
95
|
+
Bucket: this.Options.bucket,
|
|
96
|
+
Key: path,
|
|
97
|
+
});
|
|
98
|
+
const result = await this.S3.send(command);
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
if (result.Body instanceof stream_1.Readable) {
|
|
101
|
+
result.Body.pipe(wStream)
|
|
102
|
+
.on('error', (err) => reject(err))
|
|
103
|
+
.on('close', () => resolve(tmpName));
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
reject(new exceptions_1.IOFail(`Cannot download file ${path}, empty response`));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* read all content of file
|
|
112
|
+
*/
|
|
113
|
+
async read(path, encoding) {
|
|
114
|
+
const fLocal = await this.download(path);
|
|
115
|
+
const content = await this.TempFs.read(fLocal, encoding);
|
|
116
|
+
await this.TempFs.rm(fLocal);
|
|
117
|
+
return content;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
*
|
|
121
|
+
* @param path
|
|
122
|
+
* @param _encoding
|
|
123
|
+
* @returns
|
|
124
|
+
*/
|
|
125
|
+
async readStream(path, encoding) {
|
|
126
|
+
const command = new client_s3_1.GetObjectCommand({
|
|
127
|
+
Bucket: this.Options.bucket,
|
|
128
|
+
Key: path,
|
|
129
|
+
});
|
|
130
|
+
const result = await this.S3.send(command);
|
|
131
|
+
const rStream = result.Body;
|
|
132
|
+
if (encoding) {
|
|
133
|
+
const encodedStream = rStream.pipe(iconv_lite_1.default.decodeStream(encoding));
|
|
134
|
+
return encodedStream;
|
|
135
|
+
}
|
|
136
|
+
return rStream;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Write to file string or buffer
|
|
140
|
+
*/
|
|
141
|
+
async write(path, data, encoding) {
|
|
142
|
+
const upload = new lib_storage_1.Upload({
|
|
143
|
+
client: this.S3,
|
|
144
|
+
params: {
|
|
145
|
+
Bucket: this.Options.bucket,
|
|
146
|
+
Key: path,
|
|
147
|
+
Body: data,
|
|
148
|
+
ContentEncoding: encoding,
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
await upload.done();
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* NOTE: append on s3 downloads file, appends to it, then uploads it again
|
|
155
|
+
* so it can be slow on large files
|
|
156
|
+
*
|
|
157
|
+
* @param path
|
|
158
|
+
* @param data
|
|
159
|
+
* @param encoding
|
|
160
|
+
*/
|
|
161
|
+
async append(path, data, encoding) {
|
|
162
|
+
/**
|
|
163
|
+
* We cannot append to file in s3 directly,
|
|
164
|
+
* we have to download file first, append locally, then upload again new file
|
|
165
|
+
*/
|
|
166
|
+
const fLocal = await this.download(path);
|
|
167
|
+
await this.TempFs.append(fLocal, data, encoding);
|
|
168
|
+
await this.upload(fLocal, path);
|
|
169
|
+
}
|
|
170
|
+
async upload(srcPath, destPath) {
|
|
171
|
+
if (!(0, fs_2.existsSync)(srcPath)) {
|
|
172
|
+
throw new exceptions_1.IOFail(`file ${srcPath} does not exists`);
|
|
173
|
+
}
|
|
174
|
+
const dPath = destPath ?? (0, path_1.basename)(srcPath);
|
|
175
|
+
const rStream = (0, fs_2.createReadStream)(srcPath);
|
|
176
|
+
const hash = await this.hash(srcPath, 'md5');
|
|
177
|
+
const fInfo = await this.FileInfo.getInfo(this.resolvePath(srcPath));
|
|
178
|
+
const upload = new lib_storage_1.Upload({
|
|
179
|
+
client: this.S3,
|
|
180
|
+
params: {
|
|
181
|
+
Bucket: this.Options.bucket,
|
|
182
|
+
Key: dPath,
|
|
183
|
+
Body: rStream,
|
|
184
|
+
// content md5 header is always base64 encoded
|
|
185
|
+
ContentMD5: Buffer.from(hash, 'hex').toString('base64'),
|
|
186
|
+
// convert all metadata values to string, and back to object with key-value pair of strings
|
|
187
|
+
Metadata: Object.fromEntries(Object.entries(fInfo).map(([key, value]) => [key, String(value)])),
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
await upload.done();
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
*
|
|
194
|
+
* Gets metadata of file in s3 bucket
|
|
195
|
+
*
|
|
196
|
+
* @param path path to file
|
|
197
|
+
* @returns
|
|
198
|
+
*/
|
|
199
|
+
async getMetadata(path) {
|
|
200
|
+
const command = new client_s3_1.HeadObjectCommand({
|
|
201
|
+
Bucket: this.Options.bucket,
|
|
202
|
+
Key: path,
|
|
203
|
+
});
|
|
204
|
+
const result = await this.S3.send(command);
|
|
205
|
+
return result.Metadata;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
*
|
|
209
|
+
* Returns writable stream for given path
|
|
210
|
+
*
|
|
211
|
+
* @param path file path ( relative to base path of provider)
|
|
212
|
+
* @param rStream readable stream, must be provided beforehand
|
|
213
|
+
* @param encoding optional stream encoding
|
|
214
|
+
*/
|
|
215
|
+
async writeStream(_path, _encoding) {
|
|
216
|
+
throw new exceptions_1.IOFail('Method not implemented, s3 does not support writable streams');
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Checks if file existst
|
|
220
|
+
* @param path - path to check
|
|
221
|
+
*/
|
|
222
|
+
async exists(path) {
|
|
223
|
+
try {
|
|
224
|
+
const command = new client_s3_1.HeadObjectCommand({
|
|
225
|
+
Bucket: this.Options.bucket,
|
|
226
|
+
Key: path,
|
|
227
|
+
});
|
|
228
|
+
await this.S3.send(command);
|
|
229
|
+
}
|
|
230
|
+
catch (err) {
|
|
231
|
+
if (err.name === 'NotFound')
|
|
232
|
+
return false;
|
|
233
|
+
throw err;
|
|
234
|
+
}
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
async dirExists() {
|
|
238
|
+
throw new exceptions_1.IOFail('Method not implemented, s3 does not support directories');
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Copy file to another location
|
|
242
|
+
* @param path - src path
|
|
243
|
+
* @param dest - dest path
|
|
244
|
+
*/
|
|
245
|
+
async copy(path, dest, dstFs) {
|
|
246
|
+
// if dest fs is set
|
|
247
|
+
// copy using it
|
|
248
|
+
if (dstFs) {
|
|
249
|
+
const file = await this.download(path);
|
|
250
|
+
await dstFs.upload(file, dest);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
// we copy file in s3 by copying it to another location
|
|
254
|
+
const command = new client_s3_1.CopyObjectCommand({
|
|
255
|
+
Bucket: this.Options.bucket,
|
|
256
|
+
CopySource: this.Options.bucket + '/' + path,
|
|
257
|
+
Key: dest,
|
|
258
|
+
});
|
|
259
|
+
await this.S3.send(command);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Copy file to another location and deletes src file
|
|
264
|
+
*/
|
|
265
|
+
async move(oldPath, newPath, dstFs) {
|
|
266
|
+
await this.copy(oldPath, newPath, dstFs);
|
|
267
|
+
await this.rm(oldPath);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Change name of a file
|
|
271
|
+
*/
|
|
272
|
+
async rename(oldPath, newPath) {
|
|
273
|
+
return this.move(oldPath, newPath);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
*
|
|
277
|
+
* Deletes dir recursively & all contents inside
|
|
278
|
+
*
|
|
279
|
+
* @param path - dir to remove
|
|
280
|
+
*/
|
|
281
|
+
async rm(_path) {
|
|
282
|
+
const command = new client_s3_1.DeleteObjectCommand({
|
|
283
|
+
Bucket: this.Options.bucket,
|
|
284
|
+
Key: _path,
|
|
285
|
+
});
|
|
286
|
+
await this.S3.send(command);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
*
|
|
290
|
+
* Creates directory, recursively
|
|
291
|
+
*
|
|
292
|
+
*/
|
|
293
|
+
async mkdir() {
|
|
294
|
+
throw new exceptions_1.IOFail('Method not implemented, s3 does not support directories');
|
|
295
|
+
}
|
|
296
|
+
async isDir(_path) {
|
|
297
|
+
throw new exceptions_1.IOFail('Method not implemented, s3 does not support directories');
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Returns file statistics, not all fields may be accesible
|
|
301
|
+
*/
|
|
302
|
+
async stat(path) {
|
|
303
|
+
const command = new client_s3_1.HeadObjectCommand({
|
|
304
|
+
Bucket: this.Options.bucket,
|
|
305
|
+
Key: path,
|
|
306
|
+
});
|
|
307
|
+
const result = await this.S3.send(command);
|
|
308
|
+
return {
|
|
309
|
+
// no directories in s3
|
|
310
|
+
IsDirectory: false,
|
|
311
|
+
// only files can be stored in s3
|
|
312
|
+
IsFile: true,
|
|
313
|
+
// no creation time
|
|
314
|
+
CreationTime: luxon_1.DateTime.min(),
|
|
315
|
+
ModifiedTime: luxon_1.DateTime.fromJSDate(result.LastModified),
|
|
316
|
+
// no access time in s3s
|
|
317
|
+
AccessTime: luxon_1.DateTime.min(),
|
|
318
|
+
Size: result.ContentLength,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
// protected async getSignedUrl(path: string) {
|
|
322
|
+
// return this.S3.getSignedUrlPromise('getObject', {
|
|
323
|
+
// Bucket: this.Options.bucket,
|
|
324
|
+
// Key: path,
|
|
325
|
+
// Expires: 24 * 60 * 60,
|
|
326
|
+
// });
|
|
327
|
+
// }
|
|
328
|
+
tmppath() {
|
|
329
|
+
throw new exceptions_1.MethodNotImplemented('fs s3 does not support temporary paths');
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* List content of directory
|
|
333
|
+
*
|
|
334
|
+
* @param path - path to directory
|
|
335
|
+
*/
|
|
336
|
+
async list(path) {
|
|
337
|
+
const command = new client_s3_1.ListObjectsV2Command({
|
|
338
|
+
Bucket: this.Options.bucket,
|
|
339
|
+
Delimiter: '/',
|
|
340
|
+
Prefix: path,
|
|
341
|
+
});
|
|
342
|
+
const result = await this.S3.send(command);
|
|
343
|
+
return result.Contents.map((x) => x.Key);
|
|
344
|
+
}
|
|
345
|
+
async unzip(_path, _destPath) {
|
|
346
|
+
throw new exceptions_1.IOFail('Method not implemented, you should download zipped file first, then unzip it');
|
|
347
|
+
}
|
|
348
|
+
async zip(_path, _dstFs, _dstFile) {
|
|
349
|
+
throw new exceptions_1.IOFail('Method not implemented, you should zip files locally, then upload it');
|
|
350
|
+
}
|
|
351
|
+
resolvePath(_path) {
|
|
352
|
+
// we checek if path is absolute
|
|
353
|
+
// for hash function
|
|
354
|
+
if (path_1.default.isAbsolute(_path)) {
|
|
355
|
+
return _path;
|
|
356
|
+
}
|
|
357
|
+
throw new exceptions_1.MethodNotImplemented('fs s3 does not support path resolving');
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
exports.fsS3 = fsS3;
|
|
361
|
+
__decorate([
|
|
362
|
+
(0, log_common_1.Logger)('fs'),
|
|
363
|
+
__metadata("design:type", log_common_1.Log)
|
|
364
|
+
], fsS3.prototype, "Logger", void 0);
|
|
365
|
+
__decorate([
|
|
366
|
+
(0, configuration_1.Config)('fs.s3.config'),
|
|
367
|
+
__metadata("design:type", Object)
|
|
368
|
+
], fsS3.prototype, "AwsConfig", void 0);
|
|
369
|
+
__decorate([
|
|
370
|
+
(0, fs_1.FileSystem)('fs-temp-s3'),
|
|
371
|
+
__metadata("design:type", fs_1.fs)
|
|
372
|
+
], fsS3.prototype, "TempFs", void 0);
|
|
373
|
+
__decorate([
|
|
374
|
+
(0, di_1.Autoinject)(),
|
|
375
|
+
__metadata("design:type", fs_1.FileInfoService)
|
|
376
|
+
], fsS3.prototype, "FileInfo", void 0);
|
|
377
|
+
exports.fsS3 = fsS3 = __decorate([
|
|
378
|
+
(0, di_1.Injectable)('fs'),
|
|
379
|
+
(0, di_1.PerInstanceCheck)(),
|
|
380
|
+
__metadata("design:paramtypes", [Object])
|
|
381
|
+
], fsS3);
|
|
345
382
|
//# sourceMappingURL=index.js.map
|