@e-mc/file-manager 0.7.1 → 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/LICENSE +10 -10
- package/index.d.ts +5 -5
- package/index.js +141 -137
- package/package.json +10 -10
package/LICENSE
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Copyright 2023 An Pham
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
-
|
|
5
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
-
|
|
7
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
1
|
+
Copyright 2023 An Pham
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
+
|
|
11
11
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { FileManagerConstructor } from '../types/lib';
|
|
2
|
-
import type { ExternalAsset } from '../types/lib/asset';
|
|
3
|
-
|
|
4
|
-
declare const FileManager: FileManagerConstructor<ExternalAsset>;
|
|
5
|
-
|
|
1
|
+
import type { FileManagerConstructor } from '../types/lib';
|
|
2
|
+
import type { ExternalAsset } from '../types/lib/asset';
|
|
3
|
+
|
|
4
|
+
declare const FileManager: FileManagerConstructor<ExternalAsset>;
|
|
5
|
+
|
|
6
6
|
export = FileManager;
|
package/index.js
CHANGED
|
@@ -179,7 +179,7 @@ function checkHash(data, fromBuffer, options) {
|
|
|
179
179
|
return true;
|
|
180
180
|
}
|
|
181
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(
|
|
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
183
|
return values.filter(value => {
|
|
184
184
|
for (const [pattern, options] of items) {
|
|
185
185
|
if (pm.isMatch(core_1.Permission.toPosix(value), pattern, options)) {
|
|
@@ -231,7 +231,7 @@ function observeFile(instance) {
|
|
|
231
231
|
if (PLATFORM_WIN32) {
|
|
232
232
|
value = value.toLowerCase();
|
|
233
233
|
}
|
|
234
|
-
if (value
|
|
234
|
+
if (!value.endsWith(path.sep)) {
|
|
235
235
|
value += path.sep;
|
|
236
236
|
}
|
|
237
237
|
for (const name of this.files) {
|
|
@@ -560,44 +560,44 @@ class FileManager extends core_1.Host {
|
|
|
560
560
|
return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
|
|
561
561
|
}
|
|
562
562
|
static loadSettings(settings, permission, password) {
|
|
563
|
-
if (super.loadSettings(settings, permission, password)) {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
this.defineHttpCache(disk, true);
|
|
572
|
-
}
|
|
573
|
-
if (buffer) {
|
|
574
|
-
this.defineHttpCache(buffer);
|
|
575
|
-
}
|
|
576
|
-
if (connect) {
|
|
577
|
-
this.defineHttpConnect(connect);
|
|
578
|
-
}
|
|
579
|
-
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;
|
|
580
571
|
}
|
|
581
|
-
if (
|
|
582
|
-
|
|
583
|
-
if (value >= 0 && value < Infinity) {
|
|
584
|
-
RECURSION_LIMIT = value;
|
|
585
|
-
}
|
|
572
|
+
if (disk) {
|
|
573
|
+
this.defineHttpCache(disk, true);
|
|
586
574
|
}
|
|
587
|
-
if (
|
|
588
|
-
|
|
589
|
-
if (value === true) {
|
|
590
|
-
SESSION_LIMIT = 1000;
|
|
591
|
-
}
|
|
592
|
-
else if (value && (value = +value) > 0) {
|
|
593
|
-
SESSION_LIMIT = Math.pow(10, value);
|
|
594
|
-
}
|
|
575
|
+
if (buffer) {
|
|
576
|
+
this.defineHttpCache(buffer);
|
|
595
577
|
}
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
578
|
+
if (connect) {
|
|
579
|
+
this.defineHttpConnect(connect);
|
|
580
|
+
}
|
|
581
|
+
request_1.default.loadSettings({ process: settings.process, request, download }, password);
|
|
599
582
|
}
|
|
600
|
-
|
|
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;
|
|
601
601
|
}
|
|
602
602
|
static sanitizeAssets(assets, exclusions = []) {
|
|
603
603
|
assets.forEach(item => {
|
|
@@ -661,7 +661,7 @@ class FileManager extends core_1.Host {
|
|
|
661
661
|
if (recursive === 1 && path.basename(pathname) === filename) {
|
|
662
662
|
continue;
|
|
663
663
|
}
|
|
664
|
-
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(/^\//, '');
|
|
665
665
|
if (verbose) {
|
|
666
666
|
process.stdout.write(current + '\n');
|
|
667
667
|
}
|
|
@@ -734,7 +734,7 @@ class FileManager extends core_1.Host {
|
|
|
734
734
|
const nested = files.filter(value => path.basename(value) === filename);
|
|
735
735
|
if (nested.length) {
|
|
736
736
|
const current = items.map(item => item[1]);
|
|
737
|
-
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) }));
|
|
738
738
|
await Promise.all(tasks).then(group => {
|
|
739
739
|
for (const item of group) {
|
|
740
740
|
if (item) {
|
|
@@ -773,9 +773,12 @@ class FileManager extends core_1.Host {
|
|
|
773
773
|
missing = Array.from(new Set(missing));
|
|
774
774
|
}
|
|
775
775
|
}
|
|
776
|
-
if (verbose === true) {
|
|
776
|
+
if (verbose === true) { // eslint-disable-line @typescript-eslint/no-unnecessary-boolean-literal-compare
|
|
777
777
|
const max = Math.max(...fail.concat(missing).map(item => item.length));
|
|
778
|
-
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
|
+
};
|
|
779
782
|
writeLog(fail, "-" /* SUMDIR_STATUS.FAIL */);
|
|
780
783
|
writeLog(missing, "?" /* SUMDIR_STATUS.MISSING */);
|
|
781
784
|
}
|
|
@@ -1053,9 +1056,9 @@ class FileManager extends core_1.Host {
|
|
|
1053
1056
|
get size() {
|
|
1054
1057
|
return this.files.size;
|
|
1055
1058
|
}
|
|
1056
|
-
abort() {
|
|
1057
|
-
this.Request.abort();
|
|
1058
|
-
super.abort();
|
|
1059
|
+
abort(reason) {
|
|
1060
|
+
this.Request.abort(reason);
|
|
1061
|
+
super.abort(reason);
|
|
1059
1062
|
}
|
|
1060
1063
|
willAbort(value) {
|
|
1061
1064
|
if ((0, types_1.isObject)(value)) {
|
|
@@ -1344,81 +1347,82 @@ class FileManager extends core_1.Host {
|
|
|
1344
1347
|
else {
|
|
1345
1348
|
({ origin, pathname, href: value } = value);
|
|
1346
1349
|
}
|
|
1347
|
-
if (value) {
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
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;
|
|
1360
1362
|
}
|
|
1361
1363
|
}
|
|
1362
|
-
|
|
1363
|
-
return true;
|
|
1364
|
+
catch {
|
|
1364
1365
|
}
|
|
1365
1366
|
}
|
|
1366
|
-
if (
|
|
1367
|
+
else if (item.url.href === value) {
|
|
1367
1368
|
return true;
|
|
1368
1369
|
}
|
|
1369
|
-
const indexA = uri.indexOf('#');
|
|
1370
|
-
const indexB = value.indexOf('#');
|
|
1371
|
-
if (indexA !== -1 || indexB !== -1) {
|
|
1372
|
-
if (indexA !== -1) {
|
|
1373
|
-
uri = uri.substring(0, indexA);
|
|
1374
|
-
}
|
|
1375
|
-
if (indexB !== -1) {
|
|
1376
|
-
value = value.substring(0, indexB);
|
|
1377
|
-
}
|
|
1378
|
-
return isSame(uri, value);
|
|
1379
|
-
}
|
|
1380
1370
|
}
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
if (replaced) {
|
|
1384
|
-
const map = this[kReplaceMap];
|
|
1385
|
-
const target = pathname || core_1.Host.toPosix(value);
|
|
1386
|
-
const found = [];
|
|
1387
|
-
for (const relative in map) {
|
|
1388
|
-
const item = map[relative];
|
|
1389
|
-
if (origin && item.url && item.url.origin !== origin) {
|
|
1390
|
-
continue;
|
|
1391
|
-
}
|
|
1392
|
-
if (path.basename(relative) === path.basename(target) && path.dirname(target).endsWith(path.dirname(relative))) {
|
|
1393
|
-
found.push([item, relative]);
|
|
1394
|
-
}
|
|
1371
|
+
if (isSame(uri, value)) {
|
|
1372
|
+
return true;
|
|
1395
1373
|
}
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
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);
|
|
1399
1382
|
}
|
|
1400
|
-
|
|
1383
|
+
return isSame(uri, value);
|
|
1401
1384
|
}
|
|
1402
1385
|
}
|
|
1403
|
-
return
|
|
1404
|
-
|
|
1405
|
-
|
|
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;
|
|
1406
1396
|
}
|
|
1407
|
-
if ((
|
|
1408
|
-
|
|
1397
|
+
if (path.basename(relative) === path.basename(target) && path.dirname(target).endsWith(path.dirname(relative))) {
|
|
1398
|
+
found.push([item, relative]);
|
|
1409
1399
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
else if (!(0, types_1.isEmpty)(bundleId) && bundleId === b.bundleId) {
|
|
1417
|
-
return a.bundleIndex < b.bundleIndex ? -1 : 1;
|
|
1400
|
+
}
|
|
1401
|
+
if (found.length) {
|
|
1402
|
+
if (result.length === 0) {
|
|
1403
|
+
return found.sort((a, b) => b[1].length - a[1].length)[0][0];
|
|
1418
1404
|
}
|
|
1419
|
-
|
|
1420
|
-
}
|
|
1405
|
+
result.push(...found.map(item => item[0]));
|
|
1406
|
+
}
|
|
1421
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];
|
|
1422
1426
|
}
|
|
1423
1427
|
removeAsset(file) {
|
|
1424
1428
|
const localUri = file.localUri;
|
|
@@ -1577,10 +1581,10 @@ class FileManager extends core_1.Host {
|
|
|
1577
1581
|
const errors = collectErrors.call(this);
|
|
1578
1582
|
const files = Array.from(this.files).sort((a, b) => {
|
|
1579
1583
|
const sep = path.sep;
|
|
1580
|
-
if (a.
|
|
1584
|
+
if (a.includes(sep) && !b.includes(sep)) {
|
|
1581
1585
|
return -1;
|
|
1582
1586
|
}
|
|
1583
|
-
if (a.
|
|
1587
|
+
if (!a.includes(sep) && b.includes(sep)) {
|
|
1584
1588
|
return 1;
|
|
1585
1589
|
}
|
|
1586
1590
|
return a < b ? -1 : 1;
|
|
@@ -1936,7 +1940,7 @@ class FileManager extends core_1.Host {
|
|
|
1936
1940
|
}
|
|
1937
1941
|
return mimeType;
|
|
1938
1942
|
}
|
|
1939
|
-
compressFile(file, overwrite = true) {
|
|
1943
|
+
async compressFile(file, overwrite = true) {
|
|
1940
1944
|
const { localUri, compress } = file;
|
|
1941
1945
|
const instance = this.Compress;
|
|
1942
1946
|
if (instance && compress && localUri && (this.has(localUri) || (0, types_1.existsFlag)(file.flags))) {
|
|
@@ -1990,7 +1994,7 @@ class FileManager extends core_1.Host {
|
|
|
1990
1994
|
return Promise.all(tasks);
|
|
1991
1995
|
}
|
|
1992
1996
|
}
|
|
1993
|
-
return
|
|
1997
|
+
return [];
|
|
1994
1998
|
}
|
|
1995
1999
|
async transformAsset(data, parent) {
|
|
1996
2000
|
const file = data.file;
|
|
@@ -2041,29 +2045,27 @@ class FileManager extends core_1.Host {
|
|
|
2041
2045
|
const handler = this.Image.get(mimeType) || this.Image.get('handler');
|
|
2042
2046
|
if (handler) {
|
|
2043
2047
|
const { instance, constructor } = handler;
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
if (instance.
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
});
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
else if (!this.aborted) {
|
|
2059
|
-
this.addProcessTimeout(instance, file, this.getProcessTimeout(handler));
|
|
2060
|
-
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
|
+
});
|
|
2061
2059
|
}
|
|
2062
2060
|
}
|
|
2063
|
-
|
|
2064
|
-
|
|
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));
|
|
2065
2064
|
}
|
|
2066
2065
|
}
|
|
2066
|
+
catch (err) {
|
|
2067
|
+
errorAsset(instance, err, 2048 /* LOG_TYPE.IMAGE */);
|
|
2068
|
+
}
|
|
2067
2069
|
}
|
|
2068
2070
|
}
|
|
2069
2071
|
}
|
|
@@ -2072,7 +2074,7 @@ class FileManager extends core_1.Host {
|
|
|
2072
2074
|
else if (file.document) {
|
|
2073
2075
|
for (const handler of this.Document) {
|
|
2074
2076
|
const { instance, constructor } = handler;
|
|
2075
|
-
if ((instance
|
|
2077
|
+
if (this.hasDocument(instance, file.document) && (instance.using || constructor.using) && !data.aborted) {
|
|
2076
2078
|
try {
|
|
2077
2079
|
if (instance.threadable) {
|
|
2078
2080
|
if (this.openThread(instance, data, this.getProcessTimeout(handler))) {
|
|
@@ -2211,14 +2213,14 @@ class FileManager extends core_1.Host {
|
|
|
2211
2213
|
getDownload(type = 0) {
|
|
2212
2214
|
return this[kDownloadStats][type];
|
|
2213
2215
|
}
|
|
2214
|
-
fetchObject(uri, options) {
|
|
2216
|
+
async fetchObject(uri, options) {
|
|
2215
2217
|
if (!(0, types_1.isObject)(options)) {
|
|
2216
2218
|
options = { format: options };
|
|
2217
2219
|
}
|
|
2218
2220
|
options.format || (options.format = 'json');
|
|
2219
2221
|
return this.fetchBuffer(uri, options).then(data => typeof data === 'object' ? data : null).catch(() => null);
|
|
2220
2222
|
}
|
|
2221
|
-
fetchBuffer(uri, options) {
|
|
2223
|
+
async fetchBuffer(uri, options) {
|
|
2222
2224
|
if (options) {
|
|
2223
2225
|
options.format = undefined;
|
|
2224
2226
|
}
|
|
@@ -2236,14 +2238,14 @@ class FileManager extends core_1.Host {
|
|
|
2236
2238
|
return buffer;
|
|
2237
2239
|
});
|
|
2238
2240
|
}
|
|
2239
|
-
fetchFiles(uri, options) {
|
|
2241
|
+
async fetchFiles(uri, options) {
|
|
2240
2242
|
if (!(0, types_1.isObject)(options)) {
|
|
2241
2243
|
options = { pathname: options };
|
|
2242
2244
|
}
|
|
2243
2245
|
options.pathname || (options.pathname = this.baseDirectory);
|
|
2244
2246
|
return this.Request.aria2c(uri, options);
|
|
2245
2247
|
}
|
|
2246
|
-
start(emptyDir) {
|
|
2248
|
+
async start(emptyDir) {
|
|
2247
2249
|
const listener = (resolve) => {
|
|
2248
2250
|
const callback = (files, errors, status) => {
|
|
2249
2251
|
if (!this.restarting) {
|
|
@@ -2335,7 +2337,7 @@ class FileManager extends core_1.Host {
|
|
|
2335
2337
|
const length = arguments.length;
|
|
2336
2338
|
const args = new Array(length);
|
|
2337
2339
|
for (let i = 0; i < length; ++i) {
|
|
2338
|
-
args[i] = arguments[i];
|
|
2340
|
+
args[i] = arguments[i]; // eslint-disable-line prefer-rest-params
|
|
2339
2341
|
}
|
|
2340
2342
|
if (this.joinQueue({ args })) {
|
|
2341
2343
|
this.finalizeState = 4 /* FINALIZE_STATE.QUEUED */;
|
|
@@ -2376,7 +2378,7 @@ class FileManager extends core_1.Host {
|
|
|
2376
2378
|
file.invalid = true;
|
|
2377
2379
|
const localUri = file.localUri;
|
|
2378
2380
|
if (expired) {
|
|
2379
|
-
data.abort();
|
|
2381
|
+
data.abort(new Error("Timeout was exceeded" /* ERR_MESSAGE.TIMEOUT */));
|
|
2380
2382
|
if (localUri) {
|
|
2381
2383
|
this.deleteFile(localUri, { id: file.id, emptyDir: true, all: true });
|
|
2382
2384
|
}
|
|
@@ -2624,7 +2626,7 @@ class FileManager extends core_1.Host {
|
|
|
2624
2626
|
if (!fs.existsSync(baseDir)) {
|
|
2625
2627
|
fs.mkdirSync(baseDir);
|
|
2626
2628
|
}
|
|
2627
|
-
tempFile = path.join(baseDir, (0, types_1.
|
|
2629
|
+
tempFile = path.join(baseDir, (0, types_1.incrementUUID)());
|
|
2628
2630
|
options.pipeTo = tempFile;
|
|
2629
2631
|
}
|
|
2630
2632
|
catch {
|
|
@@ -3316,7 +3318,7 @@ class FileManager extends core_1.Host {
|
|
|
3316
3318
|
}
|
|
3317
3319
|
async finalizeCompress(assets) {
|
|
3318
3320
|
const compress = this.Compress;
|
|
3319
|
-
if (!(
|
|
3321
|
+
if (!(assets.length && compress)) {
|
|
3320
3322
|
return;
|
|
3321
3323
|
}
|
|
3322
3324
|
const tasks = [];
|
|
@@ -3382,9 +3384,11 @@ class FileManager extends core_1.Host {
|
|
|
3382
3384
|
}
|
|
3383
3385
|
}
|
|
3384
3386
|
}
|
|
3385
|
-
finalizeCloud() {
|
|
3387
|
+
async finalizeCloud() {
|
|
3386
3388
|
const cloud = this.Cloud;
|
|
3387
|
-
|
|
3389
|
+
if (cloud) {
|
|
3390
|
+
return cloud_1.default.finalize.call(this, cloud).catch(err => rejectModule.call(cloud, err, 64 /* LOG_TYPE.CLOUD */));
|
|
3391
|
+
}
|
|
3388
3392
|
}
|
|
3389
3393
|
async finalizeCleanup() {
|
|
3390
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,15 +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
32
|
"picomatch": "^3.0.1"
|
|
33
33
|
}
|
|
34
34
|
}
|