@e-mc/file-manager 0.7.0 → 0.8.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.
- package/index.js +157 -141
- package/package.json +11 -10
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const fs = require("fs");
|
|
7
|
+
const pm = require("picomatch");
|
|
7
8
|
const lib_v4_1 = require("../module/lib-v4");
|
|
8
9
|
const util_1 = require("../request/util");
|
|
9
10
|
const asset_1 = require("../document/asset");
|
|
@@ -177,13 +178,24 @@ function checkHash(data, fromBuffer, options) {
|
|
|
177
178
|
}
|
|
178
179
|
return true;
|
|
179
180
|
}
|
|
180
|
-
function
|
|
181
|
+
function validatePaths(values, patterns, include, dot) {
|
|
182
|
+
const items = patterns.map(value => !value.startsWith('*') && /[\\/]/.test(value) ? [core_1.Permission.toPosix(path.resolve(value)), { nocase: PLATFORM_WIN32, dot }] : [value.replace(/(?:^\\|\\+)/g, '/'), { matchBase: true, nocase: PLATFORM_WIN32, dot }]);
|
|
183
|
+
return values.filter(value => {
|
|
184
|
+
for (const [pattern, options] of items) {
|
|
185
|
+
if (pm.isMatch(core_1.Permission.toPosix(value), pattern, options)) {
|
|
186
|
+
return include;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return !include;
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function filterPaths(values, include, exclude, dot) {
|
|
181
193
|
if (include) {
|
|
182
194
|
if ((0, types_1.isString)(include)) {
|
|
183
195
|
include = [include];
|
|
184
196
|
}
|
|
185
197
|
if ((0, types_1.isArray)(include)) {
|
|
186
|
-
return values
|
|
198
|
+
return validatePaths(values, include, true, dot);
|
|
187
199
|
}
|
|
188
200
|
}
|
|
189
201
|
if (exclude) {
|
|
@@ -191,7 +203,7 @@ function filterPaths(values, include, exclude) {
|
|
|
191
203
|
exclude = [exclude];
|
|
192
204
|
}
|
|
193
205
|
if ((0, types_1.isArray)(exclude)) {
|
|
194
|
-
return values
|
|
206
|
+
return validatePaths(values, exclude, false, dot);
|
|
195
207
|
}
|
|
196
208
|
}
|
|
197
209
|
return values;
|
|
@@ -219,7 +231,7 @@ function observeFile(instance) {
|
|
|
219
231
|
if (PLATFORM_WIN32) {
|
|
220
232
|
value = value.toLowerCase();
|
|
221
233
|
}
|
|
222
|
-
if (value
|
|
234
|
+
if (!value.endsWith(path.sep)) {
|
|
223
235
|
value += path.sep;
|
|
224
236
|
}
|
|
225
237
|
for (const name of this.files) {
|
|
@@ -548,44 +560,44 @@ class FileManager extends core_1.Host {
|
|
|
548
560
|
return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
|
|
549
561
|
}
|
|
550
562
|
static loadSettings(settings, permission, password) {
|
|
551
|
-
if (super.loadSettings(settings, permission, password)) {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
this.defineHttpCache(disk, true);
|
|
560
|
-
}
|
|
561
|
-
if (buffer) {
|
|
562
|
-
this.defineHttpCache(buffer);
|
|
563
|
-
}
|
|
564
|
-
if (connect) {
|
|
565
|
-
this.defineHttpConnect(connect);
|
|
566
|
-
}
|
|
567
|
-
request_1.default.loadSettings({ process: settings.process, request, download }, password);
|
|
563
|
+
if (!super.loadSettings(settings, permission, password)) {
|
|
564
|
+
return false;
|
|
565
|
+
}
|
|
566
|
+
const { download, request, error, logger } = settings;
|
|
567
|
+
if ((0, types_1.isPlainObject)(request)) {
|
|
568
|
+
let { timeout, disk, buffer, connect } = request;
|
|
569
|
+
if ((timeout = (0, util_1.fromSeconds)(timeout)) >= 0) {
|
|
570
|
+
HTTP_CLIENT.timeout = timeout;
|
|
568
571
|
}
|
|
569
|
-
if (
|
|
570
|
-
|
|
571
|
-
if (value >= 0 && value < Infinity) {
|
|
572
|
-
RECURSION_LIMIT = value;
|
|
573
|
-
}
|
|
572
|
+
if (disk) {
|
|
573
|
+
this.defineHttpCache(disk, true);
|
|
574
574
|
}
|
|
575
|
-
if (
|
|
576
|
-
|
|
577
|
-
if (value === true) {
|
|
578
|
-
SESSION_LIMIT = 1000;
|
|
579
|
-
}
|
|
580
|
-
else if (value && (value = +value) > 0) {
|
|
581
|
-
SESSION_LIMIT = Math.pow(10, value);
|
|
582
|
-
}
|
|
575
|
+
if (buffer) {
|
|
576
|
+
this.defineHttpCache(buffer);
|
|
583
577
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
578
|
+
if (connect) {
|
|
579
|
+
this.defineHttpConnect(connect);
|
|
580
|
+
}
|
|
581
|
+
request_1.default.loadSettings({ process: settings.process, request, download }, password);
|
|
587
582
|
}
|
|
588
|
-
|
|
583
|
+
if (error) {
|
|
584
|
+
const value = (0, util_1.asInt)(error.recursion_limit);
|
|
585
|
+
if (value >= 0 && value < Infinity) {
|
|
586
|
+
RECURSION_LIMIT = value;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (logger) {
|
|
590
|
+
let value = logger.session_id;
|
|
591
|
+
if (value === true) {
|
|
592
|
+
SESSION_LIMIT = 1000;
|
|
593
|
+
}
|
|
594
|
+
else if (value && (value = +value) > 0) {
|
|
595
|
+
SESSION_LIMIT = Math.pow(10, value);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
LOG_TIMEELAPSED = this.hasLogType(128 /* LOG_TYPE.TIME_ELAPSED */);
|
|
599
|
+
LOG_TIMEPROCESS = this.hasLogType(256 /* LOG_TYPE.TIME_PROCESS */);
|
|
600
|
+
return true;
|
|
589
601
|
}
|
|
590
602
|
static sanitizeAssets(assets, exclusions = []) {
|
|
591
603
|
assets.forEach(item => {
|
|
@@ -645,11 +657,11 @@ class FileManager extends core_1.Host {
|
|
|
645
657
|
to = joinRoot ? path.join(root, to) : path.resolve(to);
|
|
646
658
|
recurseDir(result, [root], { ignore: [...ignore, to], sortBy, recursive });
|
|
647
659
|
const output = [];
|
|
648
|
-
for (const pathname of result = filterPaths(result, include, exclude)) {
|
|
660
|
+
for (const pathname of result = filterPaths(result, include, exclude, options.dot)) {
|
|
649
661
|
if (recursive === 1 && path.basename(pathname) === filename) {
|
|
650
662
|
continue;
|
|
651
663
|
}
|
|
652
|
-
const current = await this.readHash(pathname, { algorithm, digest }) + ' ' + (path.sep === '\\' ? pathname.replace(
|
|
664
|
+
const current = await this.readHash(pathname, { algorithm, digest }) + ' ' + (path.sep === '\\' ? pathname.replace(/(?:^\\|\\+)/g, '/') : pathname).substring(root.length).replace(/^\//, '');
|
|
653
665
|
if (verbose) {
|
|
654
666
|
process.stdout.write(current + '\n');
|
|
655
667
|
}
|
|
@@ -698,7 +710,7 @@ class FileManager extends core_1.Host {
|
|
|
698
710
|
const index = item.indexOf(' ');
|
|
699
711
|
return [item.substring(0, index), path.join(root, item.substring(index + 1))];
|
|
700
712
|
});
|
|
701
|
-
const checked = include || exclude ? filterPaths(items.map(item => item[1]), include, exclude) : null;
|
|
713
|
+
const checked = include || exclude ? filterPaths(items.map(item => item[1]), include, exclude, options.dot) : null;
|
|
702
714
|
let valid;
|
|
703
715
|
for (const [previous, pathname] of items) {
|
|
704
716
|
if (checked !== null && !checked.includes(pathname) || recursive === 1 && path.basename(pathname) === filename) {
|
|
@@ -722,7 +734,7 @@ class FileManager extends core_1.Host {
|
|
|
722
734
|
const nested = files.filter(value => path.basename(value) === filename);
|
|
723
735
|
if (nested.length) {
|
|
724
736
|
const current = items.map(item => item[1]);
|
|
725
|
-
const tasks = nested.map(pathname => this.verifyChecksum(path.dirname(pathname), filename, { ...options, ignore: current, joinRoot: true, verbose: (verbose ? 1 : 0) }));
|
|
737
|
+
const tasks = nested.map(async (pathname) => this.verifyChecksum(path.dirname(pathname), filename, { ...options, ignore: current, joinRoot: true, verbose: (verbose ? 1 : 0) }));
|
|
726
738
|
await Promise.all(tasks).then(group => {
|
|
727
739
|
for (const item of group) {
|
|
728
740
|
if (item) {
|
|
@@ -761,9 +773,12 @@ class FileManager extends core_1.Host {
|
|
|
761
773
|
missing = Array.from(new Set(missing));
|
|
762
774
|
}
|
|
763
775
|
}
|
|
764
|
-
if (verbose === true) {
|
|
776
|
+
if (verbose === true) { // eslint-disable-line @typescript-eslint/no-unnecessary-boolean-literal-compare
|
|
765
777
|
const max = Math.max(...fail.concat(missing).map(item => item.length));
|
|
766
|
-
const writeLog = (items, symbol) =>
|
|
778
|
+
const writeLog = (items, symbol) => {
|
|
779
|
+
const [bg, fg] = symbol === "-" /* SUMDIR_STATUS.FAIL */ ? ['\x1b[31m', '\x1b[89m'] : ['\x1b[33m', '\x1b[89m'];
|
|
780
|
+
items.forEach((value, index) => process.stdout.write(bg + symbol + ` ${value.padEnd(max)} (${(index + 1).toString()})${fg}\n`));
|
|
781
|
+
};
|
|
767
782
|
writeLog(fail, "-" /* SUMDIR_STATUS.FAIL */);
|
|
768
783
|
writeLog(missing, "?" /* SUMDIR_STATUS.MISSING */);
|
|
769
784
|
}
|
|
@@ -1041,9 +1056,9 @@ class FileManager extends core_1.Host {
|
|
|
1041
1056
|
get size() {
|
|
1042
1057
|
return this.files.size;
|
|
1043
1058
|
}
|
|
1044
|
-
abort() {
|
|
1045
|
-
this.Request.abort();
|
|
1046
|
-
super.abort();
|
|
1059
|
+
abort(reason) {
|
|
1060
|
+
this.Request.abort(reason);
|
|
1061
|
+
super.abort(reason);
|
|
1047
1062
|
}
|
|
1048
1063
|
willAbort(value) {
|
|
1049
1064
|
if ((0, types_1.isObject)(value)) {
|
|
@@ -1332,81 +1347,82 @@ class FileManager extends core_1.Host {
|
|
|
1332
1347
|
else {
|
|
1333
1348
|
({ origin, pathname, href: value } = value);
|
|
1334
1349
|
}
|
|
1335
|
-
if (value) {
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
catch {
|
|
1350
|
+
if (!(0, types_1.isString)(value)) {
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
const isSame = (a, b) => a === b || decodeURIComponent(a) === decodeURIComponent(b);
|
|
1354
|
+
const result = (assets || this.assets).filter(item => {
|
|
1355
|
+
let { uri, flags } = item;
|
|
1356
|
+
if (uri && (!instance || this.hasDocument(instance, item.document)) && (!item.invalid || assets || (0, types_1.mainFlag)(flags) || (0, types_1.usingFlag)(flags) || (0, types_1.cloneFlag)(flags) || (0, types_1.watchFlag)(flags))) {
|
|
1357
|
+
if (origin) {
|
|
1358
|
+
if (!item.url) {
|
|
1359
|
+
try {
|
|
1360
|
+
if ((item.url = new URL(uri)).href === value) {
|
|
1361
|
+
return true;
|
|
1348
1362
|
}
|
|
1349
1363
|
}
|
|
1350
|
-
|
|
1351
|
-
return true;
|
|
1364
|
+
catch {
|
|
1352
1365
|
}
|
|
1353
1366
|
}
|
|
1354
|
-
if (
|
|
1367
|
+
else if (item.url.href === value) {
|
|
1355
1368
|
return true;
|
|
1356
1369
|
}
|
|
1357
|
-
const indexA = uri.indexOf('#');
|
|
1358
|
-
const indexB = value.indexOf('#');
|
|
1359
|
-
if (indexA !== -1 || indexB !== -1) {
|
|
1360
|
-
if (indexA !== -1) {
|
|
1361
|
-
uri = uri.substring(0, indexA);
|
|
1362
|
-
}
|
|
1363
|
-
if (indexB !== -1) {
|
|
1364
|
-
value = value.substring(0, indexB);
|
|
1365
|
-
}
|
|
1366
|
-
return isSame(uri, value);
|
|
1367
|
-
}
|
|
1368
1370
|
}
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
if (replaced) {
|
|
1372
|
-
const map = this[kReplaceMap];
|
|
1373
|
-
const target = pathname || core_1.Host.toPosix(value);
|
|
1374
|
-
const found = [];
|
|
1375
|
-
for (const relative in map) {
|
|
1376
|
-
const item = map[relative];
|
|
1377
|
-
if (origin && item.url && item.url.origin !== origin) {
|
|
1378
|
-
continue;
|
|
1379
|
-
}
|
|
1380
|
-
if (path.basename(relative) === path.basename(target) && path.dirname(target).endsWith(path.dirname(relative))) {
|
|
1381
|
-
found.push([item, relative]);
|
|
1382
|
-
}
|
|
1371
|
+
if (isSame(uri, value)) {
|
|
1372
|
+
return true;
|
|
1383
1373
|
}
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1374
|
+
const indexA = uri.indexOf('#');
|
|
1375
|
+
const indexB = value.indexOf('#');
|
|
1376
|
+
if (indexA !== -1 || indexB !== -1) {
|
|
1377
|
+
if (indexA !== -1) {
|
|
1378
|
+
uri = uri.substring(0, indexA);
|
|
1379
|
+
}
|
|
1380
|
+
if (indexB !== -1) {
|
|
1381
|
+
value = value.substring(0, indexB);
|
|
1387
1382
|
}
|
|
1388
|
-
|
|
1383
|
+
return isSame(uri, value);
|
|
1389
1384
|
}
|
|
1390
1385
|
}
|
|
1391
|
-
return
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1386
|
+
return false;
|
|
1387
|
+
});
|
|
1388
|
+
if (replaced) {
|
|
1389
|
+
const map = this[kReplaceMap];
|
|
1390
|
+
const target = pathname || core_1.Host.toPosix(value);
|
|
1391
|
+
const found = [];
|
|
1392
|
+
for (const relative in map) {
|
|
1393
|
+
const item = map[relative];
|
|
1394
|
+
if (origin && item.url && item.url.origin !== origin) {
|
|
1395
|
+
continue;
|
|
1397
1396
|
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
if (a.id && b.id) {
|
|
1401
|
-
return a.id < b.id ? -1 : 1;
|
|
1402
|
-
}
|
|
1397
|
+
if (path.basename(relative) === path.basename(target) && path.dirname(target).endsWith(path.dirname(relative))) {
|
|
1398
|
+
found.push([item, relative]);
|
|
1403
1399
|
}
|
|
1404
|
-
|
|
1405
|
-
|
|
1400
|
+
}
|
|
1401
|
+
if (found.length) {
|
|
1402
|
+
if (result.length === 0) {
|
|
1403
|
+
return found.sort((a, b) => b[1].length - a[1].length)[0][0];
|
|
1406
1404
|
}
|
|
1407
|
-
|
|
1408
|
-
}
|
|
1405
|
+
result.push(...found.map(item => item[0]));
|
|
1406
|
+
}
|
|
1409
1407
|
}
|
|
1408
|
+
return result.sort((a, b) => {
|
|
1409
|
+
if ((a.content || a.base64) && !b.content && !b.base64 || a.uri === value && b.uri !== value) {
|
|
1410
|
+
return -1;
|
|
1411
|
+
}
|
|
1412
|
+
if ((b.content || b.base64) && !a.content && !a.base64 || b.uri === value && a.uri !== value) {
|
|
1413
|
+
return 1;
|
|
1414
|
+
}
|
|
1415
|
+
const bundleId = a.bundleId;
|
|
1416
|
+
if (((0, types_1.isEmpty)(bundleId) || a.bundleIndex === 0) && ((0, types_1.isEmpty)(b.bundleId) || b.bundleIndex === 0)) {
|
|
1417
|
+
if (a.id && b.id) {
|
|
1418
|
+
return a.id < b.id ? -1 : 1;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
else if (!(0, types_1.isEmpty)(bundleId) && bundleId === b.bundleId) {
|
|
1422
|
+
return a.bundleIndex < b.bundleIndex ? -1 : 1;
|
|
1423
|
+
}
|
|
1424
|
+
return 0;
|
|
1425
|
+
})[0];
|
|
1410
1426
|
}
|
|
1411
1427
|
removeAsset(file) {
|
|
1412
1428
|
const localUri = file.localUri;
|
|
@@ -1565,10 +1581,10 @@ class FileManager extends core_1.Host {
|
|
|
1565
1581
|
const errors = collectErrors.call(this);
|
|
1566
1582
|
const files = Array.from(this.files).sort((a, b) => {
|
|
1567
1583
|
const sep = path.sep;
|
|
1568
|
-
if (a.
|
|
1584
|
+
if (a.includes(sep) && !b.includes(sep)) {
|
|
1569
1585
|
return -1;
|
|
1570
1586
|
}
|
|
1571
|
-
if (a.
|
|
1587
|
+
if (!a.includes(sep) && b.includes(sep)) {
|
|
1572
1588
|
return 1;
|
|
1573
1589
|
}
|
|
1574
1590
|
return a < b ? -1 : 1;
|
|
@@ -1924,7 +1940,7 @@ class FileManager extends core_1.Host {
|
|
|
1924
1940
|
}
|
|
1925
1941
|
return mimeType;
|
|
1926
1942
|
}
|
|
1927
|
-
compressFile(file, overwrite = true) {
|
|
1943
|
+
async compressFile(file, overwrite = true) {
|
|
1928
1944
|
const { localUri, compress } = file;
|
|
1929
1945
|
const instance = this.Compress;
|
|
1930
1946
|
if (instance && compress && localUri && (this.has(localUri) || (0, types_1.existsFlag)(file.flags))) {
|
|
@@ -1978,7 +1994,7 @@ class FileManager extends core_1.Host {
|
|
|
1978
1994
|
return Promise.all(tasks);
|
|
1979
1995
|
}
|
|
1980
1996
|
}
|
|
1981
|
-
return
|
|
1997
|
+
return [];
|
|
1982
1998
|
}
|
|
1983
1999
|
async transformAsset(data, parent) {
|
|
1984
2000
|
const file = data.file;
|
|
@@ -2029,29 +2045,27 @@ class FileManager extends core_1.Host {
|
|
|
2029
2045
|
const handler = this.Image.get(mimeType) || this.Image.get('handler');
|
|
2030
2046
|
if (handler) {
|
|
2031
2047
|
const { instance, constructor } = handler;
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
if (instance.
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
});
|
|
2044
|
-
}
|
|
2045
|
-
}
|
|
2046
|
-
else if (!this.aborted) {
|
|
2047
|
-
this.addProcessTimeout(instance, file, this.getProcessTimeout(handler));
|
|
2048
|
-
await (instance.using ? instance.using(data, command) : constructor.using.call(this, instance, data, command));
|
|
2048
|
+
for (const command of file.commands) {
|
|
2049
|
+
if (withinSizeRange(localUri, command, constructor.REGEXP_SIZERANGE) && (instance.using || constructor.using) && !data.aborted) {
|
|
2050
|
+
try {
|
|
2051
|
+
if (instance.threadable) {
|
|
2052
|
+
if (this.openThread(instance, data, this.getProcessTimeout(handler))) {
|
|
2053
|
+
(instance.using ? instance.using(data, command) : constructor.using.call(this, instance, data, command))
|
|
2054
|
+
.then(() => this.closeThread(instance, data))
|
|
2055
|
+
.catch(err => {
|
|
2056
|
+
this.closeThread(instance, data);
|
|
2057
|
+
errorAsset(instance, err, 2048 /* LOG_TYPE.IMAGE */);
|
|
2058
|
+
});
|
|
2049
2059
|
}
|
|
2050
2060
|
}
|
|
2051
|
-
|
|
2052
|
-
|
|
2061
|
+
else if (!this.aborted) {
|
|
2062
|
+
this.addProcessTimeout(instance, file, this.getProcessTimeout(handler));
|
|
2063
|
+
await (instance.using ? instance.using(data, command) : constructor.using.call(this, instance, data, command));
|
|
2053
2064
|
}
|
|
2054
2065
|
}
|
|
2066
|
+
catch (err) {
|
|
2067
|
+
errorAsset(instance, err, 2048 /* LOG_TYPE.IMAGE */);
|
|
2068
|
+
}
|
|
2055
2069
|
}
|
|
2056
2070
|
}
|
|
2057
2071
|
}
|
|
@@ -2060,7 +2074,7 @@ class FileManager extends core_1.Host {
|
|
|
2060
2074
|
else if (file.document) {
|
|
2061
2075
|
for (const handler of this.Document) {
|
|
2062
2076
|
const { instance, constructor } = handler;
|
|
2063
|
-
if ((instance
|
|
2077
|
+
if (this.hasDocument(instance, file.document) && (instance.using || constructor.using) && !data.aborted) {
|
|
2064
2078
|
try {
|
|
2065
2079
|
if (instance.threadable) {
|
|
2066
2080
|
if (this.openThread(instance, data, this.getProcessTimeout(handler))) {
|
|
@@ -2199,14 +2213,14 @@ class FileManager extends core_1.Host {
|
|
|
2199
2213
|
getDownload(type = 0) {
|
|
2200
2214
|
return this[kDownloadStats][type];
|
|
2201
2215
|
}
|
|
2202
|
-
fetchObject(uri, options) {
|
|
2216
|
+
async fetchObject(uri, options) {
|
|
2203
2217
|
if (!(0, types_1.isObject)(options)) {
|
|
2204
2218
|
options = { format: options };
|
|
2205
2219
|
}
|
|
2206
2220
|
options.format || (options.format = 'json');
|
|
2207
2221
|
return this.fetchBuffer(uri, options).then(data => typeof data === 'object' ? data : null).catch(() => null);
|
|
2208
2222
|
}
|
|
2209
|
-
fetchBuffer(uri, options) {
|
|
2223
|
+
async fetchBuffer(uri, options) {
|
|
2210
2224
|
if (options) {
|
|
2211
2225
|
options.format = undefined;
|
|
2212
2226
|
}
|
|
@@ -2224,14 +2238,14 @@ class FileManager extends core_1.Host {
|
|
|
2224
2238
|
return buffer;
|
|
2225
2239
|
});
|
|
2226
2240
|
}
|
|
2227
|
-
fetchFiles(uri, options) {
|
|
2241
|
+
async fetchFiles(uri, options) {
|
|
2228
2242
|
if (!(0, types_1.isObject)(options)) {
|
|
2229
2243
|
options = { pathname: options };
|
|
2230
2244
|
}
|
|
2231
2245
|
options.pathname || (options.pathname = this.baseDirectory);
|
|
2232
2246
|
return this.Request.aria2c(uri, options);
|
|
2233
2247
|
}
|
|
2234
|
-
start(emptyDir) {
|
|
2248
|
+
async start(emptyDir) {
|
|
2235
2249
|
const listener = (resolve) => {
|
|
2236
2250
|
const callback = (files, errors, status) => {
|
|
2237
2251
|
if (!this.restarting) {
|
|
@@ -2323,7 +2337,7 @@ class FileManager extends core_1.Host {
|
|
|
2323
2337
|
const length = arguments.length;
|
|
2324
2338
|
const args = new Array(length);
|
|
2325
2339
|
for (let i = 0; i < length; ++i) {
|
|
2326
|
-
args[i] = arguments[i];
|
|
2340
|
+
args[i] = arguments[i]; // eslint-disable-line prefer-rest-params
|
|
2327
2341
|
}
|
|
2328
2342
|
if (this.joinQueue({ args })) {
|
|
2329
2343
|
this.finalizeState = 4 /* FINALIZE_STATE.QUEUED */;
|
|
@@ -2364,7 +2378,7 @@ class FileManager extends core_1.Host {
|
|
|
2364
2378
|
file.invalid = true;
|
|
2365
2379
|
const localUri = file.localUri;
|
|
2366
2380
|
if (expired) {
|
|
2367
|
-
data.abort();
|
|
2381
|
+
data.abort(new Error("Timeout was exceeded" /* ERR_MESSAGE.TIMEOUT */));
|
|
2368
2382
|
if (localUri) {
|
|
2369
2383
|
this.deleteFile(localUri, { id: file.id, emptyDir: true, all: true });
|
|
2370
2384
|
}
|
|
@@ -2612,7 +2626,7 @@ class FileManager extends core_1.Host {
|
|
|
2612
2626
|
if (!fs.existsSync(baseDir)) {
|
|
2613
2627
|
fs.mkdirSync(baseDir);
|
|
2614
2628
|
}
|
|
2615
|
-
tempFile = path.join(baseDir, (0, types_1.
|
|
2629
|
+
tempFile = path.join(baseDir, (0, types_1.incrementUUID)());
|
|
2616
2630
|
options.pipeTo = tempFile;
|
|
2617
2631
|
}
|
|
2618
2632
|
catch {
|
|
@@ -3304,7 +3318,7 @@ class FileManager extends core_1.Host {
|
|
|
3304
3318
|
}
|
|
3305
3319
|
async finalizeCompress(assets) {
|
|
3306
3320
|
const compress = this.Compress;
|
|
3307
|
-
if (!(
|
|
3321
|
+
if (!(assets.length && compress)) {
|
|
3308
3322
|
return;
|
|
3309
3323
|
}
|
|
3310
3324
|
const tasks = [];
|
|
@@ -3370,9 +3384,11 @@ class FileManager extends core_1.Host {
|
|
|
3370
3384
|
}
|
|
3371
3385
|
}
|
|
3372
3386
|
}
|
|
3373
|
-
finalizeCloud() {
|
|
3387
|
+
async finalizeCloud() {
|
|
3374
3388
|
const cloud = this.Cloud;
|
|
3375
|
-
|
|
3389
|
+
if (cloud) {
|
|
3390
|
+
return cloud_1.default.finalize.call(this, cloud).catch(err => rejectModule.call(cloud, err, 64 /* LOG_TYPE.CLOUD */));
|
|
3391
|
+
}
|
|
3376
3392
|
}
|
|
3377
3393
|
async finalizeCleanup() {
|
|
3378
3394
|
if (this.emptyDir.size) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/file-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "FileManager constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,14 +20,15 @@
|
|
|
20
20
|
"license": "BSD 3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "0.
|
|
24
|
-
"@e-mc/compress": "0.
|
|
25
|
-
"@e-mc/core": "0.
|
|
26
|
-
"@e-mc/document": "0.
|
|
27
|
-
"@e-mc/image": "0.
|
|
28
|
-
"@e-mc/request": "0.
|
|
29
|
-
"@e-mc/task": "0.
|
|
30
|
-
"@e-mc/types": "0.
|
|
31
|
-
"@e-mc/watch": "0.
|
|
23
|
+
"@e-mc/cloud": "0.8.0",
|
|
24
|
+
"@e-mc/compress": "0.8.0",
|
|
25
|
+
"@e-mc/core": "0.8.0",
|
|
26
|
+
"@e-mc/document": "0.8.0",
|
|
27
|
+
"@e-mc/image": "0.8.0",
|
|
28
|
+
"@e-mc/request": "0.8.0",
|
|
29
|
+
"@e-mc/task": "0.8.0",
|
|
30
|
+
"@e-mc/types": "0.8.0",
|
|
31
|
+
"@e-mc/watch": "0.8.0",
|
|
32
|
+
"picomatch": "^3.0.1"
|
|
32
33
|
}
|
|
33
34
|
}
|