@arkstack/filesystem 0.12.22 → 0.12.24
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/index.d.ts
CHANGED
|
@@ -76,10 +76,11 @@ interface FilesystemConfig {
|
|
|
76
76
|
}
|
|
77
77
|
//#endregion
|
|
78
78
|
//#region src/Storage.d.ts
|
|
79
|
-
declare class Storage implements DriverContract {
|
|
79
|
+
declare class Storage<D extends keyof KnownDisks | keyof CustomDiskDriverRegistry = keyof KnownDisks | keyof CustomDiskDriverRegistry> implements DriverContract {
|
|
80
80
|
driver: DriveManager<any>;
|
|
81
81
|
services: Record<string, () => DriverContract>;
|
|
82
|
-
diskName:
|
|
82
|
+
diskName: D;
|
|
83
|
+
driverName: FilesystemConfig['disks'][D]['driver'];
|
|
83
84
|
constructor();
|
|
84
85
|
/**
|
|
85
86
|
* Static method to get a disk instance directly from the Storage class without needing to instantiate it first.
|
|
@@ -87,7 +88,7 @@ declare class Storage implements DriverContract {
|
|
|
87
88
|
* @param diskName The name of the disk to use. If not provided, the default disk will be used.
|
|
88
89
|
* @returns A Storage instance
|
|
89
90
|
*/
|
|
90
|
-
static disk<K extends
|
|
91
|
+
static disk<K extends keyof KnownDisks | keyof CustomDiskDriverRegistry>(diskName?: K): Storage<K>;
|
|
91
92
|
/**
|
|
92
93
|
* Generate a unique name for the file based on random numbers and original extension
|
|
93
94
|
*
|
|
@@ -118,85 +119,166 @@ declare class Storage implements DriverContract {
|
|
|
118
119
|
saveFile: (file: FileLike, filePath?: string, fileName?: string) => Promise<[string, string]>;
|
|
119
120
|
/**
|
|
120
121
|
* Return a boolean indicating if the file exists
|
|
122
|
+
*
|
|
123
|
+
* @param key
|
|
124
|
+
* @returns
|
|
121
125
|
*/
|
|
122
126
|
exists(key: string): Promise<boolean>;
|
|
123
127
|
/**
|
|
124
128
|
* Return contents of a object for the given key as a UTF-8 string.
|
|
125
129
|
* Should throw "E_CANNOT_READ_FILE" error when the file
|
|
126
130
|
* does not exists.
|
|
131
|
+
*
|
|
132
|
+
* @param key
|
|
133
|
+
* @returns
|
|
127
134
|
*/
|
|
128
135
|
get(key: string): Promise<string>;
|
|
136
|
+
/**
|
|
137
|
+
* Get the name of the disk currently in use.
|
|
138
|
+
*
|
|
139
|
+
* @returns
|
|
140
|
+
*/
|
|
141
|
+
getDiskName(): D;
|
|
142
|
+
/**
|
|
143
|
+
* Get the name of the driver currently in use.
|
|
144
|
+
*
|
|
145
|
+
* @returns
|
|
146
|
+
*/
|
|
147
|
+
getDriverName(): (KnownDisks & CustomDiskDriverRegistry)[D]["driver"];
|
|
148
|
+
/**
|
|
149
|
+
* Get the driver currently in use.
|
|
150
|
+
*
|
|
151
|
+
* @returns
|
|
152
|
+
*/
|
|
153
|
+
getDriver(): DriveManager<any>;
|
|
129
154
|
/**
|
|
130
155
|
* Return contents of a object for the given key as a Readable stream.
|
|
131
156
|
* Should throw "E_CANNOT_READ_FILE" error when the file
|
|
132
157
|
* does not exists.
|
|
158
|
+
*
|
|
159
|
+
* @param key
|
|
160
|
+
* @returns
|
|
133
161
|
*/
|
|
134
162
|
getStream(key: string): Promise<Readable>;
|
|
135
163
|
/**
|
|
136
164
|
* Return contents of an object for the given key as an Uint8Array.
|
|
137
165
|
* Should throw "E_CANNOT_READ_FILE" error when the file
|
|
138
166
|
* does not exists.
|
|
167
|
+
*
|
|
168
|
+
* @param key
|
|
169
|
+
* @returns
|
|
139
170
|
*/
|
|
140
171
|
getBytes(key: string): Promise<Uint8Array>;
|
|
141
172
|
/**
|
|
142
173
|
* Return metadata of an object for the given key.
|
|
174
|
+
*
|
|
175
|
+
* @param key
|
|
176
|
+
* @returns
|
|
143
177
|
*/
|
|
144
178
|
getMetaData(key: string): Promise<ObjectMetaData>;
|
|
145
179
|
/**
|
|
146
180
|
* Return the visibility of the file
|
|
181
|
+
*
|
|
182
|
+
* @param key
|
|
183
|
+
* @returns
|
|
147
184
|
*/
|
|
148
185
|
getVisibility(key: string): Promise<ObjectVisibility>;
|
|
149
186
|
/**
|
|
150
187
|
* Return the public URL to access the file
|
|
188
|
+
*
|
|
189
|
+
* @param key
|
|
190
|
+
* @returns
|
|
151
191
|
*/
|
|
152
192
|
getUrl(key: string): Promise<string>;
|
|
153
193
|
/**
|
|
154
194
|
* Return the signed/temporary URL to access the file
|
|
195
|
+
*
|
|
196
|
+
* @param key
|
|
197
|
+
* @param options
|
|
198
|
+
* @returns
|
|
155
199
|
*/
|
|
156
200
|
getSignedUrl(key: string, options?: SignedURLOptions): Promise<string>;
|
|
157
201
|
/**
|
|
158
202
|
* Return the signed/temporary URL that can be used to directly upload
|
|
159
203
|
* the file contents to the storage.
|
|
204
|
+
*
|
|
205
|
+
* @param key
|
|
206
|
+
* @param options
|
|
207
|
+
* @returns
|
|
160
208
|
*/
|
|
161
209
|
getSignedUploadUrl(key: string, options?: SignedURLOptions): Promise<string>;
|
|
162
210
|
/**
|
|
163
211
|
* Update the visibility of the file
|
|
212
|
+
*
|
|
213
|
+
* @param key
|
|
214
|
+
* @param visibility
|
|
215
|
+
* @returns
|
|
164
216
|
*/
|
|
165
217
|
setVisibility(key: string, visibility: ObjectVisibility): Promise<void>;
|
|
166
218
|
/**
|
|
167
219
|
* Write object to the destination with the provided
|
|
168
220
|
* contents.
|
|
221
|
+
*
|
|
222
|
+
* @param key
|
|
223
|
+
* @param contents
|
|
224
|
+
* @param options
|
|
225
|
+
* @returns
|
|
169
226
|
*/
|
|
170
227
|
put(key: string, contents: string | Uint8Array | FileLike, options?: WriteOptions): Promise<void>;
|
|
171
228
|
/**
|
|
172
229
|
* Write object to the destination with the provided
|
|
173
230
|
* contents as a readable stream
|
|
231
|
+
*
|
|
232
|
+
* @param key
|
|
233
|
+
* @param contents
|
|
234
|
+
* @param options
|
|
235
|
+
* @returns
|
|
174
236
|
*/
|
|
175
237
|
putStream(key: string, contents: Readable, options?: WriteOptions): Promise<void>;
|
|
176
238
|
/**
|
|
177
239
|
* Copy the file from within the disk root location. Both
|
|
178
240
|
* the "source" and "destination" will be the key names
|
|
179
241
|
* and not absolute paths.
|
|
242
|
+
*
|
|
243
|
+
* @param source
|
|
244
|
+
* @param destination
|
|
245
|
+
* @param options
|
|
246
|
+
* @returns
|
|
180
247
|
*/
|
|
181
248
|
copy(source: string, destination: string, options?: WriteOptions): Promise<void>;
|
|
182
249
|
/**
|
|
183
250
|
* Move the file from within the disk root location. Both
|
|
184
251
|
* the "source" and "destination" will be the key names
|
|
185
252
|
* and not absolute paths.
|
|
253
|
+
*
|
|
254
|
+
* @param source
|
|
255
|
+
* @param destination
|
|
256
|
+
* @param options
|
|
257
|
+
* @returns
|
|
186
258
|
*/
|
|
187
259
|
move(source: string, destination: string, options?: WriteOptions): Promise<void>;
|
|
188
260
|
/**
|
|
189
261
|
* Delete the file for the given key. Should not throw
|
|
190
262
|
* error when file does not exist in first place
|
|
263
|
+
*
|
|
264
|
+
* @param key
|
|
265
|
+
* @returns
|
|
191
266
|
*/
|
|
192
267
|
delete(key: string): Promise<void>;
|
|
193
268
|
/**
|
|
194
269
|
* Delete the files and directories matching the provided prefix.
|
|
270
|
+
*
|
|
271
|
+
* @param prefix
|
|
272
|
+
* @returns
|
|
195
273
|
*/
|
|
196
274
|
deleteAll(prefix: string): Promise<void>;
|
|
197
275
|
/**
|
|
198
276
|
* The list all method must return an array of objects with
|
|
199
277
|
* the ability to paginate results (if supported).
|
|
278
|
+
*
|
|
279
|
+
* @param prefix
|
|
280
|
+
* @param options
|
|
281
|
+
* @returns
|
|
200
282
|
*/
|
|
201
283
|
listAll(prefix: string, options?: {
|
|
202
284
|
recursive?: boolean;
|
|
@@ -207,10 +289,15 @@ declare class Storage implements DriverContract {
|
|
|
207
289
|
}>;
|
|
208
290
|
/**
|
|
209
291
|
* Switch bucket at runtime if supported.
|
|
292
|
+
*
|
|
293
|
+
* @param bucket
|
|
294
|
+
* @returns
|
|
210
295
|
*/
|
|
211
296
|
bucket(bucket: string): DriverContract;
|
|
212
297
|
/**
|
|
213
298
|
* Create symbolic links for all configured links in the application configuration.
|
|
299
|
+
*
|
|
300
|
+
* @param param0
|
|
214
301
|
*/
|
|
215
302
|
static link({
|
|
216
303
|
force
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as FtpDriver, t as Storage } from "./src-
|
|
1
|
+
import { n as FtpDriver, t as Storage } from "./src-DX_iPdpM.js";
|
|
2
2
|
export { FtpDriver, Storage };
|
|
@@ -327,12 +327,14 @@ var Storage = class Storage {
|
|
|
327
327
|
driver;
|
|
328
328
|
services = {};
|
|
329
329
|
diskName;
|
|
330
|
+
driverName;
|
|
330
331
|
constructor() {
|
|
331
332
|
const disks = Object.entries(config("filesystem.disks", {}));
|
|
332
333
|
const customDrivers = config("filesystem.custom_drivers", {});
|
|
333
334
|
for (const [name, driver] of Object.entries(customDrivers)) Driver.registerDriver(name, driver);
|
|
334
335
|
for (const [disk, config] of disks) this.services[disk] = () => Driver.make(config);
|
|
335
336
|
this.diskName = config("filesystem.default");
|
|
337
|
+
this.driverName = config(`filesystem.disks.${this.diskName}.driver`);
|
|
336
338
|
this.driver = new DriveManager({
|
|
337
339
|
default: config("filesystem.default"),
|
|
338
340
|
services: this.services
|
|
@@ -348,6 +350,7 @@ var Storage = class Storage {
|
|
|
348
350
|
const storage = new Storage();
|
|
349
351
|
if (diskName) {
|
|
350
352
|
storage.diskName = diskName;
|
|
353
|
+
storage.driverName = config(`filesystem.disks.${diskName}.driver`);
|
|
351
354
|
storage.driver = new DriveManager({
|
|
352
355
|
default: diskName,
|
|
353
356
|
services: storage.services
|
|
@@ -391,10 +394,13 @@ var Storage = class Storage {
|
|
|
391
394
|
if (file instanceof File && !file.buffer) file.buffer = Buffer.from(await file.arrayBuffer());
|
|
392
395
|
await drive.put(path.join(filePath, name), file.buffer);
|
|
393
396
|
const url = await drive.getUrl(path.join(filePath, name));
|
|
394
|
-
return [url, this.
|
|
397
|
+
return [url, this.driverName === "local" ? path.join(filePath, name) : url];
|
|
395
398
|
};
|
|
396
399
|
/**
|
|
397
400
|
* Return a boolean indicating if the file exists
|
|
401
|
+
*
|
|
402
|
+
* @param key
|
|
403
|
+
* @returns
|
|
398
404
|
*/
|
|
399
405
|
exists(key) {
|
|
400
406
|
return this.driver.use().exists(key);
|
|
@@ -403,14 +409,44 @@ var Storage = class Storage {
|
|
|
403
409
|
* Return contents of a object for the given key as a UTF-8 string.
|
|
404
410
|
* Should throw "E_CANNOT_READ_FILE" error when the file
|
|
405
411
|
* does not exists.
|
|
412
|
+
*
|
|
413
|
+
* @param key
|
|
414
|
+
* @returns
|
|
406
415
|
*/
|
|
407
416
|
get(key) {
|
|
408
417
|
return this.driver.use().get(key);
|
|
409
418
|
}
|
|
410
419
|
/**
|
|
420
|
+
* Get the name of the disk currently in use.
|
|
421
|
+
*
|
|
422
|
+
* @returns
|
|
423
|
+
*/
|
|
424
|
+
getDiskName() {
|
|
425
|
+
return this.diskName;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Get the name of the driver currently in use.
|
|
429
|
+
*
|
|
430
|
+
* @returns
|
|
431
|
+
*/
|
|
432
|
+
getDriverName() {
|
|
433
|
+
return this.driverName;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Get the driver currently in use.
|
|
437
|
+
*
|
|
438
|
+
* @returns
|
|
439
|
+
*/
|
|
440
|
+
getDriver() {
|
|
441
|
+
return this.driver;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
411
444
|
* Return contents of a object for the given key as a Readable stream.
|
|
412
445
|
* Should throw "E_CANNOT_READ_FILE" error when the file
|
|
413
446
|
* does not exists.
|
|
447
|
+
*
|
|
448
|
+
* @param key
|
|
449
|
+
* @returns
|
|
414
450
|
*/
|
|
415
451
|
getStream(key) {
|
|
416
452
|
return this.driver.use().getStream(key);
|
|
@@ -419,30 +455,46 @@ var Storage = class Storage {
|
|
|
419
455
|
* Return contents of an object for the given key as an Uint8Array.
|
|
420
456
|
* Should throw "E_CANNOT_READ_FILE" error when the file
|
|
421
457
|
* does not exists.
|
|
458
|
+
*
|
|
459
|
+
* @param key
|
|
460
|
+
* @returns
|
|
422
461
|
*/
|
|
423
462
|
getBytes(key) {
|
|
424
463
|
return this.driver.use().getBytes(key);
|
|
425
464
|
}
|
|
426
465
|
/**
|
|
427
466
|
* Return metadata of an object for the given key.
|
|
467
|
+
*
|
|
468
|
+
* @param key
|
|
469
|
+
* @returns
|
|
428
470
|
*/
|
|
429
471
|
getMetaData(key) {
|
|
430
472
|
return this.driver.use().getMetaData(key);
|
|
431
473
|
}
|
|
432
474
|
/**
|
|
433
475
|
* Return the visibility of the file
|
|
476
|
+
*
|
|
477
|
+
* @param key
|
|
478
|
+
* @returns
|
|
434
479
|
*/
|
|
435
480
|
getVisibility(key) {
|
|
436
481
|
return this.driver.use().getVisibility(key);
|
|
437
482
|
}
|
|
438
483
|
/**
|
|
439
484
|
* Return the public URL to access the file
|
|
485
|
+
*
|
|
486
|
+
* @param key
|
|
487
|
+
* @returns
|
|
440
488
|
*/
|
|
441
489
|
getUrl(key) {
|
|
442
490
|
return this.driver.use().getUrl(key);
|
|
443
491
|
}
|
|
444
492
|
/**
|
|
445
493
|
* Return the signed/temporary URL to access the file
|
|
494
|
+
*
|
|
495
|
+
* @param key
|
|
496
|
+
* @param options
|
|
497
|
+
* @returns
|
|
446
498
|
*/
|
|
447
499
|
getSignedUrl(key, options) {
|
|
448
500
|
return this.driver.use().getSignedUrl(key, options);
|
|
@@ -450,12 +502,20 @@ var Storage = class Storage {
|
|
|
450
502
|
/**
|
|
451
503
|
* Return the signed/temporary URL that can be used to directly upload
|
|
452
504
|
* the file contents to the storage.
|
|
505
|
+
*
|
|
506
|
+
* @param key
|
|
507
|
+
* @param options
|
|
508
|
+
* @returns
|
|
453
509
|
*/
|
|
454
510
|
getSignedUploadUrl(key, options) {
|
|
455
511
|
return this.driver.use().getSignedUploadUrl(key, options);
|
|
456
512
|
}
|
|
457
513
|
/**
|
|
458
514
|
* Update the visibility of the file
|
|
515
|
+
*
|
|
516
|
+
* @param key
|
|
517
|
+
* @param visibility
|
|
518
|
+
* @returns
|
|
459
519
|
*/
|
|
460
520
|
setVisibility(key, visibility) {
|
|
461
521
|
return this.driver.use().setVisibility(key, visibility);
|
|
@@ -463,6 +523,11 @@ var Storage = class Storage {
|
|
|
463
523
|
/**
|
|
464
524
|
* Write object to the destination with the provided
|
|
465
525
|
* contents.
|
|
526
|
+
*
|
|
527
|
+
* @param key
|
|
528
|
+
* @param contents
|
|
529
|
+
* @param options
|
|
530
|
+
* @returns
|
|
466
531
|
*/
|
|
467
532
|
put(key, contents, options) {
|
|
468
533
|
if (!(contents instanceof Uint8Array) && typeof contents !== "string") contents = contents.buffer;
|
|
@@ -471,6 +536,11 @@ var Storage = class Storage {
|
|
|
471
536
|
/**
|
|
472
537
|
* Write object to the destination with the provided
|
|
473
538
|
* contents as a readable stream
|
|
539
|
+
*
|
|
540
|
+
* @param key
|
|
541
|
+
* @param contents
|
|
542
|
+
* @param options
|
|
543
|
+
* @returns
|
|
474
544
|
*/
|
|
475
545
|
putStream(key, contents, options) {
|
|
476
546
|
return this.driver.use().putStream(key, contents, options);
|
|
@@ -479,6 +549,11 @@ var Storage = class Storage {
|
|
|
479
549
|
* Copy the file from within the disk root location. Both
|
|
480
550
|
* the "source" and "destination" will be the key names
|
|
481
551
|
* and not absolute paths.
|
|
552
|
+
*
|
|
553
|
+
* @param source
|
|
554
|
+
* @param destination
|
|
555
|
+
* @param options
|
|
556
|
+
* @returns
|
|
482
557
|
*/
|
|
483
558
|
copy(source, destination, options) {
|
|
484
559
|
return this.driver.use().copy(source, destination, options);
|
|
@@ -487,6 +562,11 @@ var Storage = class Storage {
|
|
|
487
562
|
* Move the file from within the disk root location. Both
|
|
488
563
|
* the "source" and "destination" will be the key names
|
|
489
564
|
* and not absolute paths.
|
|
565
|
+
*
|
|
566
|
+
* @param source
|
|
567
|
+
* @param destination
|
|
568
|
+
* @param options
|
|
569
|
+
* @returns
|
|
490
570
|
*/
|
|
491
571
|
move(source, destination, options) {
|
|
492
572
|
return this.driver.use().move(source, destination, options);
|
|
@@ -494,12 +574,18 @@ var Storage = class Storage {
|
|
|
494
574
|
/**
|
|
495
575
|
* Delete the file for the given key. Should not throw
|
|
496
576
|
* error when file does not exist in first place
|
|
577
|
+
*
|
|
578
|
+
* @param key
|
|
579
|
+
* @returns
|
|
497
580
|
*/
|
|
498
581
|
delete(key) {
|
|
499
582
|
return this.driver.use().delete(key);
|
|
500
583
|
}
|
|
501
584
|
/**
|
|
502
585
|
* Delete the files and directories matching the provided prefix.
|
|
586
|
+
*
|
|
587
|
+
* @param prefix
|
|
588
|
+
* @returns
|
|
503
589
|
*/
|
|
504
590
|
deleteAll(prefix) {
|
|
505
591
|
return this.driver.use().deleteAll(prefix);
|
|
@@ -507,18 +593,27 @@ var Storage = class Storage {
|
|
|
507
593
|
/**
|
|
508
594
|
* The list all method must return an array of objects with
|
|
509
595
|
* the ability to paginate results (if supported).
|
|
596
|
+
*
|
|
597
|
+
* @param prefix
|
|
598
|
+
* @param options
|
|
599
|
+
* @returns
|
|
510
600
|
*/
|
|
511
601
|
listAll(prefix, options) {
|
|
512
602
|
return this.driver.use().listAll(prefix, options);
|
|
513
603
|
}
|
|
514
604
|
/**
|
|
515
605
|
* Switch bucket at runtime if supported.
|
|
606
|
+
*
|
|
607
|
+
* @param bucket
|
|
608
|
+
* @returns
|
|
516
609
|
*/
|
|
517
610
|
bucket(bucket) {
|
|
518
611
|
return this.driver.use().bucket(bucket);
|
|
519
612
|
}
|
|
520
613
|
/**
|
|
521
614
|
* Create symbolic links for all configured links in the application configuration.
|
|
615
|
+
*
|
|
616
|
+
* @param param0
|
|
522
617
|
*/
|
|
523
618
|
static link({ force = false } = {}) {
|
|
524
619
|
for (const link in config("filesystem.links")) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/filesystem",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.24",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Filesystem module for Arkstack, providing shared file storage and filesystem utitlities for the framework.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net",
|
|
@@ -31,16 +31,16 @@
|
|
|
31
31
|
"./package.json": "./package.json"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@h3ravel/musket": "^0.
|
|
34
|
+
"@h3ravel/musket": "^2.0.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@h3ravel/shared": "^
|
|
37
|
+
"@h3ravel/shared": "^2.1.3",
|
|
38
38
|
"@aws-sdk/client-s3": "^3.1011.0",
|
|
39
39
|
"@aws-sdk/s3-request-presigner": "^3.1011.0",
|
|
40
40
|
"flydrive": "^2.0.0",
|
|
41
41
|
"ssh2-sftp-client": "^12.1.0",
|
|
42
|
-
"@arkstack/common": "^0.12.
|
|
43
|
-
"@arkstack/contract": "^0.12.
|
|
42
|
+
"@arkstack/common": "^0.12.24",
|
|
43
|
+
"@arkstack/contract": "^0.12.24"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/ssh2-sftp-client": "^9.0.6"
|