@nuvix/storage 0.1.0

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.
@@ -0,0 +1,1270 @@
1
+ 'use strict';
2
+
3
+ var promises = require('fs/promises');
4
+ var fs = require('fs');
5
+ var path = require('path');
6
+ var crypto = require('crypto');
7
+
8
+ class Device {
9
+ constructor() {
10
+ /**
11
+ * Max chunk size while transferring file from one device to another
12
+ */
13
+ this.transferChunkSize = 20000000; // 20 MB
14
+ }
15
+ /**
16
+ * Set Transfer Chunk Size
17
+ */
18
+ setTransferChunkSize(chunkSize) {
19
+ this.transferChunkSize = chunkSize;
20
+ }
21
+ /**
22
+ * Get Transfer Chunk Size
23
+ */
24
+ getTransferChunkSize() {
25
+ return this.transferChunkSize;
26
+ }
27
+ /**
28
+ * Move file from given source to given path, return true on success and false on failure.
29
+ */
30
+ async move(source, target) {
31
+ if (source === target) {
32
+ return false;
33
+ }
34
+ if (await this.transfer(source, target, this)) {
35
+ return await this.delete(source);
36
+ }
37
+ return false;
38
+ }
39
+ /**
40
+ * Get the absolute path by resolving strings like ../, .., //, /\ and so on.
41
+ *
42
+ * Works like the realpath function but works on files that does not exist
43
+ */
44
+ getAbsolutePath(path) {
45
+ const normalizedPath = path.replace(/[/\\]/g, '/');
46
+ const parts = normalizedPath.split('/').filter(part => part.length > 0);
47
+ const absolutes = [];
48
+ for (const part of parts) {
49
+ if (part === '.') {
50
+ continue;
51
+ }
52
+ if (part === '..') {
53
+ absolutes.pop();
54
+ }
55
+ else {
56
+ absolutes.push(part);
57
+ }
58
+ }
59
+ return '/' + absolutes.join('/');
60
+ }
61
+ async getMimeType(filePath) {
62
+ const path = await import('path');
63
+ // Node.js doesn't have a built-in MIME type module, so we'll use a comprehensive mapping
64
+ const ext = path.extname(filePath).toLowerCase().slice(1);
65
+ const mimeTypes = {
66
+ // Text
67
+ 'txt': 'text/plain',
68
+ 'html': 'text/html',
69
+ 'htm': 'text/html',
70
+ 'css': 'text/css',
71
+ 'csv': 'text/csv',
72
+ 'xml': 'text/xml',
73
+ // JavaScript
74
+ 'js': 'application/javascript',
75
+ 'mjs': 'application/javascript',
76
+ 'json': 'application/json',
77
+ // Images
78
+ 'png': 'image/png',
79
+ 'jpg': 'image/jpeg',
80
+ 'jpeg': 'image/jpeg',
81
+ 'gif': 'image/gif',
82
+ 'svg': 'image/svg+xml',
83
+ 'webp': 'image/webp',
84
+ 'ico': 'image/x-icon',
85
+ 'bmp': 'image/bmp',
86
+ 'tiff': 'image/tiff',
87
+ 'tif': 'image/tiff',
88
+ // Documents
89
+ 'pdf': 'application/pdf',
90
+ 'doc': 'application/msword',
91
+ 'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
92
+ 'xls': 'application/vnd.ms-excel',
93
+ 'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
94
+ 'ppt': 'application/vnd.ms-powerpoint',
95
+ 'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
96
+ // Audio
97
+ 'mp3': 'audio/mpeg',
98
+ 'wav': 'audio/wav',
99
+ 'ogg': 'audio/ogg',
100
+ 'm4a': 'audio/mp4',
101
+ // Video
102
+ 'mp4': 'video/mp4',
103
+ 'avi': 'video/x-msvideo',
104
+ 'mov': 'video/quicktime',
105
+ 'wmv': 'video/x-ms-wmv',
106
+ 'flv': 'video/x-flv',
107
+ 'webm': 'video/webm',
108
+ // Archives
109
+ 'zip': 'application/zip',
110
+ 'rar': 'application/x-rar-compressed',
111
+ 'tar': 'application/x-tar',
112
+ 'gz': 'application/gzip',
113
+ '7z': 'application/x-7z-compressed',
114
+ // Other
115
+ 'bin': 'application/octet-stream',
116
+ 'exe': 'application/octet-stream',
117
+ 'dmg': 'application/octet-stream'
118
+ };
119
+ return mimeTypes[ext] || 'application/octet-stream';
120
+ }
121
+ }
122
+ /**
123
+ * Sets the maximum number of keys returned to the response. By default, the action returns up to 1,000 key names.
124
+ */
125
+ Device.MAX_PAGE_SIZE = Number.MAX_SAFE_INTEGER;
126
+
127
+ class Storage {
128
+ /**
129
+ * Set Device.
130
+ *
131
+ * Add device by name
132
+ *
133
+ * @param name
134
+ * @param device
135
+ * @throws Error
136
+ */
137
+ static setDevice(name, device) {
138
+ this.devices.set(name, device);
139
+ }
140
+ /**
141
+ * Get Device.
142
+ *
143
+ * Get device by name
144
+ *
145
+ * @param name
146
+ * @returns Device
147
+ * @throws Error
148
+ */
149
+ static getDevice(name) {
150
+ if (!this.devices.has(name)) {
151
+ throw new Error(`The device "${name}" is not listed`);
152
+ }
153
+ return this.devices.get(name);
154
+ }
155
+ /**
156
+ * Exists.
157
+ *
158
+ * Checks if given storage name is registered or not
159
+ *
160
+ * @param name
161
+ * @returns boolean
162
+ */
163
+ static exists(name) {
164
+ return this.devices.has(name);
165
+ }
166
+ /**
167
+ * Human readable data size format from bytes input.
168
+ *
169
+ * Based on: https://stackoverflow.com/a/38659168/2299554
170
+ *
171
+ * @param bytes
172
+ * @param decimals
173
+ * @param system
174
+ * @returns string
175
+ */
176
+ static human(bytes, decimals = 2, system = 'metric') {
177
+ const mod = system === 'binary' ? 1024 : 1000;
178
+ const units = {
179
+ binary: ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'],
180
+ metric: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
181
+ };
182
+ const factor = Math.floor((bytes.toString().length - 1) / 3);
183
+ return `${(bytes / Math.pow(mod, factor)).toFixed(decimals)}${units[system][factor]}`;
184
+ }
185
+ }
186
+ /**
187
+ * Supported devices
188
+ */
189
+ Storage.DEVICE_LOCAL = 'local';
190
+ Storage.DEVICE_S3 = 's3';
191
+ // static readonly DEVICE_DO_SPACES = 'dospaces';
192
+ Storage.DEVICE_WASABI = 'wasabi';
193
+ // static readonly DEVICE_BACKBLAZE = 'backblaze';
194
+ // static readonly DEVICE_LINODE = 'linode';
195
+ /**
196
+ * Devices.
197
+ *
198
+ * List of all available storage devices
199
+ */
200
+ Storage.devices = new Map();
201
+
202
+ class Validator {
203
+ }
204
+ Validator.TYPE_STRING = 'string';
205
+ Validator.TYPE_ARRAY = 'array';
206
+ Validator.TYPE_INTEGER = 'integer';
207
+ Validator.TYPE_BOOLEAN = 'boolean';
208
+
209
+ class File extends Validator {
210
+ getDescription() {
211
+ return 'File is not valid';
212
+ }
213
+ /**
214
+ * NOT MUCH RIGHT NOW.
215
+ *
216
+ * TODO think what to do here, currently only used for parameter to be present in SDKs
217
+ *
218
+ * @param name
219
+ * @return boolean
220
+ */
221
+ isValid(name) {
222
+ return true;
223
+ }
224
+ /**
225
+ * Is array
226
+ *
227
+ * Function will return true if object is array.
228
+ *
229
+ * @return boolean
230
+ */
231
+ isArray() {
232
+ return false;
233
+ }
234
+ /**
235
+ * Get Type
236
+ *
237
+ * Returns validator type.
238
+ *
239
+ * @return string
240
+ */
241
+ getType() {
242
+ return 'string';
243
+ }
244
+ }
245
+
246
+ class FileExt extends Validator {
247
+ constructor(allowed) {
248
+ super();
249
+ this.allowed = allowed;
250
+ }
251
+ getDescription() {
252
+ return 'File extension is not valid';
253
+ }
254
+ isValid(filename) {
255
+ const ext = this.getFileExtension(filename).toLowerCase();
256
+ return this.allowed.includes(ext);
257
+ }
258
+ isArray() {
259
+ return false;
260
+ }
261
+ getType() {
262
+ return 'string';
263
+ }
264
+ getFileExtension(filename) {
265
+ const lastDotIndex = filename.lastIndexOf('.');
266
+ return lastDotIndex !== -1 ? filename.substring(lastDotIndex + 1) : '';
267
+ }
268
+ }
269
+ FileExt.TYPE_JPEG = 'jpeg';
270
+ FileExt.TYPE_JPG = 'jpg';
271
+ FileExt.TYPE_GIF = 'gif';
272
+ FileExt.TYPE_PNG = 'png';
273
+ FileExt.TYPE_GZIP = 'gz';
274
+ FileExt.TYPE_ZIP = 'zip';
275
+
276
+ class FileName extends Validator {
277
+ /**
278
+ * Get Description
279
+ */
280
+ getDescription() {
281
+ return 'Filename is not valid';
282
+ }
283
+ /**
284
+ * The file name can only contain "a-z", "A-Z", "0-9" and "." and not empty.
285
+ *
286
+ * @param name - The filename to validate
287
+ * @returns boolean indicating if the filename is valid
288
+ */
289
+ isValid(name) {
290
+ if (!name) {
291
+ return false;
292
+ }
293
+ if (typeof name !== 'string') {
294
+ return false;
295
+ }
296
+ if (!/^[a-zA-Z0-9.]+$/.test(name)) {
297
+ return false;
298
+ }
299
+ return true;
300
+ }
301
+ /**
302
+ * Is array
303
+ *
304
+ * Function will return true if object is array.
305
+ *
306
+ * @returns boolean
307
+ */
308
+ isArray() {
309
+ return false;
310
+ }
311
+ /**
312
+ * Get Type
313
+ *
314
+ * Returns validator type.
315
+ *
316
+ * @returns string
317
+ */
318
+ getType() {
319
+ return Validator.TYPE_STRING;
320
+ }
321
+ }
322
+
323
+ class FileSize extends Validator {
324
+ /**
325
+ * Max size in bytes
326
+ */
327
+ constructor(max) {
328
+ super();
329
+ this.max = max;
330
+ }
331
+ /**
332
+ * Get Description
333
+ */
334
+ getDescription() {
335
+ return `File size can't be bigger than ${this.max}`;
336
+ }
337
+ /**
338
+ * Finds whether a file size is smaller than required limit.
339
+ */
340
+ isValid(fileSize) {
341
+ if (typeof fileSize !== 'number' || !Number.isInteger(fileSize)) {
342
+ return false;
343
+ }
344
+ if (fileSize > this.max) {
345
+ return false;
346
+ }
347
+ return true;
348
+ }
349
+ /**
350
+ * Is array
351
+ *
352
+ * Function will return true if object is array.
353
+ */
354
+ isArray() {
355
+ return false;
356
+ }
357
+ /**
358
+ * Get Type
359
+ *
360
+ * Returns validator type.
361
+ */
362
+ getType() {
363
+ return Validator.TYPE_INTEGER;
364
+ }
365
+ }
366
+
367
+ class FileType extends Validator {
368
+ constructor(allowed) {
369
+ super();
370
+ /**
371
+ * File Type Binaries.
372
+ */
373
+ this.types = {
374
+ [FileType.FILE_TYPE_JPEG]: '\xFF\xD8\xFF',
375
+ [FileType.FILE_TYPE_GIF]: 'GIF',
376
+ [FileType.FILE_TYPE_PNG]: '\x89\x50\x4e\x47\x0d\x0a',
377
+ [FileType.FILE_TYPE_GZIP]: 'application/x-gzip',
378
+ };
379
+ for (const key of allowed) {
380
+ if (!(key in this.types)) {
381
+ throw new Error('Unknown file mime type');
382
+ }
383
+ }
384
+ this.allowed = allowed;
385
+ }
386
+ /**
387
+ * Get Description
388
+ */
389
+ getDescription() {
390
+ return 'File mime-type is not allowed ';
391
+ }
392
+ /**
393
+ * Is Valid.
394
+ *
395
+ * Binary check to finds whether a file is of valid type
396
+ */
397
+ async isValid(path) {
398
+ try {
399
+ const buffer = await promises.readFile(path);
400
+ const bytes = buffer.toString('binary', 0, 8);
401
+ for (const key of this.allowed) {
402
+ if (bytes.indexOf(this.types[key]) === 0) {
403
+ return true;
404
+ }
405
+ }
406
+ return false;
407
+ }
408
+ catch {
409
+ return false;
410
+ }
411
+ }
412
+ /**
413
+ * Is array
414
+ */
415
+ isArray() {
416
+ return false;
417
+ }
418
+ /**
419
+ * Get Type
420
+ */
421
+ getType() {
422
+ return 'string';
423
+ }
424
+ }
425
+ /**
426
+ * File Types Constants.
427
+ */
428
+ FileType.FILE_TYPE_JPEG = 'jpeg';
429
+ FileType.FILE_TYPE_GIF = 'gif';
430
+ FileType.FILE_TYPE_PNG = 'png';
431
+ FileType.FILE_TYPE_GZIP = 'gz';
432
+
433
+ class Upload extends Validator {
434
+ /**
435
+ * Get Description
436
+ */
437
+ getDescription() {
438
+ return 'Not a valid upload file';
439
+ }
440
+ /**
441
+ * Check if a file is a valid upload file
442
+ *
443
+ * @param path - The file path to validate
444
+ * @returns Promise that resolves to true if valid upload file, false otherwise
445
+ */
446
+ async isValid(path) {
447
+ if (typeof path !== 'string') {
448
+ return false;
449
+ }
450
+ try {
451
+ const stats = await fs.promises.stat(path);
452
+ return stats.isFile();
453
+ }
454
+ catch {
455
+ return false;
456
+ }
457
+ }
458
+ /**
459
+ * Is array
460
+ *
461
+ * Function will return true if object is array.
462
+ *
463
+ * @returns false - this validator doesn't handle arrays
464
+ */
465
+ isArray() {
466
+ return false;
467
+ }
468
+ /**
469
+ * Get Type
470
+ *
471
+ * Returns validator type.
472
+ *
473
+ * @returns The validator type
474
+ */
475
+ getType() {
476
+ return 'string';
477
+ }
478
+ }
479
+
480
+ class Local extends Device {
481
+ constructor(root = '') {
482
+ super();
483
+ this.root = 'temp';
484
+ this.MAX_PAGE_SIZE = 1000;
485
+ this.root = root;
486
+ }
487
+ getName() {
488
+ return 'Local Storage';
489
+ }
490
+ getType() {
491
+ return Storage.DEVICE_LOCAL;
492
+ }
493
+ getDescription() {
494
+ return 'Adapter for Local storage that is in the physical or virtual machine or mounted to it.';
495
+ }
496
+ getRoot() {
497
+ return this.root;
498
+ }
499
+ getPath(filename, prefix) {
500
+ return this.getAbsolutePath(path.join(this.getRoot(), filename));
501
+ }
502
+ async upload(source, filePath, chunk = 1, chunks = 1, metadata = {}) {
503
+ await this.createDirectory(path.dirname(filePath));
504
+ if (chunks === 1) {
505
+ try {
506
+ await fs.promises.rename(source, filePath);
507
+ return chunks;
508
+ }
509
+ catch (error) {
510
+ throw new Error(`Can't upload file ${filePath}`);
511
+ }
512
+ }
513
+ const tmp = path.join(path.dirname(filePath), `tmp_${path.basename(filePath)}`, `${path.basename(filePath)}_chunks.log`);
514
+ await this.createDirectory(path.dirname(tmp));
515
+ const chunkFilePath = path.join(path.dirname(tmp), `${path.parse(filePath).name}.part.${chunk}`);
516
+ // Skip writing chunk if the chunk was re-uploaded
517
+ if (!(await this.exists(chunkFilePath))) {
518
+ try {
519
+ await fs.promises.appendFile(tmp, `${chunk}\n`);
520
+ }
521
+ catch (error) {
522
+ throw new Error(`Can't write chunk log ${tmp}`);
523
+ }
524
+ }
525
+ try {
526
+ const chunkLogs = await fs.promises.readFile(tmp, 'utf8');
527
+ const chunksReceived = chunkLogs.trim().split('\n').length;
528
+ await fs.promises.rename(source, chunkFilePath);
529
+ if (chunks === chunksReceived) {
530
+ await this.joinChunks(filePath, chunks);
531
+ return chunksReceived;
532
+ }
533
+ return chunksReceived;
534
+ }
535
+ catch (error) {
536
+ throw new Error(`Failed to write chunk ${chunk}`);
537
+ }
538
+ }
539
+ async uploadData(data, filePath, contentType, chunk = 1, chunks = 1, metadata = {}) {
540
+ await this.createDirectory(path.dirname(filePath));
541
+ if (chunks === 1) {
542
+ try {
543
+ await fs.promises.writeFile(filePath, data);
544
+ return chunks;
545
+ }
546
+ catch (error) {
547
+ throw new Error(`Can't write file ${filePath}`);
548
+ }
549
+ }
550
+ const tmp = path.join(path.dirname(filePath), `tmp_${path.basename(filePath)}`, `${path.basename(filePath)}_chunks.log`);
551
+ await this.createDirectory(path.dirname(tmp));
552
+ try {
553
+ await fs.promises.appendFile(tmp, `${chunk}\n`);
554
+ const chunkLogs = await fs.promises.readFile(tmp, 'utf8');
555
+ const chunksReceived = chunkLogs.trim().split('\n').length;
556
+ const chunkFilePath = path.join(path.dirname(tmp), `${path.parse(filePath).name}.part.${chunk}`);
557
+ await fs.promises.writeFile(chunkFilePath, data);
558
+ if (chunks === chunksReceived) {
559
+ await this.joinChunks(filePath, chunks);
560
+ return chunksReceived;
561
+ }
562
+ return chunksReceived;
563
+ }
564
+ catch (error) {
565
+ throw new Error(`Failed to write chunk ${chunk}`);
566
+ }
567
+ }
568
+ async joinChunks(filePath, chunks) {
569
+ const tmp = path.join(path.dirname(filePath), `tmp_${path.basename(filePath)}`, `${path.basename(filePath)}_chunks.log`);
570
+ for (let i = 1; i <= chunks; i++) {
571
+ const part = path.join(path.dirname(tmp), `${path.parse(filePath).name}.part.${i}`);
572
+ try {
573
+ const data = await fs.promises.readFile(part);
574
+ await fs.promises.appendFile(filePath, data);
575
+ await fs.promises.unlink(part);
576
+ }
577
+ catch (error) {
578
+ throw new Error(`Failed to read/append chunk ${part}`);
579
+ }
580
+ }
581
+ await fs.promises.unlink(tmp);
582
+ await fs.promises.rmdir(path.dirname(tmp));
583
+ }
584
+ async transfer(filePath, destination, device) {
585
+ if (!(await this.exists(filePath))) {
586
+ throw new Error('File Not Found');
587
+ }
588
+ const size = await this.getFileSize(filePath);
589
+ const contentType = await this.getFileMimeType(filePath);
590
+ if (size <= this.transferChunkSize) {
591
+ const source = await this.read(filePath);
592
+ return await device.write(destination, source, contentType);
593
+ }
594
+ const totalChunks = Math.ceil(size / this.transferChunkSize);
595
+ const metadata = { content_type: contentType };
596
+ for (let counter = 0; counter < totalChunks; counter++) {
597
+ const start = counter * this.transferChunkSize;
598
+ const data = await this.read(filePath, start, this.transferChunkSize);
599
+ await device.uploadData(data, destination, contentType, counter + 1, totalChunks, metadata);
600
+ }
601
+ return true;
602
+ }
603
+ async abort(filePath, extra = '') {
604
+ if (await this.exists(filePath)) {
605
+ await fs.promises.unlink(filePath);
606
+ }
607
+ const tmp = path.join(path.dirname(filePath), `tmp_${path.basename(filePath)}`);
608
+ if (!(await this.exists(path.dirname(tmp)))) {
609
+ throw new Error(`File doesn't exist: ${path.dirname(filePath)}`);
610
+ }
611
+ const files = await this.getFiles(tmp);
612
+ for (const file of files) {
613
+ await this.delete(file, true);
614
+ }
615
+ return fs.promises.rmdir(tmp).then(() => true).catch(() => false);
616
+ }
617
+ async read(filePath, offset = 0, length) {
618
+ if (!(await this.exists(filePath))) {
619
+ throw new Error('File Not Found');
620
+ }
621
+ const fileHandle = await fs.promises.open(filePath, 'r');
622
+ try {
623
+ const buffer = Buffer.alloc(length || (await fileHandle.stat()).size - offset);
624
+ await fileHandle.read(buffer, 0, buffer.length, offset);
625
+ return buffer.toString();
626
+ }
627
+ finally {
628
+ await fileHandle.close();
629
+ }
630
+ }
631
+ async write(filePath, data, contentType = '') {
632
+ try {
633
+ await this.createDirectory(path.dirname(filePath));
634
+ await fs.promises.writeFile(filePath, data);
635
+ return true;
636
+ }
637
+ catch (error) {
638
+ throw new Error(`Can't create directory ${path.dirname(filePath)}`);
639
+ }
640
+ }
641
+ async move(source, target) {
642
+ if (source === target) {
643
+ return false;
644
+ }
645
+ try {
646
+ await this.createDirectory(path.dirname(target));
647
+ await fs.promises.rename(source, target);
648
+ return true;
649
+ }
650
+ catch (error) {
651
+ return false;
652
+ }
653
+ }
654
+ async delete(filePath, recursive = false) {
655
+ try {
656
+ const stats = await fs.promises.stat(filePath);
657
+ if (stats.isDirectory() && recursive) {
658
+ const files = await this.getFiles(filePath);
659
+ for (const file of files) {
660
+ await this.delete(file, true);
661
+ }
662
+ await fs.promises.rmdir(filePath);
663
+ }
664
+ else if (stats.isFile() || stats.isSymbolicLink()) {
665
+ await fs.promises.unlink(filePath);
666
+ }
667
+ return true;
668
+ }
669
+ catch (error) {
670
+ return false;
671
+ }
672
+ }
673
+ async deletePath(filePath) {
674
+ const fullPath = path.resolve(path.join(this.getRoot(), filePath));
675
+ try {
676
+ if (!(await this.exists(fullPath))) {
677
+ return false;
678
+ }
679
+ const stats = await fs.promises.stat(fullPath);
680
+ if (!stats.isDirectory()) {
681
+ return false;
682
+ }
683
+ const files = await this.getFiles(fullPath);
684
+ for (const file of files) {
685
+ const stats = await fs.promises.stat(file);
686
+ if (stats.isDirectory()) {
687
+ const relativePath = file.replace(this.getRoot() + path.sep, '');
688
+ await this.deletePath(relativePath);
689
+ }
690
+ else {
691
+ await this.delete(file, true);
692
+ }
693
+ }
694
+ await fs.promises.rmdir(fullPath);
695
+ return true;
696
+ }
697
+ catch (error) {
698
+ return false;
699
+ }
700
+ }
701
+ async exists(filePath) {
702
+ try {
703
+ await fs.promises.access(filePath);
704
+ return true;
705
+ }
706
+ catch {
707
+ return false;
708
+ }
709
+ }
710
+ async getFileSize(filePath) {
711
+ const stats = await fs.promises.stat(filePath);
712
+ return stats.size;
713
+ }
714
+ async getFileMimeType(filePath) {
715
+ // Note: Node.js doesn't have a built-in mime-type detection
716
+ // You might want to use a library like 'mime-types' or 'file-type'
717
+ const ext = path.extname(filePath);
718
+ const mimeTypes = {
719
+ '.txt': 'text/plain',
720
+ '.html': 'text/html',
721
+ '.js': 'application/javascript',
722
+ '.json': 'application/json',
723
+ '.png': 'image/png',
724
+ '.jpg': 'image/jpeg',
725
+ '.jpeg': 'image/jpeg',
726
+ '.gif': 'image/gif'
727
+ };
728
+ return mimeTypes[ext] || 'application/octet-stream';
729
+ }
730
+ async getFileHash(filePath) {
731
+ const data = await fs.promises.readFile(filePath);
732
+ return crypto.createHash('md5').update(data).digest('hex');
733
+ }
734
+ async createDirectory(dirPath) {
735
+ try {
736
+ await fs.promises.mkdir(dirPath, { recursive: true, mode: 0o755 });
737
+ return true;
738
+ }
739
+ catch (error) {
740
+ return false;
741
+ }
742
+ }
743
+ async getDirectorySize(dirPath) {
744
+ try {
745
+ let size = 0;
746
+ const files = await fs.promises.readdir(dirPath, { withFileTypes: true });
747
+ for (const file of files) {
748
+ if (file.name.startsWith('.'))
749
+ continue;
750
+ const fullPath = path.join(dirPath, file.name);
751
+ if (file.isDirectory()) {
752
+ size += await this.getDirectorySize(fullPath);
753
+ }
754
+ else {
755
+ const stats = await fs.promises.stat(fullPath);
756
+ size += stats.size;
757
+ }
758
+ }
759
+ return size;
760
+ }
761
+ catch (error) {
762
+ return -1;
763
+ }
764
+ }
765
+ async getPartitionFreeSpace() {
766
+ const stats = await fs.promises.statfs(this.getRoot());
767
+ return stats.bavail * stats.bsize;
768
+ }
769
+ async getPartitionTotalSpace() {
770
+ const stats = await fs.promises.statfs(this.getRoot());
771
+ return stats.blocks * stats.bsize;
772
+ }
773
+ async getFiles(dir, max = this.MAX_PAGE_SIZE, continuationToken = '') {
774
+ const files = [];
775
+ try {
776
+ const entries = await fs.promises.readdir(dir, { withFileTypes: true });
777
+ for (const entry of entries) {
778
+ files.push(path.join(dir, entry.name));
779
+ }
780
+ return files;
781
+ }
782
+ catch (error) {
783
+ return [];
784
+ }
785
+ }
786
+ }
787
+
788
+ class S3 extends Device {
789
+ constructor(root, accessKey, secretKey, bucket, region = S3.US_EAST_1, acl = S3.ACL_PRIVATE, endpointUrl = '') {
790
+ super();
791
+ this.acl = S3.ACL_PRIVATE;
792
+ this.root = 'temp';
793
+ this.headers = {
794
+ 'host': '',
795
+ 'date': '',
796
+ 'content-md5': '',
797
+ 'content-type': '',
798
+ };
799
+ this.accessKey = accessKey;
800
+ this.secretKey = secretKey;
801
+ this.bucket = bucket;
802
+ this.region = region;
803
+ this.root = root;
804
+ this.acl = acl;
805
+ this.amzHeaders = {};
806
+ let host;
807
+ if (endpointUrl) {
808
+ host = `${bucket}.${endpointUrl}`;
809
+ }
810
+ else {
811
+ switch (region) {
812
+ case S3.CN_NORTH_1:
813
+ case S3.CN_NORTH_4:
814
+ case S3.CN_NORTHWEST_1:
815
+ host = `${bucket}.s3.${region}.amazonaws.cn`;
816
+ break;
817
+ default:
818
+ host = `${bucket}.s3.${region}.amazonaws.com`;
819
+ }
820
+ }
821
+ this.headers['host'] = host;
822
+ }
823
+ getName() {
824
+ return 'S3 Storage';
825
+ }
826
+ getType() {
827
+ return Storage.DEVICE_S3;
828
+ }
829
+ getDescription() {
830
+ return 'S3 Bucket Storage drive for AWS or on premise solution';
831
+ }
832
+ getRoot() {
833
+ return this.root;
834
+ }
835
+ getPath(filename, prefix) {
836
+ return `${this.getRoot()}/${filename}`;
837
+ }
838
+ getPartitionTotalSpace() {
839
+ throw new Error("Method not implemented.");
840
+ }
841
+ static setRetryAttempts(attempts) {
842
+ S3.retryAttempts = attempts;
843
+ }
844
+ static setRetryDelay(delay) {
845
+ S3.retryDelay = delay;
846
+ }
847
+ async upload(source, path, chunk = 1, chunks = 1, metadata = {}) {
848
+ let data;
849
+ let contentType;
850
+ if (typeof source === 'string') {
851
+ const fs = await import('fs');
852
+ const fileData = await fs.promises.readFile(source);
853
+ data = fileData.toString();
854
+ contentType = await this.getMimeType(source);
855
+ }
856
+ else {
857
+ data = source.toString();
858
+ contentType = metadata.contentType || 'application/octet-stream';
859
+ }
860
+ return this.uploadData(data, path, contentType, chunk, chunks, metadata);
861
+ }
862
+ async uploadData(data, path, contentType, chunk = 1, chunks = 1, metadata = {}) {
863
+ if (chunk === 1 && chunks === 1) {
864
+ await this.write(path, data, contentType);
865
+ return 1;
866
+ }
867
+ let uploadId = metadata['uploadId'];
868
+ if (!uploadId) {
869
+ uploadId = await this.createMultipartUpload(path, contentType);
870
+ metadata['uploadId'] = uploadId;
871
+ }
872
+ metadata['parts'] = metadata['parts'] || {};
873
+ metadata['chunks'] = metadata['chunks'] || 0;
874
+ const etag = await this.uploadPart(data, path, contentType, chunk, uploadId);
875
+ if (!(chunk in metadata['parts'])) {
876
+ metadata['chunks']++;
877
+ }
878
+ metadata['parts'][chunk] = etag;
879
+ if (metadata['chunks'] === chunks) {
880
+ await this.completeMultipartUpload(path, uploadId, metadata['parts']);
881
+ }
882
+ return metadata['chunks'];
883
+ }
884
+ async transfer(path, destination, device) {
885
+ try {
886
+ const response = await this.getInfo(path);
887
+ const size = parseInt(response['content-length'] || '0');
888
+ const contentType = response['content-type'] || '';
889
+ if (size <= this.transferChunkSize) {
890
+ const source = await this.read(path);
891
+ return device.write(destination, source, contentType);
892
+ }
893
+ const totalChunks = Math.ceil(size / this.transferChunkSize);
894
+ const metadata = { content_type: contentType };
895
+ for (let counter = 0; counter < totalChunks; counter++) {
896
+ const start = counter * this.transferChunkSize;
897
+ const data = await this.read(path, start, this.transferChunkSize);
898
+ await device.uploadData(data, destination, contentType, counter + 1, totalChunks, metadata);
899
+ }
900
+ return true;
901
+ }
902
+ catch (e) {
903
+ throw new Error('File not found');
904
+ }
905
+ }
906
+ async createMultipartUpload(path, contentType) {
907
+ const uri = path !== '' ? `/${encodeURIComponent(path).replace(/%2F/g, '/').replace(/%3F/g, '?')}` : '/';
908
+ this.headers['content-md5'] = Buffer.from(this.md5('')).toString('base64');
909
+ delete this.amzHeaders['x-amz-content-sha256'];
910
+ this.headers['content-type'] = contentType;
911
+ this.amzHeaders['x-amz-acl'] = this.acl;
912
+ const response = await this.call(S3.METHOD_POST, uri, '', { uploads: '' });
913
+ return response.body['UploadId'];
914
+ }
915
+ async uploadPart(data, path, contentType, chunk, uploadId) {
916
+ const uri = path !== '' ? `/${encodeURIComponent(path).replace(/%2F/g, '/').replace(/%3F/g, '?')}` : '/';
917
+ this.headers['content-type'] = contentType;
918
+ this.headers['content-md5'] = Buffer.from(this.md5(data)).toString('base64');
919
+ this.amzHeaders['x-amz-content-sha256'] = this.sha256(data);
920
+ delete this.amzHeaders['x-amz-acl'];
921
+ const response = await this.call(S3.METHOD_PUT, uri, data, {
922
+ partNumber: chunk.toString(),
923
+ uploadId: uploadId,
924
+ });
925
+ return response.headers['etag'];
926
+ }
927
+ async completeMultipartUpload(path, uploadId, parts) {
928
+ const uri = path !== '' ? `/${encodeURIComponent(path).replace(/%2F/g, '/').replace(/%3F/g, '?')}` : '/';
929
+ let body = '<CompleteMultipartUpload>';
930
+ for (const [key, etag] of Object.entries(parts)) {
931
+ body += `<Part><ETag>${etag}</ETag><PartNumber>${key}</PartNumber></Part>`;
932
+ }
933
+ body += '</CompleteMultipartUpload>';
934
+ this.amzHeaders['x-amz-content-sha256'] = this.sha256(body);
935
+ this.headers['content-md5'] = Buffer.from(this.md5(body)).toString('base64');
936
+ await this.call(S3.METHOD_POST, uri, body, { uploadId });
937
+ return true;
938
+ }
939
+ async abort(path, extra = '') {
940
+ const uri = path !== '' ? `/${encodeURIComponent(path).replace(/%2F/g, '/')}` : '/';
941
+ delete this.headers['content-type'];
942
+ this.headers['content-md5'] = Buffer.from(this.md5('')).toString('base64');
943
+ await this.call(S3.METHOD_DELETE, uri, '', { uploadId: extra });
944
+ return true;
945
+ }
946
+ async read(path, offset = 0, length) {
947
+ delete this.amzHeaders['x-amz-acl'];
948
+ delete this.amzHeaders['x-amz-content-sha256'];
949
+ delete this.headers['content-type'];
950
+ this.headers['content-md5'] = Buffer.from(this.md5('')).toString('base64');
951
+ const uri = path !== '' ? `/${encodeURIComponent(path).replace(/%2F/g, '/')}` : '/';
952
+ if (length !== undefined) {
953
+ const end = offset + length - 1;
954
+ this.headers['range'] = `bytes=${offset}-${end}`;
955
+ }
956
+ const response = await this.call(S3.METHOD_GET, uri, '', {}, false);
957
+ return response.body;
958
+ }
959
+ async write(path, data, contentType = '') {
960
+ const uri = path !== '' ? `/${encodeURIComponent(path).replace(/%2F/g, '/').replace(/%3F/g, '?')}` : '/';
961
+ this.headers['content-type'] = contentType;
962
+ this.headers['content-md5'] = Buffer.from(this.md5(data)).toString('base64');
963
+ this.amzHeaders['x-amz-content-sha256'] = this.sha256(data);
964
+ this.amzHeaders['x-amz-acl'] = this.acl;
965
+ await this.call(S3.METHOD_PUT, uri, data);
966
+ return true;
967
+ }
968
+ async delete(path, recursive = false) {
969
+ const uri = path !== '' ? `/${encodeURIComponent(path).replace(/%2F/g, '/')}` : '/';
970
+ delete this.headers['content-type'];
971
+ delete this.amzHeaders['x-amz-acl'];
972
+ delete this.amzHeaders['x-amz-content-sha256'];
973
+ this.headers['content-md5'] = Buffer.from(this.md5('')).toString('base64');
974
+ await this.call(S3.METHOD_DELETE, uri);
975
+ return true;
976
+ }
977
+ async listObjects(prefix = '', maxKeys = S3.MAX_PAGE_SIZE, continuationToken = '') {
978
+ if (maxKeys > S3.MAX_PAGE_SIZE) {
979
+ throw new Error(`Cannot list more than ${S3.MAX_PAGE_SIZE} objects`);
980
+ }
981
+ const uri = '/';
982
+ prefix = prefix.replace(/^\//, '');
983
+ this.headers['content-type'] = 'text/plain';
984
+ this.headers['content-md5'] = Buffer.from(this.md5('')).toString('base64');
985
+ delete this.amzHeaders['x-amz-content-sha256'];
986
+ delete this.amzHeaders['x-amz-acl'];
987
+ const parameters = {
988
+ 'list-type': '2',
989
+ 'prefix': prefix,
990
+ 'max-keys': maxKeys.toString(),
991
+ };
992
+ if (continuationToken) {
993
+ parameters['continuation-token'] = continuationToken;
994
+ }
995
+ const response = await this.call(S3.METHOD_GET, uri, '', parameters);
996
+ return response.body;
997
+ }
998
+ async deletePath(path) {
999
+ path = `${this.getRoot()}/${path}`;
1000
+ const uri = '/';
1001
+ let continuationToken = '';
1002
+ do {
1003
+ const objects = await this.listObjects(path, S3.MAX_PAGE_SIZE, continuationToken);
1004
+ const count = parseInt(objects['KeyCount'] || '1');
1005
+ if (count < 1)
1006
+ break;
1007
+ continuationToken = objects['NextContinuationToken'] || '';
1008
+ let body = '<Delete xmlns="http://s3.amazonaws.com/doc/2006-03-01/">';
1009
+ if (count > 1) {
1010
+ for (const object of objects['Contents']) {
1011
+ body += `<Object><Key>${object['Key']}</Key></Object>`;
1012
+ }
1013
+ }
1014
+ else {
1015
+ body += `<Object><Key>${objects['Contents']['Key']}</Key></Object>`;
1016
+ }
1017
+ body += '<Quiet>true</Quiet></Delete>';
1018
+ this.amzHeaders['x-amz-content-sha256'] = this.sha256(body);
1019
+ this.headers['content-md5'] = Buffer.from(this.md5(body)).toString('base64');
1020
+ await this.call(S3.METHOD_POST, uri, body, { delete: '' });
1021
+ } while (continuationToken);
1022
+ return true;
1023
+ }
1024
+ async exists(path) {
1025
+ try {
1026
+ await this.getInfo(path);
1027
+ return true;
1028
+ }
1029
+ catch {
1030
+ return false;
1031
+ }
1032
+ }
1033
+ async getFileSize(path) {
1034
+ const response = await this.getInfo(path);
1035
+ return parseInt(response['content-length'] || '0');
1036
+ }
1037
+ async getFileMimeType(path) {
1038
+ const response = await this.getInfo(path);
1039
+ return response['content-type'] || '';
1040
+ }
1041
+ async getFileHash(path) {
1042
+ const etag = (await this.getInfo(path))['etag'] || '';
1043
+ return etag ? etag.slice(1, -1) : etag;
1044
+ }
1045
+ async createDirectory(path) {
1046
+ return true; // S3 doesn't have directories
1047
+ }
1048
+ async getDirectorySize(path) {
1049
+ return -1;
1050
+ }
1051
+ async getPartitionFreeSpace() {
1052
+ return -1;
1053
+ }
1054
+ async getFiles(dir, max = S3.MAX_PAGE_SIZE, continuationToken = '') {
1055
+ const data = await this.listObjects(dir, max, continuationToken);
1056
+ data['IsTruncated'] = data['IsTruncated'] === 'true';
1057
+ data['KeyCount'] = parseInt(data['KeyCount']);
1058
+ data['MaxKeys'] = parseInt(data['MaxKeys']);
1059
+ return data;
1060
+ }
1061
+ async getInfo(path) {
1062
+ delete this.headers['content-type'];
1063
+ delete this.amzHeaders['x-amz-acl'];
1064
+ delete this.amzHeaders['x-amz-content-sha256'];
1065
+ this.headers['content-md5'] = Buffer.from(this.md5('')).toString('base64');
1066
+ const uri = path !== '' ? `/${encodeURIComponent(path).replace(/%2F/g, '/')}` : '/';
1067
+ const response = await this.call(S3.METHOD_HEAD, uri);
1068
+ return response.headers;
1069
+ }
1070
+ getSignatureV4(method, uri, parameters = {}) {
1071
+ const service = 's3';
1072
+ const region = this.region;
1073
+ const algorithm = 'AWS4-HMAC-SHA256';
1074
+ const combinedHeaders = {};
1075
+ const amzDateStamp = this.amzHeaders['x-amz-date'].substring(0, 8);
1076
+ // Combine headers
1077
+ for (const [k, v] of Object.entries(this.headers)) {
1078
+ combinedHeaders[k.toLowerCase()] = v.trim();
1079
+ }
1080
+ for (const [k, v] of Object.entries(this.amzHeaders)) {
1081
+ combinedHeaders[k.toLowerCase()] = v.trim();
1082
+ }
1083
+ // Sort headers
1084
+ const sortedHeaders = Object.keys(combinedHeaders).sort();
1085
+ const sortedCombinedHeaders = {};
1086
+ for (const key of sortedHeaders) {
1087
+ sortedCombinedHeaders[key] = combinedHeaders[key];
1088
+ }
1089
+ // Sort parameters
1090
+ const sortedParams = Object.keys(parameters).sort();
1091
+ const queryString = sortedParams.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(parameters[key])}`).join('&');
1092
+ // Create canonical request
1093
+ const canonicalRequest = [
1094
+ method,
1095
+ uri.split('?')[0],
1096
+ queryString,
1097
+ ...Object.entries(sortedCombinedHeaders).map(([k, v]) => `${k}:${v}`),
1098
+ '',
1099
+ Object.keys(sortedCombinedHeaders).join(';'),
1100
+ this.amzHeaders['x-amz-content-sha256']
1101
+ ].join('\n');
1102
+ // Create string to sign
1103
+ const credentialScope = [amzDateStamp, region, service, 'aws4_request'].join('/');
1104
+ const stringToSign = [
1105
+ algorithm,
1106
+ this.amzHeaders['x-amz-date'],
1107
+ credentialScope,
1108
+ this.sha256(canonicalRequest)
1109
+ ].join('\n');
1110
+ // Calculate signature
1111
+ const kSecret = `AWS4${this.secretKey}`;
1112
+ const kDate = this.hmacSha256(amzDateStamp, kSecret);
1113
+ const kRegion = this.hmacSha256(region, kDate);
1114
+ const kService = this.hmacSha256(service, kRegion);
1115
+ const kSigning = this.hmacSha256('aws4_request', kService);
1116
+ const signature = this.hmacSha256(stringToSign, kSigning, 'hex');
1117
+ return `${algorithm} Credential=${this.accessKey}/${credentialScope},SignedHeaders=${Object.keys(sortedCombinedHeaders).join(';')},Signature=${signature}`;
1118
+ }
1119
+ async call(method, uri, data = '', parameters = {}, decode = true) {
1120
+ await import('crypto');
1121
+ uri = this.getAbsolutePath(uri);
1122
+ const queryString = Object.keys(parameters).length ? '?' + Object.entries(parameters).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join('&') : '';
1123
+ const url = `https://${this.headers['host']}${uri}${queryString}`;
1124
+ this.amzHeaders['x-amz-date'] = new Date().toISOString().replace(/[:-]|\.\d{3}/g, '');
1125
+ if (!this.amzHeaders['x-amz-content-sha256']) {
1126
+ this.amzHeaders['x-amz-content-sha256'] = this.sha256(data);
1127
+ }
1128
+ const headers = {};
1129
+ for (const [header, value] of Object.entries(this.amzHeaders)) {
1130
+ if (value.length > 0) {
1131
+ headers[header] = value;
1132
+ }
1133
+ }
1134
+ this.headers['date'] = new Date().toUTCString();
1135
+ for (const [header, value] of Object.entries(this.headers)) {
1136
+ if (value.length > 0) {
1137
+ headers[header] = value;
1138
+ }
1139
+ }
1140
+ headers['Authorization'] = this.getSignatureV4(method, uri, parameters);
1141
+ const fetchOptions = {
1142
+ method,
1143
+ headers,
1144
+ };
1145
+ if (method === S3.METHOD_PUT || method === S3.METHOD_POST) {
1146
+ fetchOptions.body = data;
1147
+ }
1148
+ const response = await fetch(url, fetchOptions);
1149
+ if (!response.ok) {
1150
+ const errorBody = await response.text();
1151
+ throw new Error(`HTTP ${response.status}: ${errorBody}`);
1152
+ }
1153
+ const responseHeaders = {};
1154
+ response.headers.forEach((value, key) => {
1155
+ responseHeaders[key.toLowerCase()] = value;
1156
+ });
1157
+ let body = await response.text();
1158
+ if (decode && (responseHeaders['content-type'] === 'application/xml' || (body.startsWith('<?xml') && responseHeaders['content-type'] !== 'image/svg+xml'))) {
1159
+ const xml2js = await import('xml2js');
1160
+ const parser = new xml2js.Parser();
1161
+ body = await parser.parseStringPromise(body);
1162
+ }
1163
+ return {
1164
+ body,
1165
+ headers: responseHeaders,
1166
+ code: response.status
1167
+ };
1168
+ }
1169
+ md5(data) {
1170
+ return crypto.createHash('md5').update(data).digest();
1171
+ }
1172
+ sha256(data) {
1173
+ return crypto.createHash('sha256').update(data).digest('hex');
1174
+ }
1175
+ hmacSha256(data, key, encoding = 'binary') {
1176
+ const hmac = crypto.createHmac('sha256', key);
1177
+ hmac.update(data);
1178
+ return encoding === 'hex' ? hmac.digest('hex') : hmac.digest();
1179
+ }
1180
+ }
1181
+ // HTTP Methods
1182
+ S3.METHOD_GET = 'GET';
1183
+ S3.METHOD_POST = 'POST';
1184
+ S3.METHOD_PUT = 'PUT';
1185
+ S3.METHOD_PATCH = 'PATCH';
1186
+ S3.METHOD_DELETE = 'DELETE';
1187
+ S3.METHOD_HEAD = 'HEAD';
1188
+ S3.METHOD_OPTIONS = 'OPTIONS';
1189
+ S3.METHOD_CONNECT = 'CONNECT';
1190
+ S3.METHOD_TRACE = 'TRACE';
1191
+ // AWS Regions
1192
+ S3.US_EAST_1 = 'us-east-1';
1193
+ S3.US_EAST_2 = 'us-east-2';
1194
+ S3.US_WEST_1 = 'us-west-1';
1195
+ S3.US_WEST_2 = 'us-west-2';
1196
+ S3.AF_SOUTH_1 = 'af-south-1';
1197
+ S3.AP_EAST_1 = 'ap-east-1';
1198
+ S3.AP_SOUTH_1 = 'ap-south-1';
1199
+ S3.AP_NORTHEAST_3 = 'ap-northeast-3';
1200
+ S3.AP_NORTHEAST_2 = 'ap-northeast-2';
1201
+ S3.AP_NORTHEAST_1 = 'ap-northeast-1';
1202
+ S3.AP_SOUTHEAST_1 = 'ap-southeast-1';
1203
+ S3.AP_SOUTHEAST_2 = 'ap-southeast-2';
1204
+ S3.CA_CENTRAL_1 = 'ca-central-1';
1205
+ S3.EU_CENTRAL_1 = 'eu-central-1';
1206
+ S3.EU_WEST_1 = 'eu-west-1';
1207
+ S3.EU_SOUTH_1 = 'eu-south-1';
1208
+ S3.EU_WEST_2 = 'eu-west-2';
1209
+ S3.EU_WEST_3 = 'eu-west-3';
1210
+ S3.EU_NORTH_1 = 'eu-north-1';
1211
+ S3.SA_EAST_1 = 'eu-north-1';
1212
+ S3.CN_NORTH_1 = 'cn-north-1';
1213
+ S3.CN_NORTH_4 = 'cn-north-4';
1214
+ S3.CN_NORTHWEST_1 = 'cn-northwest-1';
1215
+ S3.ME_SOUTH_1 = 'me-south-1';
1216
+ S3.US_GOV_EAST_1 = 'us-gov-east-1';
1217
+ S3.US_GOV_WEST_1 = 'us-gov-west-1';
1218
+ // ACL Flags
1219
+ S3.ACL_PRIVATE = 'private';
1220
+ S3.ACL_PUBLIC_READ = 'public-read';
1221
+ S3.ACL_PUBLIC_READ_WRITE = 'public-read-write';
1222
+ S3.ACL_AUTHENTICATED_READ = 'authenticated-read';
1223
+ S3.MAX_PAGE_SIZE = 1000;
1224
+ S3.retryAttempts = 3;
1225
+ S3.retryDelay = 500;
1226
+
1227
+ class Wasabi extends S3 {
1228
+ /**
1229
+ * Wasabi Constructor
1230
+ */
1231
+ constructor(root, accessKey, secretKey, bucket, region = Wasabi.EU_CENTRAL_1, acl = S3.ACL_PRIVATE) {
1232
+ super(root, accessKey, secretKey, bucket, region, acl);
1233
+ this.headers['host'] = `${bucket}.s3.${region}.wasabisys.com`;
1234
+ }
1235
+ getName() {
1236
+ return 'Wasabi Storage';
1237
+ }
1238
+ getDescription() {
1239
+ return 'Wasabi Storage';
1240
+ }
1241
+ getType() {
1242
+ return Storage.DEVICE_WASABI;
1243
+ }
1244
+ }
1245
+ /**
1246
+ * Regions constants
1247
+ */
1248
+ Wasabi.US_WEST_1 = 'us-west-1';
1249
+ Wasabi.AP_NORTHEAST_1 = 'ap-northeast-1';
1250
+ Wasabi.AP_NORTHEAST_2 = 'ap-northeast-2';
1251
+ Wasabi.EU_CENTRAL_1 = 'eu-central-1';
1252
+ Wasabi.EU_CENTRAL_2 = 'eu-central-2';
1253
+ Wasabi.EU_WEST_1 = 'eu-west-1';
1254
+ Wasabi.EU_WEST_2 = 'eu-west-2';
1255
+ Wasabi.US_CENTRAL_1 = 'us-central-1';
1256
+ Wasabi.US_EAST_1 = 'us-east-1';
1257
+ Wasabi.US_EAST_2 = 'us-east-2';
1258
+
1259
+ exports.Device = Device;
1260
+ exports.File = File;
1261
+ exports.FileExt = FileExt;
1262
+ exports.FileName = FileName;
1263
+ exports.FileSize = FileSize;
1264
+ exports.FileType = FileType;
1265
+ exports.Local = Local;
1266
+ exports.S3 = S3;
1267
+ exports.Storage = Storage;
1268
+ exports.Upload = Upload;
1269
+ exports.Wasabi = Wasabi;
1270
+ //# sourceMappingURL=index.cjs.js.map