@arkstack/filesystem 0.12.21 → 0.12.23
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
|
@@ -46,7 +46,7 @@ type CustomDiskConfig = keyof CustomDiskDriverRegistry extends never ? {
|
|
|
46
46
|
driver: K;
|
|
47
47
|
} }[keyof CustomDiskDriverRegistry];
|
|
48
48
|
type DiskConfig = LocalDriverConfig & {
|
|
49
|
-
driver: 'local';
|
|
49
|
+
driver: 'local' | 'public';
|
|
50
50
|
} | FtpDriverConfig & {
|
|
51
51
|
driver: 'ftp';
|
|
52
52
|
} | S3DriverConfig & {
|
|
@@ -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 };
|
|
@@ -243,7 +243,8 @@ var Driver = class Driver {
|
|
|
243
243
|
constructor(config) {
|
|
244
244
|
this.config = config;
|
|
245
245
|
}
|
|
246
|
-
static make(
|
|
246
|
+
static make(config) {
|
|
247
|
+
const name = config.driver;
|
|
247
248
|
if (![
|
|
248
249
|
"local",
|
|
249
250
|
"ftp",
|
|
@@ -326,12 +327,14 @@ var Storage = class Storage {
|
|
|
326
327
|
driver;
|
|
327
328
|
services = {};
|
|
328
329
|
diskName;
|
|
330
|
+
driverName;
|
|
329
331
|
constructor() {
|
|
330
332
|
const disks = Object.entries(config("filesystem.disks", {}));
|
|
331
333
|
const customDrivers = config("filesystem.custom_drivers", {});
|
|
332
334
|
for (const [name, driver] of Object.entries(customDrivers)) Driver.registerDriver(name, driver);
|
|
333
|
-
for (const [disk,
|
|
335
|
+
for (const [disk, config] of disks) this.services[disk] = () => Driver.make(config);
|
|
334
336
|
this.diskName = config("filesystem.default");
|
|
337
|
+
this.driverName = config(`filesystem.disks.${this.diskName}.driver`);
|
|
335
338
|
this.driver = new DriveManager({
|
|
336
339
|
default: config("filesystem.default"),
|
|
337
340
|
services: this.services
|
|
@@ -347,6 +350,7 @@ var Storage = class Storage {
|
|
|
347
350
|
const storage = new Storage();
|
|
348
351
|
if (diskName) {
|
|
349
352
|
storage.diskName = diskName;
|
|
353
|
+
storage.driverName = config(`filesystem.disks.${diskName}.driver`);
|
|
350
354
|
storage.driver = new DriveManager({
|
|
351
355
|
default: diskName,
|
|
352
356
|
services: storage.services
|
|
@@ -390,10 +394,13 @@ var Storage = class Storage {
|
|
|
390
394
|
if (file instanceof File && !file.buffer) file.buffer = Buffer.from(await file.arrayBuffer());
|
|
391
395
|
await drive.put(path.join(filePath, name), file.buffer);
|
|
392
396
|
const url = await drive.getUrl(path.join(filePath, name));
|
|
393
|
-
return [url, this.
|
|
397
|
+
return [url, this.driverName === "local" ? path.join(filePath, name) : url];
|
|
394
398
|
};
|
|
395
399
|
/**
|
|
396
400
|
* Return a boolean indicating if the file exists
|
|
401
|
+
*
|
|
402
|
+
* @param key
|
|
403
|
+
* @returns
|
|
397
404
|
*/
|
|
398
405
|
exists(key) {
|
|
399
406
|
return this.driver.use().exists(key);
|
|
@@ -402,14 +409,44 @@ var Storage = class Storage {
|
|
|
402
409
|
* Return contents of a object for the given key as a UTF-8 string.
|
|
403
410
|
* Should throw "E_CANNOT_READ_FILE" error when the file
|
|
404
411
|
* does not exists.
|
|
412
|
+
*
|
|
413
|
+
* @param key
|
|
414
|
+
* @returns
|
|
405
415
|
*/
|
|
406
416
|
get(key) {
|
|
407
417
|
return this.driver.use().get(key);
|
|
408
418
|
}
|
|
409
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
|
+
/**
|
|
410
444
|
* Return contents of a object for the given key as a Readable stream.
|
|
411
445
|
* Should throw "E_CANNOT_READ_FILE" error when the file
|
|
412
446
|
* does not exists.
|
|
447
|
+
*
|
|
448
|
+
* @param key
|
|
449
|
+
* @returns
|
|
413
450
|
*/
|
|
414
451
|
getStream(key) {
|
|
415
452
|
return this.driver.use().getStream(key);
|
|
@@ -418,30 +455,46 @@ var Storage = class Storage {
|
|
|
418
455
|
* Return contents of an object for the given key as an Uint8Array.
|
|
419
456
|
* Should throw "E_CANNOT_READ_FILE" error when the file
|
|
420
457
|
* does not exists.
|
|
458
|
+
*
|
|
459
|
+
* @param key
|
|
460
|
+
* @returns
|
|
421
461
|
*/
|
|
422
462
|
getBytes(key) {
|
|
423
463
|
return this.driver.use().getBytes(key);
|
|
424
464
|
}
|
|
425
465
|
/**
|
|
426
466
|
* Return metadata of an object for the given key.
|
|
467
|
+
*
|
|
468
|
+
* @param key
|
|
469
|
+
* @returns
|
|
427
470
|
*/
|
|
428
471
|
getMetaData(key) {
|
|
429
472
|
return this.driver.use().getMetaData(key);
|
|
430
473
|
}
|
|
431
474
|
/**
|
|
432
475
|
* Return the visibility of the file
|
|
476
|
+
*
|
|
477
|
+
* @param key
|
|
478
|
+
* @returns
|
|
433
479
|
*/
|
|
434
480
|
getVisibility(key) {
|
|
435
481
|
return this.driver.use().getVisibility(key);
|
|
436
482
|
}
|
|
437
483
|
/**
|
|
438
484
|
* Return the public URL to access the file
|
|
485
|
+
*
|
|
486
|
+
* @param key
|
|
487
|
+
* @returns
|
|
439
488
|
*/
|
|
440
489
|
getUrl(key) {
|
|
441
490
|
return this.driver.use().getUrl(key);
|
|
442
491
|
}
|
|
443
492
|
/**
|
|
444
493
|
* Return the signed/temporary URL to access the file
|
|
494
|
+
*
|
|
495
|
+
* @param key
|
|
496
|
+
* @param options
|
|
497
|
+
* @returns
|
|
445
498
|
*/
|
|
446
499
|
getSignedUrl(key, options) {
|
|
447
500
|
return this.driver.use().getSignedUrl(key, options);
|
|
@@ -449,12 +502,20 @@ var Storage = class Storage {
|
|
|
449
502
|
/**
|
|
450
503
|
* Return the signed/temporary URL that can be used to directly upload
|
|
451
504
|
* the file contents to the storage.
|
|
505
|
+
*
|
|
506
|
+
* @param key
|
|
507
|
+
* @param options
|
|
508
|
+
* @returns
|
|
452
509
|
*/
|
|
453
510
|
getSignedUploadUrl(key, options) {
|
|
454
511
|
return this.driver.use().getSignedUploadUrl(key, options);
|
|
455
512
|
}
|
|
456
513
|
/**
|
|
457
514
|
* Update the visibility of the file
|
|
515
|
+
*
|
|
516
|
+
* @param key
|
|
517
|
+
* @param visibility
|
|
518
|
+
* @returns
|
|
458
519
|
*/
|
|
459
520
|
setVisibility(key, visibility) {
|
|
460
521
|
return this.driver.use().setVisibility(key, visibility);
|
|
@@ -462,6 +523,11 @@ var Storage = class Storage {
|
|
|
462
523
|
/**
|
|
463
524
|
* Write object to the destination with the provided
|
|
464
525
|
* contents.
|
|
526
|
+
*
|
|
527
|
+
* @param key
|
|
528
|
+
* @param contents
|
|
529
|
+
* @param options
|
|
530
|
+
* @returns
|
|
465
531
|
*/
|
|
466
532
|
put(key, contents, options) {
|
|
467
533
|
if (!(contents instanceof Uint8Array) && typeof contents !== "string") contents = contents.buffer;
|
|
@@ -470,6 +536,11 @@ var Storage = class Storage {
|
|
|
470
536
|
/**
|
|
471
537
|
* Write object to the destination with the provided
|
|
472
538
|
* contents as a readable stream
|
|
539
|
+
*
|
|
540
|
+
* @param key
|
|
541
|
+
* @param contents
|
|
542
|
+
* @param options
|
|
543
|
+
* @returns
|
|
473
544
|
*/
|
|
474
545
|
putStream(key, contents, options) {
|
|
475
546
|
return this.driver.use().putStream(key, contents, options);
|
|
@@ -478,6 +549,11 @@ var Storage = class Storage {
|
|
|
478
549
|
* Copy the file from within the disk root location. Both
|
|
479
550
|
* the "source" and "destination" will be the key names
|
|
480
551
|
* and not absolute paths.
|
|
552
|
+
*
|
|
553
|
+
* @param source
|
|
554
|
+
* @param destination
|
|
555
|
+
* @param options
|
|
556
|
+
* @returns
|
|
481
557
|
*/
|
|
482
558
|
copy(source, destination, options) {
|
|
483
559
|
return this.driver.use().copy(source, destination, options);
|
|
@@ -486,6 +562,11 @@ var Storage = class Storage {
|
|
|
486
562
|
* Move the file from within the disk root location. Both
|
|
487
563
|
* the "source" and "destination" will be the key names
|
|
488
564
|
* and not absolute paths.
|
|
565
|
+
*
|
|
566
|
+
* @param source
|
|
567
|
+
* @param destination
|
|
568
|
+
* @param options
|
|
569
|
+
* @returns
|
|
489
570
|
*/
|
|
490
571
|
move(source, destination, options) {
|
|
491
572
|
return this.driver.use().move(source, destination, options);
|
|
@@ -493,12 +574,18 @@ var Storage = class Storage {
|
|
|
493
574
|
/**
|
|
494
575
|
* Delete the file for the given key. Should not throw
|
|
495
576
|
* error when file does not exist in first place
|
|
577
|
+
*
|
|
578
|
+
* @param key
|
|
579
|
+
* @returns
|
|
496
580
|
*/
|
|
497
581
|
delete(key) {
|
|
498
582
|
return this.driver.use().delete(key);
|
|
499
583
|
}
|
|
500
584
|
/**
|
|
501
585
|
* Delete the files and directories matching the provided prefix.
|
|
586
|
+
*
|
|
587
|
+
* @param prefix
|
|
588
|
+
* @returns
|
|
502
589
|
*/
|
|
503
590
|
deleteAll(prefix) {
|
|
504
591
|
return this.driver.use().deleteAll(prefix);
|
|
@@ -506,18 +593,27 @@ var Storage = class Storage {
|
|
|
506
593
|
/**
|
|
507
594
|
* The list all method must return an array of objects with
|
|
508
595
|
* the ability to paginate results (if supported).
|
|
596
|
+
*
|
|
597
|
+
* @param prefix
|
|
598
|
+
* @param options
|
|
599
|
+
* @returns
|
|
509
600
|
*/
|
|
510
601
|
listAll(prefix, options) {
|
|
511
602
|
return this.driver.use().listAll(prefix, options);
|
|
512
603
|
}
|
|
513
604
|
/**
|
|
514
605
|
* Switch bucket at runtime if supported.
|
|
606
|
+
*
|
|
607
|
+
* @param bucket
|
|
608
|
+
* @returns
|
|
515
609
|
*/
|
|
516
610
|
bucket(bucket) {
|
|
517
611
|
return this.driver.use().bucket(bucket);
|
|
518
612
|
}
|
|
519
613
|
/**
|
|
520
614
|
* Create symbolic links for all configured links in the application configuration.
|
|
615
|
+
*
|
|
616
|
+
* @param param0
|
|
521
617
|
*/
|
|
522
618
|
static link({ force = false } = {}) {
|
|
523
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.23",
|
|
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",
|
|
@@ -39,8 +39,8 @@
|
|
|
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.23",
|
|
43
|
+
"@arkstack/contract": "^0.12.23"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/ssh2-sftp-client": "^9.0.6"
|