@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/index.js CHANGED
@@ -1,345 +1,382 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- 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;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.fsS3 = void 0;
16
- const di_1 = require("@spinajs/di");
17
- const log_common_1 = require("@spinajs/log-common");
18
- const fs_1 = require("@spinajs/fs");
19
- const client_s3_1 = require("@aws-sdk/client-s3");
20
- const lib_storage_1 = require("@aws-sdk/lib-storage");
21
- const configuration_1 = require("@spinajs/configuration");
22
- const archiver_1 = __importDefault(require("archiver"));
23
- const path_1 = require("path");
24
- const exceptions_1 = require("@spinajs/exceptions");
25
- const fs_2 = require("fs");
26
- const luxon_1 = require("luxon");
27
- const stream_1 = require("stream");
28
- /**
29
- * Abstract layer for file operations.
30
- * Basic implementation is just wrapper for native node fs functions
31
- *
32
- * It allows to wrap other libs eg. aws s3, ftp
33
- * and inject it into code without changing logic that use them.
34
- *
35
- * TODO: map errors to some kind of common errors shared with other implementations
36
- */
37
- let fsS3 = class fsS3 extends fs_1.fs {
38
- /**
39
- * Name of provider. We can have multiple providers of the same type but with different options.
40
- * Also used in InjectService decorator for mapping
41
- */
42
- get Name() {
43
- return this.Options.name;
44
- }
45
- constructor(Options) {
46
- super();
47
- this.Options = Options;
48
- }
49
- async resolve() {
50
- this.S3 = new client_s3_1.S3Client(this.AwsConfig);
51
- }
52
- /**
53
- *
54
- * Tries to download file to local filesystem, then returns local filesystem path.
55
- * Native implementation simply returns local path and does nothing.
56
- *
57
- * @param path - file to download
58
- */
59
- async download(path) {
60
- const tmpName = this.TempFs.tmppath();
61
- const wStream = await this.TempFs.writeStream(tmpName);
62
- const command = new client_s3_1.GetObjectCommand({
63
- Bucket: this.Options.bucket,
64
- Key: path,
65
- });
66
- const result = await this.S3.send(command);
67
- return new Promise((resolve, reject) => {
68
- if (result.Body instanceof stream_1.Readable) {
69
- result.Body
70
- .pipe(wStream)
71
- .on("error", (err) => reject(err))
72
- .on("close", () => resolve(tmpName));
73
- }
74
- else {
75
- reject(new exceptions_1.IOFail(`Cannot download file ${path}, empty response`));
76
- }
77
- });
78
- }
79
- /**
80
- * read all content of file
81
- */
82
- async read(path, encoding) {
83
- const fLocal = await this.download(path);
84
- const content = await this.TempFs.read(fLocal, encoding);
85
- await this.TempFs.unlink(fLocal);
86
- return content;
87
- }
88
- async readStream(path, encoding) {
89
- const fLocal = await this.download(path);
90
- return this.TempFs.readStream(fLocal, encoding);
91
- }
92
- /**
93
- * Write to file string or buffer
94
- */
95
- async write(path, data, encoding) {
96
- const upload = new lib_storage_1.Upload({
97
- client: this.S3,
98
- params: {
99
- Bucket: this.Options.bucket,
100
- Key: path,
101
- Body: data,
102
- ContentEncoding: encoding
103
- },
104
- });
105
- await upload.done();
106
- }
107
- async append(path, data, encoding) {
108
- /**
109
- * We cannot append to file in s3 directly,
110
- * we have to download file first, append locally, then upload again new file
111
- */
112
- const fLocal = await this.download(path);
113
- await this.TempFs.append(fLocal, data, encoding);
114
- const wStream = await this.writeStream(path, encoding);
115
- const rStream = await this.TempFs.readStream(fLocal, encoding);
116
- return new Promise((resolve, reject) => {
117
- rStream
118
- .pipe(wStream)
119
- .on('end', () => {
120
- this.TempFs.rm(fLocal)
121
- .then(() => {
122
- return resolve();
123
- })
124
- .catch(() => {
125
- resolve();
126
- });
127
- })
128
- .on('error', (err) => {
129
- // eslint-disable-next-line promise/no-promise-in-callback
130
- this.TempFs.rm(fLocal)
131
- .then(() => {
132
- return reject(err);
133
- })
134
- .catch(() => {
135
- reject(err);
136
- });
137
- });
138
- });
139
- }
140
- async upload(srcPath, destPath) {
141
- if (!(0, fs_2.existsSync)(srcPath)) {
142
- throw new exceptions_1.IOFail(`file ${srcPath} does not exists`);
143
- }
144
- const dPath = this.resolvePath(destPath ?? (0, path_1.basename)(srcPath));
145
- const rStream = (0, fs_2.createReadStream)(srcPath);
146
- await this.writeStream(dPath, rStream);
147
- }
148
- async writeStream(path, rStream, encoding) {
149
- if (!(rStream instanceof fs_2.ReadStream)) {
150
- throw new exceptions_1.InvalidArgument(`rStream should be readable stream`);
151
- }
152
- const result = new lib_storage_1.Upload({
153
- client: this.S3,
154
- params: {
155
- Bucket: this.Options.bucket,
156
- Key: path,
157
- Body: rStream,
158
- ContentEncoding: encoding,
159
- },
160
- });
161
- await result.done();
162
- }
163
- /**
164
- * Checks if file existst
165
- * @param path - path to check
166
- */
167
- async exists(path) {
168
- try {
169
- const command = new client_s3_1.HeadObjectCommand({
170
- Bucket: this.Options.bucket,
171
- Key: path,
172
- });
173
- await this.S3.send(command);
174
- }
175
- catch (err) {
176
- if (err.name === 'NotFound')
177
- return false;
178
- }
179
- return true;
180
- }
181
- async dirExists() {
182
- // s3 does not have concept of folders
183
- // we assume that all exists
184
- return Promise.resolve(true);
185
- }
186
- /**
187
- * Copy file to another location
188
- * @param path - src path
189
- * @param dest - dest path
190
- */
191
- async copy(path, dest) {
192
- const command = new client_s3_1.CopyObjectCommand({
193
- Bucket: this.Options.bucket,
194
- CopySource: this.Options.bucket + '/' + path,
195
- Key: dest,
196
- });
197
- await this.S3.send(command);
198
- }
199
- /**
200
- * Copy file to another location and deletes src file
201
- */
202
- async move(oldPath, newPath) {
203
- await this.copy(oldPath, newPath);
204
- await this.unlink(oldPath);
205
- }
206
- /**
207
- * Change name of a file
208
- */
209
- async rename(oldPath, newPath) {
210
- return this.move(oldPath, newPath);
211
- }
212
- /**
213
- * Deletes file permanently
214
- *
215
- * @param path - path to file that will be deleted
216
- * @param onlyTemp - remote filesystems need to download file before, if so, calling unlink with this flag removes only local temp file after we finished processing
217
- */
218
- async unlink(path, onlyTemp) {
219
- if (onlyTemp) {
220
- await this.TempFs.unlink(path);
221
- return;
222
- }
223
- const command = new client_s3_1.DeleteObjectCommand({
224
- Key: path,
225
- Bucket: this.Options.bucket,
226
- });
227
- await this.S3.send(command);
228
- }
229
- /**
230
- *
231
- * Deletes dir recursively & all contents inside
232
- *
233
- * @param path - dir to remove
234
- */
235
- async rm(_path) {
236
- const command = new client_s3_1.DeleteObjectCommand({
237
- Bucket: this.Options.bucket,
238
- Key: _path
239
- });
240
- await this.S3.send(command);
241
- }
242
- /**
243
- *
244
- * Creates directory, recursively
245
- *
246
- */
247
- async mkdir() {
248
- // s3 dont need to create folders
249
- }
250
- /**
251
- * Returns file statistics, not all fields may be accesible
252
- */
253
- async stat(path) {
254
- const command = new client_s3_1.HeadObjectCommand({
255
- Bucket: this.Options.bucket,
256
- Key: path
257
- });
258
- const result = await this.S3.send(command);
259
- return {
260
- // no directories in s3
261
- IsDirectory: false,
262
- // only files can be stored in s3
263
- IsFile: true,
264
- // no creation time
265
- CreationTime: luxon_1.DateTime.min(),
266
- ModifiedTime: luxon_1.DateTime.fromJSDate(result.LastModified),
267
- // no access time in s3s
268
- AccessTime: luxon_1.DateTime.min(),
269
- Size: result.ContentLength,
270
- };
271
- }
272
- // protected async getSignedUrl(path: string) {
273
- // return this.S3.getSignedUrlPromise('getObject', {
274
- // Bucket: this.Options.bucket,
275
- // Key: path,
276
- // Expires: 24 * 60 * 60,
277
- // });
278
- // }
279
- tmppath() {
280
- throw new exceptions_1.MethodNotImplemented('fs s3 does not support temporary paths');
281
- }
282
- /**
283
- * List content of directory
284
- *
285
- * @param path - path to directory
286
- */
287
- async list(path) {
288
- const command = new client_s3_1.ListObjectsV2Command({
289
- Bucket: this.Options.bucket,
290
- Delimiter: '/',
291
- Prefix: path,
292
- });
293
- const result = await this.S3.send(command);
294
- return result.Contents.map((x) => x.Key);
295
- }
296
- async unzip(_path, _destPath) {
297
- throw new Error('not implemented');
298
- }
299
- async zip(path, zName) {
300
- const zTmpName = this.TempFs.tmppath();
301
- const output = await this.TempFs.writeStream(zTmpName);
302
- const archive = (0, archiver_1.default)('zip', {
303
- zlib: { level: 9 }, // Sets the compression level.
304
- });
305
- // pipe archive data to the file
306
- archive.pipe(output);
307
- const tFile = await this.download(path);
308
- archive.file(tFile, { name: zName ?? (0, path_1.basename)(path) });
309
- await archive.finalize();
310
- return {
311
- asFilePath: () => {
312
- return zTmpName;
313
- },
314
- asStream: (encoding) => {
315
- return (0, fs_2.createReadStream)(`${zTmpName}`, encoding);
316
- },
317
- asBase64: () => {
318
- return (0, fs_2.readFileSync)(`${zTmpName}`, 'base64');
319
- },
320
- };
321
- }
322
- // eslint-disable-next-line @typescript-eslint/no-empty-function
323
- resolvePath(_path) {
324
- throw new exceptions_1.MethodNotImplemented('fs s3 does not support path resolving');
325
- }
326
- };
327
- __decorate([
328
- (0, log_common_1.Logger)('fs'),
329
- __metadata("design:type", log_common_1.Log)
330
- ], fsS3.prototype, "Logger", void 0);
331
- __decorate([
332
- (0, configuration_1.Config)('fs.s3.config'),
333
- __metadata("design:type", Object)
334
- ], fsS3.prototype, "AwsConfig", void 0);
335
- __decorate([
336
- (0, fs_1.FileSystem)('fs-temp'),
337
- __metadata("design:type", fs_1.fs)
338
- ], fsS3.prototype, "TempFs", void 0);
339
- fsS3 = __decorate([
340
- (0, di_1.Injectable)('fs'),
341
- (0, di_1.PerInstanceCheck)(),
342
- __metadata("design:paramtypes", [Object])
343
- ], fsS3);
344
- exports.fsS3 = fsS3;
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