@e-mc/file-manager 0.13.9 → 0.14.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/README.md +11 -11
- package/index.d.ts +2 -2
- package/index.js +307 -310
- package/package.json +12 -12
package/index.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const chalk = require(
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const stream = require('node:stream');
|
|
6
|
+
const pm = require('picomatch');
|
|
7
|
+
const chalk = require('chalk');
|
|
8
|
+
const { fileURLToPath } = require('node:url');
|
|
9
|
+
const { stripVTControlCharacters } = require('node:util');
|
|
10
|
+
const { structuredPatch } = require('diff');
|
|
11
|
+
const { DOWNLOAD_TYPE, FILE_TYPE, THRESHOLD, asExt, cloneFlag, convertTime, createAbortError, errorMessage, errorValue, existsFlag, formatSize, formatTime, getAlgorithm, getEncoding, getLogCurrent, getTempDir, hasBit, hasGlob, ignoreFlag, incrementUUID, isArray, isEmpty, isError, isErrorCode, isFunction, isObject, isPlainObject, isString, mainFlag, parseExpires, parseTime, renameExt, requireESM, setLogCurrent, usingFlag, watchFlag } = require('@e-mc/types');
|
|
12
|
+
const { AbortComponent, Host, Permission } = require('@e-mc/core');
|
|
13
|
+
const { isEqual, setInitialValue } = require('@e-mc/document/asset');
|
|
14
|
+
const { concatString, getNewline } = require('@e-mc/document/util');
|
|
15
|
+
const { asFloat, asInt, byteLength, checkRetryable, fromSeconds, fromURL, getSize, getTransferRate, hasSameStat, hasSize } = require('@e-mc/request/util');
|
|
16
|
+
const Request = require('@e-mc/request');
|
|
17
|
+
const Image = require('@e-mc/image');
|
|
18
|
+
const Watch = require('@e-mc/watch');
|
|
19
|
+
const Compress = require('@e-mc/compress');
|
|
20
|
+
const Cloud = require('@e-mc/cloud');
|
|
20
21
|
const kFileManager = Symbol.for('filemanager:constructor');
|
|
21
22
|
const PROCESS_STDOUT = process.stdout;
|
|
22
23
|
const PROCESS_STDIN = process.stdin;
|
|
@@ -27,7 +28,7 @@ const CACHE_ETAG = new Map();
|
|
|
27
28
|
const DISK = {
|
|
28
29
|
ENABLED: false,
|
|
29
30
|
EXPIRES: 0,
|
|
30
|
-
LIMIT:
|
|
31
|
+
LIMIT: formatSize("1gb"),
|
|
31
32
|
INCLUDE: [],
|
|
32
33
|
EXCLUDE: []
|
|
33
34
|
};
|
|
@@ -36,8 +37,8 @@ const MEMORY = {
|
|
|
36
37
|
CACHE: new Map(),
|
|
37
38
|
SIZE: 0,
|
|
38
39
|
EXPIRES: 0,
|
|
39
|
-
LIMIT:
|
|
40
|
-
LIMIT_ALL:
|
|
40
|
+
LIMIT: formatSize("100mb"),
|
|
41
|
+
LIMIT_ALL: formatSize("512mb"),
|
|
41
42
|
INCLUDE: [],
|
|
42
43
|
EXCLUDE: [],
|
|
43
44
|
PURGE: 0.25,
|
|
@@ -70,7 +71,7 @@ let SESSION_ID = 0;
|
|
|
70
71
|
let SESSION_LIMIT = 1000;
|
|
71
72
|
let ASSET_ID = 0;
|
|
72
73
|
let RETRY_LIMIT = 10;
|
|
73
|
-
let PROCESS_SUB_LIMIT =
|
|
74
|
+
let PROCESS_SUB_LIMIT = Host.availableParallelism(2);
|
|
74
75
|
let LOG_TIMEELAPSED = true;
|
|
75
76
|
let LOG_TIMEPROCESS = true;
|
|
76
77
|
const HTTP_CLIENT = {
|
|
@@ -93,7 +94,7 @@ function parseTimeout(value) {
|
|
|
93
94
|
if (+value === 0) {
|
|
94
95
|
return 0;
|
|
95
96
|
}
|
|
96
|
-
if ((value =
|
|
97
|
+
if ((value = parseTime(value)) > 0) {
|
|
97
98
|
return value;
|
|
98
99
|
}
|
|
99
100
|
return -1;
|
|
@@ -102,7 +103,7 @@ function withinSizeRange(uri, value, pattern) {
|
|
|
102
103
|
const match = (pattern || /\(\s*(\d+)\s*(?:,\s*(\d+|\*)\s*)?\)/).exec(value);
|
|
103
104
|
const [minSize, maxSize] = match && !match[1] ? [+match[2], !match[3] || match[3] === '*' ? Infinity : +match[3]] : [0, Infinity];
|
|
104
105
|
if (minSize > 0 || maxSize < Infinity) {
|
|
105
|
-
const fileSize =
|
|
106
|
+
const fileSize = getSize(uri);
|
|
106
107
|
if (fileSize === 0 || fileSize < minSize || fileSize > maxSize) {
|
|
107
108
|
return false;
|
|
108
109
|
}
|
|
@@ -112,7 +113,7 @@ function withinSizeRange(uri, value, pattern) {
|
|
|
112
113
|
function bundleTorrent(host, files, mimeType, encoding) {
|
|
113
114
|
let output = '';
|
|
114
115
|
for (const file of files) {
|
|
115
|
-
if (
|
|
116
|
+
if (Host.lookupMime(file) === mimeType) {
|
|
116
117
|
try {
|
|
117
118
|
output += fs.readFileSync(file, encoding);
|
|
118
119
|
}
|
|
@@ -126,10 +127,10 @@ function bundleTorrent(host, files, mimeType, encoding) {
|
|
|
126
127
|
function recurseDir(output, subDirs, options) {
|
|
127
128
|
const { ignore, ignoreRoot, sortBy, recursive } = options;
|
|
128
129
|
const fromDir = subDirs.length > 1 ? path.posix.join(...subDirs.slice(1)) : null;
|
|
129
|
-
if (ignoreRoot.length > 0 && fromDir && pm.isMatch(fromDir + '/', ignoreRoot,
|
|
130
|
+
if (ignoreRoot.length > 0 && fromDir && pm.isMatch(fromDir + '/', ignoreRoot, Host.PLATFORM_WIN32 ? { nocase: true } : undefined)) {
|
|
130
131
|
return output;
|
|
131
132
|
}
|
|
132
|
-
const ignoreGlob = ignore.length > 0 ? pm(ignore,
|
|
133
|
+
const ignoreGlob = ignore.length > 0 ? pm(ignore, Host.PLATFORM_WIN32 ? { nocase: true, matchBase: true } : { matchBase: true }) : null;
|
|
133
134
|
const baseDir = path.join(...subDirs);
|
|
134
135
|
const items = fs.readdirSync(baseDir, { withFileTypes: true })
|
|
135
136
|
.filter(item => {
|
|
@@ -152,12 +153,12 @@ function recurseDir(output, subDirs, options) {
|
|
|
152
153
|
for (const item of items) {
|
|
153
154
|
if (!item.isDirectory()) {
|
|
154
155
|
const pathname = path.join(baseDir, item.name);
|
|
155
|
-
if (item.isSymbolicLink() &&
|
|
156
|
+
if (item.isSymbolicLink() && Host.isDir(pathname) || ignore.length > 0 && (Host.PLATFORM_WIN32 ? ignore.includes(pathname.toLowerCase()) : ignore.includes(pathname))) {
|
|
156
157
|
continue;
|
|
157
158
|
}
|
|
158
159
|
output.push(pathname);
|
|
159
160
|
}
|
|
160
|
-
else if (recursive && (subDirs.length > 1 || (
|
|
161
|
+
else if (recursive && (subDirs.length > 1 || (Host.PLATFORM_WIN32 ? !ignoreRoot.includes(item.name.toLowerCase()) : !ignoreRoot.includes(item.name)))) {
|
|
161
162
|
recurseDir(output, subDirs.concat(item.name), options);
|
|
162
163
|
}
|
|
163
164
|
}
|
|
@@ -171,10 +172,10 @@ function createMatchNegate(patterns, options) {
|
|
|
171
172
|
for (let value of patterns) {
|
|
172
173
|
let invert = false;
|
|
173
174
|
if (value.startsWith('!')) {
|
|
174
|
-
value = value.
|
|
175
|
+
value = value.slice(1);
|
|
175
176
|
invert = true;
|
|
176
177
|
}
|
|
177
|
-
value =
|
|
178
|
+
value = Permission.toPosix(value);
|
|
178
179
|
const match = pm(value, getPmOptions(value, options));
|
|
179
180
|
if (path.isAbsolute(value)) {
|
|
180
181
|
(invert ? negateAbs : baseAbs).push(match);
|
|
@@ -190,30 +191,30 @@ function isMatch(value, globs) {
|
|
|
190
191
|
}
|
|
191
192
|
function filterPaths(rootDir, values, options = {}) {
|
|
192
193
|
let { include, exclude } = options;
|
|
193
|
-
rootDir =
|
|
194
|
+
rootDir = Host.normalizePath(rootDir, 2);
|
|
194
195
|
if (include) {
|
|
195
|
-
if (
|
|
196
|
+
if (isString(include)) {
|
|
196
197
|
include = [include];
|
|
197
198
|
}
|
|
198
|
-
if (
|
|
199
|
+
if (isArray(include)) {
|
|
199
200
|
const [glob, globAbs] = createMatchNegate(include, options);
|
|
200
201
|
for (let i = 0; i < values.length; ++i) {
|
|
201
202
|
const value = values[i];
|
|
202
|
-
if (!isMatch(value, globAbs) && !isMatch(value.
|
|
203
|
+
if (!isMatch(value, globAbs) && !isMatch(value.slice(rootDir.length), glob)) {
|
|
203
204
|
values.splice(i--, 1);
|
|
204
205
|
}
|
|
205
206
|
}
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
209
|
if (exclude) {
|
|
209
|
-
if (
|
|
210
|
+
if (isString(exclude)) {
|
|
210
211
|
exclude = [exclude];
|
|
211
212
|
}
|
|
212
|
-
if (
|
|
213
|
+
if (isArray(exclude)) {
|
|
213
214
|
const [glob, globAbs] = createMatchNegate(exclude, options);
|
|
214
215
|
for (let i = 0; i < values.length; ++i) {
|
|
215
216
|
const value = values[i];
|
|
216
|
-
if (isMatch(value, globAbs) || isMatch(value.
|
|
217
|
+
if (isMatch(value, globAbs) || isMatch(value.slice(rootDir.length), glob)) {
|
|
217
218
|
values.splice(i--, 1);
|
|
218
219
|
}
|
|
219
220
|
}
|
|
@@ -228,7 +229,7 @@ function formatMinutes(elapsed) {
|
|
|
228
229
|
if (elapsed < 60000) {
|
|
229
230
|
return (elapsed / 1000).toPrecision(3) + 's';
|
|
230
231
|
}
|
|
231
|
-
return
|
|
232
|
+
return formatTime(elapsed, ':');
|
|
232
233
|
}
|
|
233
234
|
function clearQueue(data, attr) {
|
|
234
235
|
if (attr && data[attr]) {
|
|
@@ -239,7 +240,7 @@ function clearQueue(data, attr) {
|
|
|
239
240
|
}
|
|
240
241
|
}
|
|
241
242
|
function hasEtag(item, cacheable, fallback) {
|
|
242
|
-
if (!cacheable || !
|
|
243
|
+
if (!cacheable || !existsFlag(item)) {
|
|
243
244
|
return false;
|
|
244
245
|
}
|
|
245
246
|
switch (item.incremental) {
|
|
@@ -298,28 +299,13 @@ function unsetContent(item) {
|
|
|
298
299
|
}
|
|
299
300
|
}
|
|
300
301
|
async function doVerifyChecksum(root, from, options, nested) {
|
|
301
|
-
const { digestEncoding
|
|
302
|
+
const { digestEncoding, sortBy = 0, recursive = false, ignore = [], ignoreRoot = [], verbose = true, joinRoot } = options;
|
|
302
303
|
const parent = recursive === 1 && typeof verbose !== 'number';
|
|
303
304
|
let algorithm = options.algorithm;
|
|
304
305
|
from ||= checksumFile(algorithm);
|
|
305
|
-
|
|
306
|
-
switch (algorithm = path.extname(from).substring(1).toLowerCase()) {
|
|
307
|
-
case 'md5':
|
|
308
|
-
case 'sha1':
|
|
309
|
-
case 'sha224':
|
|
310
|
-
case 'sha256':
|
|
311
|
-
case 'sha384':
|
|
312
|
-
case 'sha512':
|
|
313
|
-
case 'ripemd':
|
|
314
|
-
case 'ripemd-160':
|
|
315
|
-
break;
|
|
316
|
-
default:
|
|
317
|
-
algorithm = undefined;
|
|
318
|
-
break;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
306
|
+
algorithm ||= getAlgorithm(asExt(from));
|
|
321
307
|
if (verbose) {
|
|
322
|
-
|
|
308
|
+
setLogCurrent(null);
|
|
323
309
|
}
|
|
324
310
|
let pass = 0, fail = [], missing = [];
|
|
325
311
|
try {
|
|
@@ -329,7 +315,7 @@ async function doVerifyChecksum(root, from, options, nested) {
|
|
|
329
315
|
recurseDir(files, [root], { ignore: mapPosix([...ignore, from]), ignoreRoot: mapPosix(ignoreRoot), sortBy, recursive });
|
|
330
316
|
const items = fs.readFileSync(from, 'utf8').split('\n').map(item => {
|
|
331
317
|
const index = item.indexOf(' ');
|
|
332
|
-
return [item.
|
|
318
|
+
return [item.slice(0, index), path.join(root, item.slice(index + 1))];
|
|
333
319
|
});
|
|
334
320
|
const checked = options.include || options.exclude ? filterPaths(root, items.map(item => item[1]), options) : null;
|
|
335
321
|
let valid = false;
|
|
@@ -443,7 +429,7 @@ function setHttpCache(value, type, disk) {
|
|
|
443
429
|
return;
|
|
444
430
|
}
|
|
445
431
|
if (typeof value === 'string') {
|
|
446
|
-
value =
|
|
432
|
+
value = formatSize(value);
|
|
447
433
|
}
|
|
448
434
|
if (value >= 0) {
|
|
449
435
|
switch (type) {
|
|
@@ -480,20 +466,20 @@ function setLogMinWidth() {
|
|
|
480
466
|
}
|
|
481
467
|
const downloadStats = () => [[0, 0], [0, 0], [0, 0]];
|
|
482
468
|
const isCacheable = (item) => item.initialValue?.cacheable !== false;
|
|
483
|
-
const getPmOptions = (value, { matchBase = value.startsWith('*') && !value.includes('/'), dot = false } = {}) => ({ nocase:
|
|
469
|
+
const getPmOptions = (value, { matchBase = value.startsWith('*') && !value.includes('/'), dot = false } = {}) => ({ nocase: Host.PLATFORM_WIN32, matchBase, dot });
|
|
484
470
|
const isDownloadAll = (type) => type === 4 || type === 0;
|
|
485
|
-
const hasFiles = (type, uri) => type === 3 || type === 4 || type === 0 &&
|
|
471
|
+
const hasFiles = (type, uri) => type === 3 || type === 4 || type === 0 && Request.isRclone(uri);
|
|
486
472
|
const hasIncremental = (value) => value === "etag" || value === "exists";
|
|
487
|
-
const matchPathname = (value) =>
|
|
488
|
-
const mapPosix = (values) =>
|
|
473
|
+
const matchPathname = (value) => Host.PLATFORM_WIN32 ? value.toLowerCase() : value;
|
|
474
|
+
const mapPosix = (values) => Host.PLATFORM_WIN32 ? values.map(value => Permission.toPosix(value).toLowerCase()) : values;
|
|
489
475
|
const formatPercent = (value) => Math.round(value).toString().padStart(3) + '%';
|
|
490
476
|
const formatLength = (value, length) => `${length} ${value + (length === 1 ? '' : 's')}`;
|
|
491
477
|
const checkEOF = (value) => value.endsWith('\n') ? value : value + '\n';
|
|
492
|
-
const checksumFile = (algorithm) => "checksum" + '.' + (
|
|
493
|
-
const ignoreAsset = (item, exists) => item.invalid ||
|
|
478
|
+
const checksumFile = (algorithm) => "checksum" + '.' + (isString(algorithm) ? algorithm.toLowerCase() : "sha256");
|
|
479
|
+
const ignoreAsset = (item, exists) => item.invalid || hasBit(item.flags, 1 | (!exists ? 128 : 0));
|
|
494
480
|
const validateChecksum = (host, item, buffer, localUri = item.localUri) => !item.checksum || host.checkHash(item.checksum, buffer, localUri);
|
|
495
|
-
const errorChecksum = (algorithm) =>
|
|
496
|
-
const errorAbsolute = (hint) =>
|
|
481
|
+
const errorChecksum = (algorithm) => errorValue("Invalid parameters", algorithm || "sha256");
|
|
482
|
+
const errorAbsolute = (hint) => errorValue("Path is not absolute", hint);
|
|
497
483
|
class Scheduler {
|
|
498
484
|
id = 0;
|
|
499
485
|
count = 0;
|
|
@@ -513,7 +499,7 @@ class Scheduler {
|
|
|
513
499
|
#columns = -1;
|
|
514
500
|
add(id, url) {
|
|
515
501
|
if (url.length > LOGGER.VALUE_WIDTH) {
|
|
516
|
-
url = url.
|
|
502
|
+
url = url.slice(0, LOGGER.VALUE_WIDTH - 3) + '...';
|
|
517
503
|
}
|
|
518
504
|
else {
|
|
519
505
|
url = url.padEnd(LOGGER.VALUE_WIDTH);
|
|
@@ -585,7 +571,7 @@ class Scheduler {
|
|
|
585
571
|
return width >= 10 ? Math.max(Math.min(width, LOGGER.PROGRESS_MAXWIDTH), 10) : -1;
|
|
586
572
|
}
|
|
587
573
|
get rawMode() {
|
|
588
|
-
return
|
|
574
|
+
return Host.PLATFORM_WIN32 && LOGGER.PROGRESS_RAWMODE;
|
|
589
575
|
}
|
|
590
576
|
}
|
|
591
577
|
class TaskStatus {
|
|
@@ -636,7 +622,7 @@ class HttpDiskCache {
|
|
|
636
622
|
return true;
|
|
637
623
|
}
|
|
638
624
|
if (flags & (2 | 8)) {
|
|
639
|
-
const ext =
|
|
625
|
+
const ext = asExt(uri.pathname);
|
|
640
626
|
if (ext) {
|
|
641
627
|
if (flags & 2) {
|
|
642
628
|
if (!this._includeExt.some(value => value === ext)) {
|
|
@@ -653,7 +639,7 @@ class HttpDiskCache {
|
|
|
653
639
|
}
|
|
654
640
|
return true;
|
|
655
641
|
}
|
|
656
|
-
add(uri, etag, target, { buffer, contentLength =
|
|
642
|
+
add(uri, etag, target, { buffer, contentLength = getSize(target) } = {}) {
|
|
657
643
|
let tempDir;
|
|
658
644
|
if (contentLength <= this.limit && (tempDir = this.host.getCacheDir(uri))) {
|
|
659
645
|
const baseDir = path.join(tempDir, etag);
|
|
@@ -672,7 +658,7 @@ class HttpDiskCache {
|
|
|
672
658
|
if (expires > 0 && expires < Infinity) {
|
|
673
659
|
setTimeout(() => {
|
|
674
660
|
this.clear(target);
|
|
675
|
-
}, Math.min(expires,
|
|
661
|
+
}, Math.min(expires, Host.MAX_TIMEOUT));
|
|
676
662
|
}
|
|
677
663
|
}
|
|
678
664
|
catch {
|
|
@@ -686,7 +672,7 @@ class HttpDiskCache {
|
|
|
686
672
|
return value > 0 && value <= this.limit;
|
|
687
673
|
}
|
|
688
674
|
clear(pathname) {
|
|
689
|
-
|
|
675
|
+
Host.removeDir(path.dirname(pathname));
|
|
690
676
|
}
|
|
691
677
|
set enabled(value) {
|
|
692
678
|
this.#enabled = value;
|
|
@@ -697,9 +683,9 @@ class HttpDiskCache {
|
|
|
697
683
|
set include(value) {
|
|
698
684
|
this._include = [];
|
|
699
685
|
this._includeExt = [];
|
|
700
|
-
if (
|
|
686
|
+
if (isArray(value)) {
|
|
701
687
|
for (const item of value) {
|
|
702
|
-
if (
|
|
688
|
+
if (Host.isURL(item)) {
|
|
703
689
|
this._include.push(item);
|
|
704
690
|
this._flags |= 1;
|
|
705
691
|
}
|
|
@@ -719,9 +705,9 @@ class HttpDiskCache {
|
|
|
719
705
|
set exclude(value) {
|
|
720
706
|
this._exclude = [];
|
|
721
707
|
this._excludeExt = [];
|
|
722
|
-
if (
|
|
708
|
+
if (isArray(value)) {
|
|
723
709
|
for (const item of value) {
|
|
724
|
-
if (
|
|
710
|
+
if (Host.isURL(item)) {
|
|
725
711
|
this._exclude.push(item);
|
|
726
712
|
this._flags |= 4;
|
|
727
713
|
}
|
|
@@ -744,7 +730,7 @@ class HttpMemoryCache extends HttpDiskCache {
|
|
|
744
730
|
expires = MEMORY.EXPIRES;
|
|
745
731
|
toDisk = [MEMORY.DISK_MIN, MEMORY.DISK_MAX];
|
|
746
732
|
constructor(host, enabled) {
|
|
747
|
-
super(host, enabled &&
|
|
733
|
+
super(host, enabled && Host.enabled("memory.settings.users", host.username));
|
|
748
734
|
if (MEMORY.INCLUDE.length > 0) {
|
|
749
735
|
this.include = MEMORY.INCLUDE;
|
|
750
736
|
}
|
|
@@ -770,7 +756,7 @@ class HttpMemoryCache extends HttpDiskCache {
|
|
|
770
756
|
if (this.expires < Infinity) {
|
|
771
757
|
setTimeout(() => {
|
|
772
758
|
this.clear(uri);
|
|
773
|
-
}, Math.min(this.expires,
|
|
759
|
+
}, Math.min(this.expires, Host.MAX_TIMEOUT));
|
|
774
760
|
}
|
|
775
761
|
}
|
|
776
762
|
else {
|
|
@@ -846,15 +832,15 @@ class ProcessFile {
|
|
|
846
832
|
createFolder(pathname, emptyDir) {
|
|
847
833
|
const emptied = this.groupData.emptied;
|
|
848
834
|
if (!emptied.includes(pathname)) {
|
|
849
|
-
if (emptyDir &&
|
|
835
|
+
if (emptyDir && Host.removeDir(pathname, true)) {
|
|
850
836
|
emptied.push(pathname);
|
|
851
837
|
}
|
|
852
|
-
else if (
|
|
838
|
+
else if (Host.createDir(pathname)) {
|
|
853
839
|
emptied.push(pathname);
|
|
854
840
|
}
|
|
855
841
|
else {
|
|
856
842
|
this.file.invalid = true;
|
|
857
|
-
this.host.writeFail("Unable to create directory",
|
|
843
|
+
this.host.writeFail("Unable to create directory", errorValue("Path not found", pathname));
|
|
858
844
|
return false;
|
|
859
845
|
}
|
|
860
846
|
}
|
|
@@ -866,7 +852,7 @@ class ProcessFile {
|
|
|
866
852
|
}
|
|
867
853
|
const { host, groupData: group, file, localUri } = this;
|
|
868
854
|
const { bundleId, bundleIndex = -1 } = file;
|
|
869
|
-
if (!
|
|
855
|
+
if (!isEmpty(bundleId) && bundleIndex >= 0) {
|
|
870
856
|
const items = group.appending[localUri] ||= [];
|
|
871
857
|
group.bundling[file.uri] ||= [];
|
|
872
858
|
if (bundleIndex > 0) {
|
|
@@ -925,7 +911,7 @@ class ProcessFile {
|
|
|
925
911
|
file.invalid = true;
|
|
926
912
|
host.filesToRemove.add(localUri);
|
|
927
913
|
host.completeAsyncTask();
|
|
928
|
-
host.writeFail(["Checksum did not match", path.basename(localUri)],
|
|
914
|
+
host.writeFail(["Checksum did not match", path.basename(localUri)], errorValue(file.uri || localUri, "Invalid checksum"), { type: 32, queue: true });
|
|
929
915
|
}
|
|
930
916
|
else {
|
|
931
917
|
if (fetched) {
|
|
@@ -951,7 +937,7 @@ class ProcessFile {
|
|
|
951
937
|
let items = uriMap.get(destUri);
|
|
952
938
|
if (!items) {
|
|
953
939
|
const pathname = path.dirname(destUri);
|
|
954
|
-
if (!
|
|
940
|
+
if (!Host.createDir(pathname)) {
|
|
955
941
|
file.invalid = true;
|
|
956
942
|
continue;
|
|
957
943
|
}
|
|
@@ -984,7 +970,7 @@ class ProcessFile {
|
|
|
984
970
|
}
|
|
985
971
|
async finalize(incremental) {
|
|
986
972
|
const { host, file, localUri, groupData } = this;
|
|
987
|
-
const bundleStart = file.bundleIndex === 0 && !
|
|
973
|
+
const bundleStart = file.bundleIndex === 0 && !isEmpty(file.bundleId) ? host.incremental !== "staging" && host.retryLimit === RETRY_LIMIT ? 2 : 1 : 0;
|
|
988
974
|
groupData.completed[localUri] = file;
|
|
989
975
|
if (bundleStart > 0) {
|
|
990
976
|
host.setAssetContent(file, host.getUTF8String(file, localUri));
|
|
@@ -1057,7 +1043,7 @@ class ProcessFile {
|
|
|
1057
1043
|
const source = cached[1];
|
|
1058
1044
|
if (validateChecksum(host, queue, source, localUri)) {
|
|
1059
1045
|
verifyBundle(typeof source === 'string' ? source : source.toString(encoding), '', true);
|
|
1060
|
-
host.addDownload(Buffer.byteLength(source, encoding),
|
|
1046
|
+
host.addDownload(Buffer.byteLength(source, encoding), DOWNLOAD_TYPE.CACHE);
|
|
1061
1047
|
continue;
|
|
1062
1048
|
}
|
|
1063
1049
|
}
|
|
@@ -1069,18 +1055,18 @@ class ProcessFile {
|
|
|
1069
1055
|
const baseDir = path.join(host.getCacheDir(url), etagDir);
|
|
1070
1056
|
pipeTo = path.join(baseDir, path.basename(localUri));
|
|
1071
1057
|
try {
|
|
1072
|
-
if (valid &&
|
|
1058
|
+
if (valid && hasSize(pipeTo)) {
|
|
1073
1059
|
const buffer = fs.readFileSync(pipeTo, { encoding });
|
|
1074
1060
|
if (validateChecksum(host, queue, localUri, buffer)) {
|
|
1075
1061
|
verifyBundle(buffer, etag, true);
|
|
1076
|
-
host.addDownload(Buffer.byteLength(buffer, encoding),
|
|
1062
|
+
host.addDownload(Buffer.byteLength(buffer, encoding), DOWNLOAD_TYPE.CACHE);
|
|
1077
1063
|
continue;
|
|
1078
1064
|
}
|
|
1079
1065
|
}
|
|
1080
1066
|
if (!fs.existsSync(baseDir)) {
|
|
1081
1067
|
fs.mkdirSync(baseDir);
|
|
1082
1068
|
}
|
|
1083
|
-
tempFile = path.join(baseDir,
|
|
1069
|
+
tempFile = path.join(baseDir, incrementUUID());
|
|
1084
1070
|
options.pipeTo = tempFile;
|
|
1085
1071
|
}
|
|
1086
1072
|
catch {
|
|
@@ -1105,7 +1091,7 @@ class ProcessFile {
|
|
|
1105
1091
|
queue.invalid = true;
|
|
1106
1092
|
}
|
|
1107
1093
|
const downloaded = groupData.bundling[uri];
|
|
1108
|
-
if (
|
|
1094
|
+
if (isArray(downloaded)) {
|
|
1109
1095
|
if (data && !queue.invalid) {
|
|
1110
1096
|
if (typeof data === 'string') {
|
|
1111
1097
|
queue.sourceUTF8 = data;
|
|
@@ -1121,7 +1107,7 @@ class ProcessFile {
|
|
|
1121
1107
|
}
|
|
1122
1108
|
}
|
|
1123
1109
|
}
|
|
1124
|
-
if (tempFile && (!pipeTo ||
|
|
1110
|
+
if (tempFile && (!pipeTo || Host.isPath(pipeTo) || !Host.renameFile(tempFile, pipeTo, false))) {
|
|
1125
1111
|
queueMicrotask(() => fs.unlink(tempFile, () => { }));
|
|
1126
1112
|
}
|
|
1127
1113
|
resolve();
|
|
@@ -1138,10 +1124,10 @@ class ProcessFile {
|
|
|
1138
1124
|
const mimeType = queue.mimeType || file.mimeType;
|
|
1139
1125
|
if (!mimeType) {
|
|
1140
1126
|
queue.invalid = true;
|
|
1141
|
-
tasks.push(Promise.reject(
|
|
1127
|
+
tasks.push(Promise.reject(errorValue("MIME not found", uri)));
|
|
1142
1128
|
break;
|
|
1143
1129
|
}
|
|
1144
|
-
const pathname =
|
|
1130
|
+
const pathname = getTempDir(true);
|
|
1145
1131
|
tasks.push(new Promise((resolve, reject) => {
|
|
1146
1132
|
void host.scheduleTask(queue.url || uri, { pathname, binOpts: queue.binOpts || file.binOpts }, (result) => {
|
|
1147
1133
|
if (result.length > 0) {
|
|
@@ -1161,7 +1147,7 @@ class ProcessFile {
|
|
|
1161
1147
|
tasks.push(fs.promises.readFile(uri, encoding)
|
|
1162
1148
|
.then(data => {
|
|
1163
1149
|
verifyBundle(data);
|
|
1164
|
-
host.addDownload(Buffer.byteLength(data, encoding),
|
|
1150
|
+
host.addDownload(Buffer.byteLength(data, encoding), DOWNLOAD_TYPE.DISK);
|
|
1165
1151
|
})
|
|
1166
1152
|
.catch(() => {
|
|
1167
1153
|
queue.invalid = true;
|
|
@@ -1181,7 +1167,7 @@ class ProcessFile {
|
|
|
1181
1167
|
return false;
|
|
1182
1168
|
});
|
|
1183
1169
|
}
|
|
1184
|
-
else if (checkEtag &&
|
|
1170
|
+
else if (checkEtag && Host.isPath(localUri)) {
|
|
1185
1171
|
host.completeAsyncTask();
|
|
1186
1172
|
groupData.appending[localUri] = undefined;
|
|
1187
1173
|
return;
|
|
@@ -1209,7 +1195,7 @@ class ProcessFile {
|
|
|
1209
1195
|
const uri = file.uri;
|
|
1210
1196
|
const processed = processing[localUri];
|
|
1211
1197
|
const downloaded = downloading[uri];
|
|
1212
|
-
if (
|
|
1198
|
+
if (isArray(downloaded)) {
|
|
1213
1199
|
this.copyDownload(file, downloaded);
|
|
1214
1200
|
}
|
|
1215
1201
|
if (processed) {
|
|
@@ -1242,14 +1228,14 @@ class ProcessFile {
|
|
|
1242
1228
|
if (!preceding) {
|
|
1243
1229
|
host.completeAsyncTask();
|
|
1244
1230
|
}
|
|
1245
|
-
host.writeFail(["Unable to download file", uri], err, err
|
|
1231
|
+
host.writeFail(["Unable to download file", uri], err, isError(err) && err.message.startsWith("Timeout was exceeded") ? 16384 : 1024);
|
|
1246
1232
|
}
|
|
1247
1233
|
}
|
|
1248
|
-
class FileThread extends
|
|
1234
|
+
class FileThread extends AbortComponent {
|
|
1249
1235
|
file;
|
|
1250
1236
|
threadCount;
|
|
1251
|
-
mimeType = '';
|
|
1252
1237
|
startTime = Date.now();
|
|
1238
|
+
#mimeType = '';
|
|
1253
1239
|
#host;
|
|
1254
1240
|
#queuedTasks = [];
|
|
1255
1241
|
constructor(host, file, threadCount) {
|
|
@@ -1278,8 +1264,16 @@ class FileThread extends core_1.AbortComponent {
|
|
|
1278
1264
|
get localUri() {
|
|
1279
1265
|
return this.file.localUri;
|
|
1280
1266
|
}
|
|
1267
|
+
set mimeType(value) {
|
|
1268
|
+
if (typeof value === 'string') {
|
|
1269
|
+
this.#mimeType = value;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
get mimeType() {
|
|
1273
|
+
return this.#mimeType;
|
|
1274
|
+
}
|
|
1281
1275
|
}
|
|
1282
|
-
class FileManager extends
|
|
1276
|
+
class FileManager extends Host {
|
|
1283
1277
|
static [kFileManager] = true;
|
|
1284
1278
|
static async purgeMemory(percent = 1, limit = 0, parent) {
|
|
1285
1279
|
if (typeof limit === 'boolean') {
|
|
@@ -1319,7 +1313,7 @@ class FileManager extends core_1.Host {
|
|
|
1319
1313
|
return false;
|
|
1320
1314
|
}
|
|
1321
1315
|
const { process: proc, memory, download, request, error, logger } = settings;
|
|
1322
|
-
const sub_limit =
|
|
1316
|
+
const sub_limit = asInt(proc?.thread?.sub_limit);
|
|
1323
1317
|
if (sub_limit > 0) {
|
|
1324
1318
|
PROCESS_SUB_LIMIT = sub_limit;
|
|
1325
1319
|
}
|
|
@@ -1329,7 +1323,7 @@ class FileManager extends core_1.Host {
|
|
|
1329
1323
|
}
|
|
1330
1324
|
if (request) {
|
|
1331
1325
|
let { timeout, disk, buffer, connect } = request;
|
|
1332
|
-
if ((timeout =
|
|
1326
|
+
if ((timeout = fromSeconds(timeout)) >= 0) {
|
|
1333
1327
|
HTTP_CLIENT.timeout = timeout;
|
|
1334
1328
|
}
|
|
1335
1329
|
if (disk) {
|
|
@@ -1341,10 +1335,10 @@ class FileManager extends core_1.Host {
|
|
|
1341
1335
|
if (connect) {
|
|
1342
1336
|
this.defineHttpConnect(connect);
|
|
1343
1337
|
}
|
|
1344
|
-
|
|
1338
|
+
Request.loadSettings({ process: settings.process, request, download }, password);
|
|
1345
1339
|
}
|
|
1346
|
-
if (error) {
|
|
1347
|
-
const limit =
|
|
1340
|
+
if (error?.retry_limit) {
|
|
1341
|
+
const limit = asInt(error.retry_limit);
|
|
1348
1342
|
if (limit >= 0 && limit < Infinity) {
|
|
1349
1343
|
RETRY_LIMIT = limit;
|
|
1350
1344
|
}
|
|
@@ -1362,13 +1356,13 @@ class FileManager extends core_1.Host {
|
|
|
1362
1356
|
}
|
|
1363
1357
|
if (logger.progress) {
|
|
1364
1358
|
let { scroll_buffer, max_width, use_color, text_wrap, color, bg_color, raw_mode, box_char } = logger.progress;
|
|
1365
|
-
if ((scroll_buffer =
|
|
1359
|
+
if ((scroll_buffer = asInt(scroll_buffer)) >= 0 && scroll_buffer <= 16) {
|
|
1366
1360
|
LOGGER.PROGRESS_SCROLLBUFFER = scroll_buffer;
|
|
1367
1361
|
}
|
|
1368
1362
|
if (max_width === 'auto' || max_width === '100%') {
|
|
1369
1363
|
LOGGER.PROGRESS_MAXWIDTH = Infinity;
|
|
1370
1364
|
}
|
|
1371
|
-
else if ((max_width =
|
|
1365
|
+
else if ((max_width = asInt(max_width)) >= 10) {
|
|
1372
1366
|
LOGGER.PROGRESS_MAXWIDTH = max_width;
|
|
1373
1367
|
}
|
|
1374
1368
|
if (typeof use_color === 'boolean') {
|
|
@@ -1382,18 +1376,18 @@ class FileManager extends core_1.Host {
|
|
|
1382
1376
|
LOGGER.PROGRESS_TEXTWRAP = text_wrap;
|
|
1383
1377
|
break;
|
|
1384
1378
|
}
|
|
1385
|
-
if (
|
|
1379
|
+
if (isString(color)) {
|
|
1386
1380
|
LOGGER.PROGRESS_COLOR = color;
|
|
1387
1381
|
}
|
|
1388
|
-
if (
|
|
1382
|
+
if (isString(bg_color)) {
|
|
1389
1383
|
LOGGER.PROGRESS_BGCOLOR = bg_color;
|
|
1390
1384
|
}
|
|
1391
|
-
if (
|
|
1385
|
+
if (isString(box_char) && box_char.length === 1) {
|
|
1392
1386
|
LOGGER.PROGRESS_BOXCHAR = box_char;
|
|
1393
1387
|
}
|
|
1394
1388
|
if (typeof raw_mode === 'boolean') {
|
|
1395
1389
|
LOGGER.PROGRESS_RAWMODE = raw_mode;
|
|
1396
|
-
if (raw_mode &&
|
|
1390
|
+
if (raw_mode && Host.PLATFORM_WIN32) {
|
|
1397
1391
|
require('readline').emitKeypressEvents(PROCESS_STDIN);
|
|
1398
1392
|
}
|
|
1399
1393
|
}
|
|
@@ -1415,7 +1409,7 @@ class FileManager extends core_1.Host {
|
|
|
1415
1409
|
}
|
|
1416
1410
|
static sanitizeAssets(assets, exclusions = []) {
|
|
1417
1411
|
for (const item of assets) {
|
|
1418
|
-
if (
|
|
1412
|
+
if (ignoreFlag(item)) {
|
|
1419
1413
|
continue;
|
|
1420
1414
|
}
|
|
1421
1415
|
const initialValue = item.initialValue;
|
|
@@ -1431,7 +1425,7 @@ class FileManager extends core_1.Host {
|
|
|
1431
1425
|
item.flags &= ~(128 | 16);
|
|
1432
1426
|
break;
|
|
1433
1427
|
case 'watch':
|
|
1434
|
-
if (
|
|
1428
|
+
if (isObject(item.watch) && item.watch.assets) {
|
|
1435
1429
|
delete item.watch.assets;
|
|
1436
1430
|
}
|
|
1437
1431
|
case 'buffer':
|
|
@@ -1456,14 +1450,14 @@ class FileManager extends core_1.Host {
|
|
|
1456
1450
|
return assets;
|
|
1457
1451
|
}
|
|
1458
1452
|
static async writeChecksum(root, to, options) {
|
|
1459
|
-
if (
|
|
1453
|
+
if (isObject(to)) {
|
|
1460
1454
|
options = to;
|
|
1461
1455
|
to = undefined;
|
|
1462
1456
|
}
|
|
1463
1457
|
else {
|
|
1464
1458
|
options ||= {};
|
|
1465
1459
|
}
|
|
1466
|
-
const { algorithm, digestEncoding
|
|
1460
|
+
const { algorithm, digestEncoding, sortBy = 0, recursive = false, ignore = [], ignoreRoot = [], verbose = false, joinRoot } = options;
|
|
1467
1461
|
to ||= checksumFile(algorithm);
|
|
1468
1462
|
let result = [];
|
|
1469
1463
|
try {
|
|
@@ -1475,7 +1469,7 @@ class FileManager extends core_1.Host {
|
|
|
1475
1469
|
if (recursive === 1 && path.basename(pathname) === filename) {
|
|
1476
1470
|
continue;
|
|
1477
1471
|
}
|
|
1478
|
-
const current = await this.readHash(pathname, { algorithm, digestEncoding }) + ' ' +
|
|
1472
|
+
const current = await this.readHash(pathname, { algorithm, digestEncoding }) + ' ' + Permission.toPosix(pathname).slice(root.length).replace(/^\//, '');
|
|
1479
1473
|
if (verbose) {
|
|
1480
1474
|
process.stdout.write(current + '\n');
|
|
1481
1475
|
}
|
|
@@ -1504,7 +1498,7 @@ class FileManager extends core_1.Host {
|
|
|
1504
1498
|
return result;
|
|
1505
1499
|
}
|
|
1506
1500
|
static async verifyChecksum(root, from, options) {
|
|
1507
|
-
if (
|
|
1501
|
+
if (isObject(from)) {
|
|
1508
1502
|
options = from;
|
|
1509
1503
|
from = undefined;
|
|
1510
1504
|
}
|
|
@@ -1521,9 +1515,9 @@ class FileManager extends core_1.Host {
|
|
|
1521
1515
|
if (typeof enabled === 'boolean') {
|
|
1522
1516
|
cache.ENABLED = enabled;
|
|
1523
1517
|
}
|
|
1524
|
-
cache.EXPIRES = expires ?
|
|
1525
|
-
cache.INCLUDE =
|
|
1526
|
-
cache.EXCLUDE =
|
|
1518
|
+
cache.EXPIRES = expires ? parseExpires(expires) : 0;
|
|
1519
|
+
cache.INCLUDE = isArray(include) ? include.slice(0) : [];
|
|
1520
|
+
cache.EXCLUDE = isArray(exclude) ? exclude.slice(0) : [];
|
|
1527
1521
|
setHttpCache(limit, 1, disk);
|
|
1528
1522
|
if (disk) {
|
|
1529
1523
|
return;
|
|
@@ -1537,24 +1531,24 @@ class FileManager extends core_1.Host {
|
|
|
1537
1531
|
setHttpCache(to_disk, 3, disk);
|
|
1538
1532
|
setHttpCache(limit_disk, 4, disk);
|
|
1539
1533
|
}
|
|
1540
|
-
if ((purge_amount =
|
|
1534
|
+
if ((purge_amount = asFloat(purge_amount)) > 0) {
|
|
1541
1535
|
MEMORY.PURGE = Math.min(purge_amount, 1);
|
|
1542
1536
|
}
|
|
1543
1537
|
}
|
|
1544
1538
|
static defineHttpConnect({ timeout, retry_wait, retry_after, retry_limit, redirect_limit }) {
|
|
1545
|
-
if ((timeout =
|
|
1539
|
+
if ((timeout = fromSeconds(timeout)) >= 0) {
|
|
1546
1540
|
HTTP_CLIENT.connectTimeout = timeout;
|
|
1547
1541
|
}
|
|
1548
|
-
if ((retry_wait =
|
|
1542
|
+
if ((retry_wait = fromSeconds(retry_wait)) >= 0) {
|
|
1549
1543
|
HTTP_CLIENT.retryWait = Math.min(retry_wait, 600 * 1000);
|
|
1550
1544
|
}
|
|
1551
|
-
if ((retry_after =
|
|
1545
|
+
if ((retry_after = fromSeconds(retry_after)) >= 0) {
|
|
1552
1546
|
HTTP_CLIENT.retryAfter = Math.min(retry_after, this.MAX_TIMEOUT);
|
|
1553
1547
|
}
|
|
1554
|
-
if ((retry_limit =
|
|
1548
|
+
if ((retry_limit = asInt(retry_limit)) >= 0) {
|
|
1555
1549
|
HTTP_CLIENT.retryLimit = retry_limit;
|
|
1556
1550
|
}
|
|
1557
|
-
if ((redirect_limit =
|
|
1551
|
+
if ((redirect_limit = asInt(redirect_limit)) >= 0) {
|
|
1558
1552
|
HTTP_CLIENT.redirectLimit = redirect_limit;
|
|
1559
1553
|
}
|
|
1560
1554
|
}
|
|
@@ -1603,15 +1597,15 @@ class FileManager extends core_1.Host {
|
|
|
1603
1597
|
#baseDirectory;
|
|
1604
1598
|
constructor(baseDirectory, config, permission, postFinalize) {
|
|
1605
1599
|
super(config);
|
|
1606
|
-
if (
|
|
1600
|
+
if (isFunction(permission)) {
|
|
1607
1601
|
postFinalize = permission;
|
|
1608
1602
|
permission = undefined;
|
|
1609
1603
|
}
|
|
1610
1604
|
if (LOG_TIMEPROCESS) {
|
|
1611
|
-
|
|
1605
|
+
Host.initCpuUsage(this);
|
|
1612
1606
|
}
|
|
1613
1607
|
this.#baseDirectory = path.normalize(baseDirectory.at(-1) === path.sep ? baseDirectory.slice(0, -1) : baseDirectory);
|
|
1614
|
-
this.permission = permission &&
|
|
1608
|
+
this.permission = permission && Host.isPermission(permission) ? permission : Host.getPermissionFromSettings();
|
|
1615
1609
|
this.sessionId = FileManager.generateSessionId();
|
|
1616
1610
|
this.supports('permission', false, true);
|
|
1617
1611
|
this.supports('sessionId', false, true);
|
|
@@ -1625,7 +1619,7 @@ class FileManager extends core_1.Host {
|
|
|
1625
1619
|
if (item.tasks) {
|
|
1626
1620
|
this.taskAssets.push(item);
|
|
1627
1621
|
}
|
|
1628
|
-
if (
|
|
1622
|
+
if (usingFlag(item)) {
|
|
1629
1623
|
targeted.push(item);
|
|
1630
1624
|
}
|
|
1631
1625
|
switch (item.encoding) {
|
|
@@ -1636,7 +1630,7 @@ class FileManager extends core_1.Host {
|
|
|
1636
1630
|
item.encoding = 'utf8';
|
|
1637
1631
|
break;
|
|
1638
1632
|
default: {
|
|
1639
|
-
const encoding =
|
|
1633
|
+
const encoding = getEncoding(item.encoding);
|
|
1640
1634
|
item.encoding = encoding === 'utf8' ? undefined : encoding;
|
|
1641
1635
|
break;
|
|
1642
1636
|
}
|
|
@@ -1657,7 +1651,7 @@ class FileManager extends core_1.Host {
|
|
|
1657
1651
|
if (config.timeout) {
|
|
1658
1652
|
applyTimeout(this.#processTimeout = Object.create(null), config.timeout);
|
|
1659
1653
|
}
|
|
1660
|
-
if (
|
|
1654
|
+
if (isFunction(postFinalize)) {
|
|
1661
1655
|
this.on('end', postFinalize);
|
|
1662
1656
|
}
|
|
1663
1657
|
this.cacheToDisk = new HttpDiskCache(this, DISK.ENABLED);
|
|
@@ -1665,10 +1659,10 @@ class FileManager extends core_1.Host {
|
|
|
1665
1659
|
if (typeof config.threads === 'number') {
|
|
1666
1660
|
this.setTaskLimit(config.threads);
|
|
1667
1661
|
}
|
|
1668
|
-
if (
|
|
1669
|
-
this.#diffSource = [config.log.showDiff.map(value =>
|
|
1662
|
+
if (isPlainObject(config.log) && isArray(config.log.showDiff) && this.incremental !== "staging") {
|
|
1663
|
+
this.#diffSource = [config.log.showDiff.map(value => hasGlob(value) ? (value = Permission.toPosix(value), pm(value, getPmOptions(value))) : value), {}];
|
|
1670
1664
|
}
|
|
1671
|
-
const request = new
|
|
1665
|
+
const request = new Request();
|
|
1672
1666
|
request.host = this;
|
|
1673
1667
|
this.Request = request;
|
|
1674
1668
|
if (this.aborted) {
|
|
@@ -1686,12 +1680,12 @@ class FileManager extends core_1.Host {
|
|
|
1686
1680
|
yield file;
|
|
1687
1681
|
}
|
|
1688
1682
|
}
|
|
1689
|
-
add(value, parent, type =
|
|
1683
|
+
add(value, parent, type = FILE_TYPE.TRANSFORM) {
|
|
1690
1684
|
const file = this.removeCwd(value);
|
|
1691
1685
|
if (file) {
|
|
1692
1686
|
this.files.add(file);
|
|
1693
1687
|
if (parent) {
|
|
1694
|
-
if (type &
|
|
1688
|
+
if (type & FILE_TYPE.TRANSFORM) {
|
|
1695
1689
|
const transforms = parent.transforms;
|
|
1696
1690
|
if (!transforms) {
|
|
1697
1691
|
parent.transforms = [value];
|
|
@@ -1700,7 +1694,7 @@ class FileManager extends core_1.Host {
|
|
|
1700
1694
|
transforms.push(value);
|
|
1701
1695
|
}
|
|
1702
1696
|
}
|
|
1703
|
-
if (type &
|
|
1697
|
+
if (type & FILE_TYPE.TORRENT) {
|
|
1704
1698
|
const torrent = parent.torrentFiles;
|
|
1705
1699
|
if (!torrent) {
|
|
1706
1700
|
parent.torrentFiles = [value];
|
|
@@ -1709,7 +1703,7 @@ class FileManager extends core_1.Host {
|
|
|
1709
1703
|
torrent.push(value);
|
|
1710
1704
|
}
|
|
1711
1705
|
}
|
|
1712
|
-
if (type & (
|
|
1706
|
+
if (type & (FILE_TYPE.COMPRESSED | FILE_TYPE.SOURCEMAP)) {
|
|
1713
1707
|
const connected = parent.descendants;
|
|
1714
1708
|
if (!connected) {
|
|
1715
1709
|
parent.descendants = [value];
|
|
@@ -1730,7 +1724,7 @@ class FileManager extends core_1.Host {
|
|
|
1730
1724
|
if (this.files.delete(this.removeCwd(value))) {
|
|
1731
1725
|
if (emptyDir) {
|
|
1732
1726
|
let dir = this.baseDirectory;
|
|
1733
|
-
for (const seg of path.dirname(value).
|
|
1727
|
+
for (const seg of path.dirname(value).slice(this.baseDirectory.length + 1).split(path.sep)) {
|
|
1734
1728
|
if (seg) {
|
|
1735
1729
|
dir += path.sep + seg;
|
|
1736
1730
|
this.emptyDir.add(dir);
|
|
@@ -1757,7 +1751,7 @@ class FileManager extends core_1.Host {
|
|
|
1757
1751
|
this.files.forEach(predicate, thisArg);
|
|
1758
1752
|
}
|
|
1759
1753
|
clear() {
|
|
1760
|
-
|
|
1754
|
+
Host.removeDir(this.baseDirectory, true);
|
|
1761
1755
|
this.files.clear();
|
|
1762
1756
|
}
|
|
1763
1757
|
get size() {
|
|
@@ -1768,11 +1762,11 @@ class FileManager extends core_1.Host {
|
|
|
1768
1762
|
super.abort(reason);
|
|
1769
1763
|
}
|
|
1770
1764
|
willAbort(value) {
|
|
1771
|
-
if (
|
|
1765
|
+
if (isObject(value)) {
|
|
1772
1766
|
value = value.moduleName;
|
|
1773
1767
|
}
|
|
1774
1768
|
const error = this.config.error;
|
|
1775
|
-
return !!error &&
|
|
1769
|
+
return !!error && isArray(error.abort) && error.abort.includes(value);
|
|
1776
1770
|
}
|
|
1777
1771
|
restart(recursive, exclusions, emptyDir) {
|
|
1778
1772
|
if (recursive === 'abort') {
|
|
@@ -1795,7 +1789,7 @@ class FileManager extends core_1.Host {
|
|
|
1795
1789
|
this.processAssets(emptyDir);
|
|
1796
1790
|
}
|
|
1797
1791
|
else {
|
|
1798
|
-
this.writeFail(['Unable to restart session', formatLength('asset', this.assets.length)],
|
|
1792
|
+
this.writeFail(['Unable to restart session', formatLength('asset', this.assets.length)], errorMessage('sessionId', this.sessionId));
|
|
1799
1793
|
}
|
|
1800
1794
|
}
|
|
1801
1795
|
else {
|
|
@@ -1809,8 +1803,8 @@ class FileManager extends core_1.Host {
|
|
|
1809
1803
|
}
|
|
1810
1804
|
switch (name) {
|
|
1811
1805
|
case 'cloud': {
|
|
1812
|
-
if (
|
|
1813
|
-
const instance = new
|
|
1806
|
+
if (isArray(args[1])) {
|
|
1807
|
+
const instance = new Cloud(args[0], args[1]);
|
|
1814
1808
|
instance.host = this;
|
|
1815
1809
|
instance.init(this.config);
|
|
1816
1810
|
this.observeFile(instance);
|
|
@@ -1858,7 +1852,7 @@ class FileManager extends core_1.Host {
|
|
|
1858
1852
|
deleteFile(value, options = {}, callback) {
|
|
1859
1853
|
if (super.deleteFile(value, options, callback)) {
|
|
1860
1854
|
let emptyDir = false;
|
|
1861
|
-
if (
|
|
1855
|
+
if (isObject(options)) {
|
|
1862
1856
|
if (options.emptyDir) {
|
|
1863
1857
|
emptyDir = true;
|
|
1864
1858
|
}
|
|
@@ -1909,7 +1903,7 @@ class FileManager extends core_1.Host {
|
|
|
1909
1903
|
}
|
|
1910
1904
|
case 'task': {
|
|
1911
1905
|
const Module = this.#tryPackage(target, name, 4);
|
|
1912
|
-
if (Module &&
|
|
1906
|
+
if (Module && isPlainObject(args[0])) {
|
|
1913
1907
|
const instance = new Module(...args);
|
|
1914
1908
|
instance.host = this;
|
|
1915
1909
|
instance.init(this.config);
|
|
@@ -1922,11 +1916,11 @@ class FileManager extends core_1.Host {
|
|
|
1922
1916
|
case 'cloud': {
|
|
1923
1917
|
const database = this.dataSourceItems.filter(item => item.source === 'cloud');
|
|
1924
1918
|
let instance;
|
|
1925
|
-
if (
|
|
1919
|
+
if (isString(target)) {
|
|
1926
1920
|
const mod = args.shift();
|
|
1927
|
-
if (
|
|
1921
|
+
if (isObject(mod)) {
|
|
1928
1922
|
if (target === "@e-mc/cloud") {
|
|
1929
|
-
instance = new
|
|
1923
|
+
instance = new Cloud(mod, database);
|
|
1930
1924
|
}
|
|
1931
1925
|
else {
|
|
1932
1926
|
const Module = this.#tryPackage(target, name, 64);
|
|
@@ -1936,8 +1930,8 @@ class FileManager extends core_1.Host {
|
|
|
1936
1930
|
}
|
|
1937
1931
|
}
|
|
1938
1932
|
}
|
|
1939
|
-
else if (
|
|
1940
|
-
instance = new
|
|
1933
|
+
else if (isObject(target)) {
|
|
1934
|
+
instance = new Cloud(target, database);
|
|
1941
1935
|
}
|
|
1942
1936
|
if (!instance) {
|
|
1943
1937
|
return;
|
|
@@ -1949,11 +1943,11 @@ class FileManager extends core_1.Host {
|
|
|
1949
1943
|
}
|
|
1950
1944
|
case 'watch': {
|
|
1951
1945
|
let instance;
|
|
1952
|
-
if (
|
|
1946
|
+
if (isString(target)) {
|
|
1953
1947
|
const mod = args.shift();
|
|
1954
|
-
if (
|
|
1948
|
+
if (isObject(mod)) {
|
|
1955
1949
|
if (target === "@e-mc/watch") {
|
|
1956
|
-
instance = new
|
|
1950
|
+
instance = new Watch(mod);
|
|
1957
1951
|
}
|
|
1958
1952
|
else {
|
|
1959
1953
|
const Module = this.#tryPackage(target, name, 16);
|
|
@@ -1963,8 +1957,8 @@ class FileManager extends core_1.Host {
|
|
|
1963
1957
|
}
|
|
1964
1958
|
}
|
|
1965
1959
|
}
|
|
1966
|
-
else if (
|
|
1967
|
-
instance = new
|
|
1960
|
+
else if (isObject(target)) {
|
|
1961
|
+
instance = new Watch(target);
|
|
1968
1962
|
}
|
|
1969
1963
|
if (!instance) {
|
|
1970
1964
|
return;
|
|
@@ -2048,7 +2042,7 @@ class FileManager extends core_1.Host {
|
|
|
2048
2042
|
this.Image ||= new Map();
|
|
2049
2043
|
}
|
|
2050
2044
|
for (const [mimeType, Module] of target) {
|
|
2051
|
-
if (
|
|
2045
|
+
if (Host.constructorOf(Module, 'image')) {
|
|
2052
2046
|
const instance = new Module(...args);
|
|
2053
2047
|
instance.host = this;
|
|
2054
2048
|
instance.init(this.config);
|
|
@@ -2062,7 +2056,7 @@ class FileManager extends core_1.Host {
|
|
|
2062
2056
|
this.Image = null;
|
|
2063
2057
|
break;
|
|
2064
2058
|
case 'compress': {
|
|
2065
|
-
const instance = new
|
|
2059
|
+
const instance = new Compress(target);
|
|
2066
2060
|
instance.host = this;
|
|
2067
2061
|
instance.init();
|
|
2068
2062
|
this.observeFile(instance);
|
|
@@ -2072,12 +2066,12 @@ class FileManager extends core_1.Host {
|
|
|
2072
2066
|
}
|
|
2073
2067
|
findAsset(value, instance) {
|
|
2074
2068
|
let assets, replaced;
|
|
2075
|
-
if (
|
|
2069
|
+
if (isPlainObject(instance)) {
|
|
2076
2070
|
({ instance, assets, replaced } = instance);
|
|
2077
2071
|
}
|
|
2078
2072
|
let origin, pathname;
|
|
2079
2073
|
if (typeof value === 'string') {
|
|
2080
|
-
if (
|
|
2074
|
+
if (Host.isURL(value, 'file')) {
|
|
2081
2075
|
try {
|
|
2082
2076
|
({ origin, pathname, href: value } = new URL(value));
|
|
2083
2077
|
}
|
|
@@ -2086,18 +2080,18 @@ class FileManager extends core_1.Host {
|
|
|
2086
2080
|
}
|
|
2087
2081
|
}
|
|
2088
2082
|
else {
|
|
2089
|
-
value =
|
|
2083
|
+
value = Host.resolveFile(value);
|
|
2090
2084
|
}
|
|
2091
2085
|
}
|
|
2092
2086
|
else {
|
|
2093
2087
|
({ origin, pathname, href: value } = value);
|
|
2094
2088
|
}
|
|
2095
|
-
if (!
|
|
2089
|
+
if (!isString(value)) {
|
|
2096
2090
|
return;
|
|
2097
2091
|
}
|
|
2098
2092
|
const result = (assets || this.assets).filter(item => {
|
|
2099
2093
|
const { uri, flags } = item;
|
|
2100
|
-
if (uri && (!instance || this.hasDocument(instance, item.document)) && (!item.invalid || assets ||
|
|
2094
|
+
if (uri && (!instance || this.hasDocument(instance, item.document)) && (!item.invalid || assets || mainFlag(flags) || usingFlag(flags) || cloneFlag(flags) || watchFlag(flags))) {
|
|
2101
2095
|
if (origin) {
|
|
2102
2096
|
if (!item.url) {
|
|
2103
2097
|
try {
|
|
@@ -2118,7 +2112,7 @@ class FileManager extends core_1.Host {
|
|
|
2118
2112
|
const indexA = uri.indexOf('#');
|
|
2119
2113
|
const indexB = value.indexOf('#');
|
|
2120
2114
|
if (indexA !== -1 || indexB !== -1) {
|
|
2121
|
-
return equalAddress(indexA !== -1 ? uri.
|
|
2115
|
+
return equalAddress(indexA !== -1 ? uri.slice(0, indexA) : uri, indexB !== -1 ? value.slice(0, indexB) : value);
|
|
2122
2116
|
}
|
|
2123
2117
|
}
|
|
2124
2118
|
return false;
|
|
@@ -2126,7 +2120,7 @@ class FileManager extends core_1.Host {
|
|
|
2126
2120
|
if (replaced) {
|
|
2127
2121
|
const map = this.#replacedAssets;
|
|
2128
2122
|
if (map) {
|
|
2129
|
-
const target = pathname ||
|
|
2123
|
+
const target = pathname || Host.toPosix(value);
|
|
2130
2124
|
const found = [];
|
|
2131
2125
|
for (const relative in map) {
|
|
2132
2126
|
const item = map[relative];
|
|
@@ -2153,12 +2147,12 @@ class FileManager extends core_1.Host {
|
|
|
2153
2147
|
return 1;
|
|
2154
2148
|
}
|
|
2155
2149
|
const bundleId = a.bundleId;
|
|
2156
|
-
if ((
|
|
2150
|
+
if ((isEmpty(bundleId) || a.bundleIndex === 0) && (isEmpty(b.bundleId) || b.bundleIndex === 0)) {
|
|
2157
2151
|
if (a.id && b.id) {
|
|
2158
2152
|
return a.id < b.id ? -1 : 1;
|
|
2159
2153
|
}
|
|
2160
2154
|
}
|
|
2161
|
-
else if (!
|
|
2155
|
+
else if (!isEmpty(bundleId) && bundleId === b.bundleId) {
|
|
2162
2156
|
return a.bundleIndex < b.bundleIndex ? -1 : 1;
|
|
2163
2157
|
}
|
|
2164
2158
|
return 0;
|
|
@@ -2175,16 +2169,16 @@ class FileManager extends core_1.Host {
|
|
|
2175
2169
|
removeCwd(value) {
|
|
2176
2170
|
if (typeof value === 'string') {
|
|
2177
2171
|
const baseDir = this.baseDirectory + path.sep;
|
|
2178
|
-
const leading = value.
|
|
2179
|
-
if (leading === baseDir ||
|
|
2180
|
-
return value.
|
|
2172
|
+
const leading = value.slice(0, baseDir.length);
|
|
2173
|
+
if (leading === baseDir || Host.PLATFORM_WIN32 && leading.toLowerCase() === baseDir.toLowerCase()) {
|
|
2174
|
+
return value.slice(baseDir.length);
|
|
2181
2175
|
}
|
|
2182
2176
|
}
|
|
2183
2177
|
return '';
|
|
2184
2178
|
}
|
|
2185
2179
|
replace(file, replaceWith, mimeType) {
|
|
2186
2180
|
let ignoreExt, rewritePath;
|
|
2187
|
-
if (
|
|
2181
|
+
if (isObject(mimeType)) {
|
|
2188
2182
|
({ mimeType, ignoreExt, rewritePath } = mimeType);
|
|
2189
2183
|
}
|
|
2190
2184
|
const { pathname, filename, localUri } = file;
|
|
@@ -2192,7 +2186,7 @@ class FileManager extends core_1.Host {
|
|
|
2192
2186
|
const name = path.basename(replaceWith);
|
|
2193
2187
|
if (!ignoreExt && localUri && path.extname(localUri) === path.extname(replaceWith)) {
|
|
2194
2188
|
try {
|
|
2195
|
-
if (!
|
|
2189
|
+
if (!Host.renameFile(replaceWith, localUri)) {
|
|
2196
2190
|
this.filesToRemove.add(replaceWith);
|
|
2197
2191
|
}
|
|
2198
2192
|
}
|
|
@@ -2202,7 +2196,7 @@ class FileManager extends core_1.Host {
|
|
|
2202
2196
|
}
|
|
2203
2197
|
}
|
|
2204
2198
|
else {
|
|
2205
|
-
|
|
2199
|
+
setInitialValue(file);
|
|
2206
2200
|
if (rewritePath || !localUri) {
|
|
2207
2201
|
file.pathname = this.removeCwd(path.dirname(replaceWith));
|
|
2208
2202
|
}
|
|
@@ -2210,7 +2204,7 @@ class FileManager extends core_1.Host {
|
|
|
2210
2204
|
const replacePath = this.setLocalUri(file, true).localUri;
|
|
2211
2205
|
if (replaceWith !== replacePath) {
|
|
2212
2206
|
try {
|
|
2213
|
-
if (!
|
|
2207
|
+
if (!Host.renameFile(replaceWith, replacePath)) {
|
|
2214
2208
|
this.filesToRemove.add(replaceWith);
|
|
2215
2209
|
}
|
|
2216
2210
|
}
|
|
@@ -2222,7 +2216,7 @@ class FileManager extends core_1.Host {
|
|
|
2222
2216
|
return false;
|
|
2223
2217
|
}
|
|
2224
2218
|
}
|
|
2225
|
-
file.mimeType = mimeType ||
|
|
2219
|
+
file.mimeType = mimeType || Host.lookupMime(name) || file.mimeType;
|
|
2226
2220
|
this.add(replaceWith);
|
|
2227
2221
|
if (localUri && !this.assets.find(item => item.localUri === localUri && !item.invalid)) {
|
|
2228
2222
|
this.filesToRemove.add(localUri);
|
|
@@ -2248,7 +2242,7 @@ class FileManager extends core_1.Host {
|
|
|
2248
2242
|
if (copy) {
|
|
2249
2243
|
fs.copyFileSync(oldPath, newPath);
|
|
2250
2244
|
}
|
|
2251
|
-
else if (!
|
|
2245
|
+
else if (!Host.renameFile(oldPath, newPath)) {
|
|
2252
2246
|
this.filesToRemove.add(oldPath);
|
|
2253
2247
|
}
|
|
2254
2248
|
}
|
|
@@ -2261,7 +2255,7 @@ class FileManager extends core_1.Host {
|
|
|
2261
2255
|
this.delete(oldPath);
|
|
2262
2256
|
}
|
|
2263
2257
|
}
|
|
2264
|
-
|
|
2258
|
+
setInitialValue(file);
|
|
2265
2259
|
file.filename = value;
|
|
2266
2260
|
this.add(file.localUri = this.setLocalUri(file, true).localUri);
|
|
2267
2261
|
}
|
|
@@ -2291,7 +2285,7 @@ class FileManager extends core_1.Host {
|
|
|
2291
2285
|
this.clearProcessTimeout();
|
|
2292
2286
|
this.#delayed = Infinity;
|
|
2293
2287
|
if (this.aborted) {
|
|
2294
|
-
this.abortFinalize(
|
|
2288
|
+
this.abortFinalize(createAbortError());
|
|
2295
2289
|
return;
|
|
2296
2290
|
}
|
|
2297
2291
|
this.finalizeState = 1;
|
|
@@ -2313,12 +2307,12 @@ class FileManager extends core_1.Host {
|
|
|
2313
2307
|
this.resetState();
|
|
2314
2308
|
const log = this.config.log;
|
|
2315
2309
|
let useNumeric, showSize;
|
|
2316
|
-
if (
|
|
2310
|
+
if (isObject(log)) {
|
|
2317
2311
|
({ useNumeric, showSize } = log);
|
|
2318
2312
|
}
|
|
2319
2313
|
const items = showSize === false ? files : files.map(name => {
|
|
2320
|
-
const size =
|
|
2321
|
-
return { name, size: useNumeric ? size :
|
|
2314
|
+
const size = getSize(path.join(this.baseDirectory, name));
|
|
2315
|
+
return { name, size: useNumeric ? size : formatSize(size) };
|
|
2322
2316
|
});
|
|
2323
2317
|
this.emit('end', items, errors, this.collectLog());
|
|
2324
2318
|
this.done = true;
|
|
@@ -2358,14 +2352,14 @@ class FileManager extends core_1.Host {
|
|
|
2358
2352
|
setLocalUri(file, replace) {
|
|
2359
2353
|
let uri = file.uri || file.url?.toString(), type;
|
|
2360
2354
|
if (uri && !file.content && !file.base64 && !file.dataView) {
|
|
2361
|
-
if (
|
|
2355
|
+
if (Host.isFile(uri, 'torrent')) {
|
|
2362
2356
|
type = 4;
|
|
2363
2357
|
}
|
|
2364
|
-
else if (
|
|
2358
|
+
else if (Request.isRclone(uri)) {
|
|
2365
2359
|
type = 0;
|
|
2366
2360
|
}
|
|
2367
2361
|
else if (!file.url) {
|
|
2368
|
-
if (
|
|
2362
|
+
if (Host.isURL(uri, 'file')) {
|
|
2369
2363
|
try {
|
|
2370
2364
|
file.url = new URL(uri);
|
|
2371
2365
|
file.uri = file.url.toString();
|
|
@@ -2380,7 +2374,7 @@ class FileManager extends core_1.Host {
|
|
|
2380
2374
|
}
|
|
2381
2375
|
else {
|
|
2382
2376
|
try {
|
|
2383
|
-
if (!(file.uri =
|
|
2377
|
+
if (!(file.uri = Host.resolveFile(uri))) {
|
|
2384
2378
|
throw errorAbsolute(uri);
|
|
2385
2379
|
}
|
|
2386
2380
|
if (file.socketPath) {
|
|
@@ -2404,7 +2398,7 @@ class FileManager extends core_1.Host {
|
|
|
2404
2398
|
}
|
|
2405
2399
|
const url = file.url;
|
|
2406
2400
|
if (file.pathname) {
|
|
2407
|
-
file.pathname =
|
|
2401
|
+
file.pathname = Host.toPosix(file.pathname);
|
|
2408
2402
|
}
|
|
2409
2403
|
if (url) {
|
|
2410
2404
|
if (type === undefined) {
|
|
@@ -2428,7 +2422,7 @@ class FileManager extends core_1.Host {
|
|
|
2428
2422
|
if (!filename && !file.document && !isDownloadAll(type)) {
|
|
2429
2423
|
filename = url.pathname.split('/').pop();
|
|
2430
2424
|
if (filename.includes('.')) {
|
|
2431
|
-
const mimeType = file.mimeType ||
|
|
2425
|
+
const mimeType = file.mimeType || Host.lookupMime(filename);
|
|
2432
2426
|
if (mimeType) {
|
|
2433
2427
|
file.filename = filename;
|
|
2434
2428
|
file.mimeType = mimeType;
|
|
@@ -2436,7 +2430,7 @@ class FileManager extends core_1.Host {
|
|
|
2436
2430
|
}
|
|
2437
2431
|
}
|
|
2438
2432
|
else if (file.mimeType && filename) {
|
|
2439
|
-
const ext =
|
|
2433
|
+
const ext = Host.lookupMime(file.mimeType, true);
|
|
2440
2434
|
if (ext) {
|
|
2441
2435
|
filename += '.' + ext;
|
|
2442
2436
|
file.filename = filename;
|
|
@@ -2464,7 +2458,7 @@ class FileManager extends core_1.Host {
|
|
|
2464
2458
|
const localUri = file.filename ? path.join(pathname, file.filename) : pathname;
|
|
2465
2459
|
file.localUri = localUri;
|
|
2466
2460
|
if (!file.mimeType && !isDownloadAll(type)) {
|
|
2467
|
-
file.mimeType = file.url &&
|
|
2461
|
+
file.mimeType = file.url && Host.lookupMime(path.basename(file.url.pathname)) || Host.lookupMime(file.filename);
|
|
2468
2462
|
}
|
|
2469
2463
|
return { pathname, localUri };
|
|
2470
2464
|
}
|
|
@@ -2472,7 +2466,7 @@ class FileManager extends core_1.Host {
|
|
|
2472
2466
|
return data.file.localUri || '';
|
|
2473
2467
|
}
|
|
2474
2468
|
getMimeType(data) {
|
|
2475
|
-
return data.mimeType ||= data.file.mimeType ||
|
|
2469
|
+
return data.mimeType ||= data.file.mimeType || Host.lookupMime(path.basename(this.getLocalUri(data)));
|
|
2476
2470
|
}
|
|
2477
2471
|
getDocumentAssets(instance, condition) {
|
|
2478
2472
|
return this.documentAssets.filter(item => this.hasDocument(instance, item.document) && (!condition || condition(item)));
|
|
@@ -2483,7 +2477,7 @@ class FileManager extends core_1.Host {
|
|
|
2483
2477
|
getUTF8String(file, uri) {
|
|
2484
2478
|
let sourceUTF8 = file.sourceUTF8;
|
|
2485
2479
|
if (!sourceUTF8) {
|
|
2486
|
-
file.encoding =
|
|
2480
|
+
file.encoding = getEncoding(file.encoding);
|
|
2487
2481
|
if (file.buffer) {
|
|
2488
2482
|
sourceUTF8 = file.buffer.toString(file.encoding);
|
|
2489
2483
|
file.buffer = null;
|
|
@@ -2497,7 +2491,7 @@ class FileManager extends core_1.Host {
|
|
|
2497
2491
|
}
|
|
2498
2492
|
}
|
|
2499
2493
|
if (sourceUTF8?.[0] === '\uFEFF' && file.encoding !== 'utf16le') {
|
|
2500
|
-
sourceUTF8 = sourceUTF8.
|
|
2494
|
+
sourceUTF8 = sourceUTF8.slice(1);
|
|
2501
2495
|
}
|
|
2502
2496
|
return file.sourceUTF8 = sourceUTF8 || '';
|
|
2503
2497
|
}
|
|
@@ -2510,13 +2504,13 @@ class FileManager extends core_1.Host {
|
|
|
2510
2504
|
let { base64, localUri } = file;
|
|
2511
2505
|
if (localUri) {
|
|
2512
2506
|
if (typeof minStreamSize === 'number') {
|
|
2513
|
-
return
|
|
2507
|
+
return Host.streamFile(localUri, { minStreamSize, cache: false, signal: this.signal });
|
|
2514
2508
|
}
|
|
2515
2509
|
try {
|
|
2516
2510
|
return fs.readFileSync(localUri);
|
|
2517
2511
|
}
|
|
2518
2512
|
catch (err) {
|
|
2519
|
-
if (!(base64 &&
|
|
2513
|
+
if (!(base64 && isErrorCode(err, 'ENOENT', 'EACCES'))) {
|
|
2520
2514
|
this.writeFail(["Unable to read file", path.basename(localUri)], err, 32);
|
|
2521
2515
|
base64 = undefined;
|
|
2522
2516
|
}
|
|
@@ -2537,7 +2531,7 @@ class FileManager extends core_1.Host {
|
|
|
2537
2531
|
return this.getTempDir({ pathname: url.hostname + '_' + (url.port || (url.protocol === 'https:' ? '443' : '80')), moduleDir: true, createDir });
|
|
2538
2532
|
}
|
|
2539
2533
|
setAssetContent(file, content, options) {
|
|
2540
|
-
let trailing =
|
|
2534
|
+
let trailing = concatString(file.trailingContent);
|
|
2541
2535
|
if (file.document) {
|
|
2542
2536
|
for (const { instance } of this.Document) {
|
|
2543
2537
|
if (instance.resolveUri && this.hasDocument(instance, file.document)) {
|
|
@@ -2565,7 +2559,7 @@ class FileManager extends core_1.Host {
|
|
|
2565
2559
|
this.contentToReplace.set(localUri, replacing = []);
|
|
2566
2560
|
}
|
|
2567
2561
|
appending[bundleIndex - 1] = content;
|
|
2568
|
-
if (
|
|
2562
|
+
if (isString(options.bundleReplace)) {
|
|
2569
2563
|
replacing[bundleIndex - 1] = options.bundleReplace;
|
|
2570
2564
|
}
|
|
2571
2565
|
file.invalid = true;
|
|
@@ -2580,10 +2574,11 @@ class FileManager extends core_1.Host {
|
|
|
2580
2574
|
return content;
|
|
2581
2575
|
}
|
|
2582
2576
|
let replacing, newline;
|
|
2583
|
-
const getSeparator = (value) => newline ||=
|
|
2577
|
+
const getSeparator = (value) => newline ||= getNewline(value);
|
|
2584
2578
|
if (content && (replacing = this.contentToReplace.get(localUri)) && replacing.length > 0) {
|
|
2585
|
-
for (let i = 0,
|
|
2586
|
-
|
|
2579
|
+
for (let i = 0, match; i < replacing.length; ++i) {
|
|
2580
|
+
let value = appending[i];
|
|
2581
|
+
if (isString(value)) {
|
|
2587
2582
|
if (replacing[i] && (match = new RegExp(replacing[i], 'i').exec(content))) {
|
|
2588
2583
|
if (document) {
|
|
2589
2584
|
for (const { instance } of this.Document) {
|
|
@@ -2596,7 +2591,7 @@ class FileManager extends core_1.Host {
|
|
|
2596
2591
|
}
|
|
2597
2592
|
}
|
|
2598
2593
|
}
|
|
2599
|
-
content = content.
|
|
2594
|
+
content = content.slice(0, match.index) + value + getSeparator(content) + content.slice(match.index + match[0].length);
|
|
2600
2595
|
}
|
|
2601
2596
|
else {
|
|
2602
2597
|
content += getSeparator(content) + value;
|
|
@@ -2636,7 +2631,7 @@ class FileManager extends core_1.Host {
|
|
|
2636
2631
|
return;
|
|
2637
2632
|
}
|
|
2638
2633
|
const document = data.file.document;
|
|
2639
|
-
const ext =
|
|
2634
|
+
const ext = asExt(localUri);
|
|
2640
2635
|
let output;
|
|
2641
2636
|
saveAs ||= ext;
|
|
2642
2637
|
if (document) {
|
|
@@ -2651,7 +2646,7 @@ class FileManager extends core_1.Host {
|
|
|
2651
2646
|
if (!replace || this.filesQueued.has(localUri)) {
|
|
2652
2647
|
let i = 1;
|
|
2653
2648
|
do {
|
|
2654
|
-
output =
|
|
2649
|
+
output = renameExt(localUri, '__copy__.' + (i > 1 ? `(${i}).` : '') + saveAs);
|
|
2655
2650
|
} while (this.filesQueued.has(output) && ++i);
|
|
2656
2651
|
try {
|
|
2657
2652
|
fs.copyFileSync(localUri, output);
|
|
@@ -2665,7 +2660,7 @@ class FileManager extends core_1.Host {
|
|
|
2665
2660
|
else {
|
|
2666
2661
|
let i = 1;
|
|
2667
2662
|
do {
|
|
2668
|
-
output =
|
|
2663
|
+
output = renameExt(localUri, (i > 1 ? `(${i}).` : '') + saveAs);
|
|
2669
2664
|
if (replace) {
|
|
2670
2665
|
break;
|
|
2671
2666
|
}
|
|
@@ -2675,7 +2670,7 @@ class FileManager extends core_1.Host {
|
|
|
2675
2670
|
return output;
|
|
2676
2671
|
}
|
|
2677
2672
|
handleFilePermission(file) {
|
|
2678
|
-
this.writeFail(["Unable to read file", file.uri && path.basename(file.uri)],
|
|
2673
|
+
this.writeFail(["Unable to read file", file.uri && path.basename(file.uri)], errorValue("Operation not permitted", file.uri || file.filename), 8192);
|
|
2679
2674
|
file.invalid = true;
|
|
2680
2675
|
this.emit('asset:permission', file);
|
|
2681
2676
|
}
|
|
@@ -2686,7 +2681,7 @@ class FileManager extends core_1.Host {
|
|
|
2686
2681
|
}
|
|
2687
2682
|
let mimeType = '', ext;
|
|
2688
2683
|
try {
|
|
2689
|
-
const result = await
|
|
2684
|
+
const result = await Host.resolveMime(file.buffer || localUri);
|
|
2690
2685
|
if (result) {
|
|
2691
2686
|
({ mime: mimeType, ext } = result);
|
|
2692
2687
|
}
|
|
@@ -2699,10 +2694,10 @@ class FileManager extends core_1.Host {
|
|
|
2699
2694
|
file.invalid = true;
|
|
2700
2695
|
}
|
|
2701
2696
|
else {
|
|
2702
|
-
const output =
|
|
2697
|
+
const output = renameExt(localUri, ext);
|
|
2703
2698
|
if (localUri !== output) {
|
|
2704
2699
|
try {
|
|
2705
|
-
const success =
|
|
2700
|
+
const success = Host.renameFile(localUri, output);
|
|
2706
2701
|
this.replace(file, output, mimeType);
|
|
2707
2702
|
if (!success) {
|
|
2708
2703
|
this.filesToRemove.add(localUri);
|
|
@@ -2722,43 +2717,44 @@ class FileManager extends core_1.Host {
|
|
|
2722
2717
|
async compressFile(file, overwrite = true) {
|
|
2723
2718
|
const compress = this.Compress;
|
|
2724
2719
|
const localUri = file.localUri;
|
|
2725
|
-
if (compress && localUri && (this.has(localUri) ||
|
|
2720
|
+
if (compress && localUri && (this.has(localUri) || existsFlag(file)) && file.compress) {
|
|
2726
2721
|
const tasks = [];
|
|
2727
2722
|
for (const options of file.compress) {
|
|
2728
2723
|
const { format, condition } = options;
|
|
2729
2724
|
let output;
|
|
2730
2725
|
switch (format) {
|
|
2731
2726
|
case 'br':
|
|
2727
|
+
case 'zst':
|
|
2732
2728
|
options.mimeType ||= file.mimeType;
|
|
2733
2729
|
case 'gz':
|
|
2734
2730
|
output = localUri + '.' + format;
|
|
2735
2731
|
break;
|
|
2736
2732
|
case 'woff':
|
|
2737
2733
|
case 'woff2':
|
|
2738
|
-
output =
|
|
2734
|
+
output = renameExt(localUri, format);
|
|
2739
2735
|
options.filename = file.filename;
|
|
2740
2736
|
options.etag = file.etag;
|
|
2741
2737
|
break;
|
|
2742
2738
|
default:
|
|
2743
2739
|
if (format && typeof compress.compressors[format] === 'function') {
|
|
2744
|
-
output =
|
|
2740
|
+
output = renameExt(localUri, format);
|
|
2745
2741
|
}
|
|
2746
2742
|
break;
|
|
2747
2743
|
}
|
|
2748
2744
|
if (output && (!condition || withinSizeRange(localUri, condition))) {
|
|
2749
2745
|
try {
|
|
2750
|
-
if (overwrite || !fs.existsSync(output) || !
|
|
2746
|
+
if (overwrite || !fs.existsSync(output) || !existsFlag(file) && fs.statSync(output).mtimeMs < this.startTime) {
|
|
2751
2747
|
options.timeout = this.#getModuleTimeout('compress');
|
|
2752
2748
|
tasks.push(compress.tryFile(file.buffer || localUri, output, options).then(() => {
|
|
2753
2749
|
const outFile = options.outFile;
|
|
2754
2750
|
if (outFile) {
|
|
2755
|
-
if (condition?.includes('%') &&
|
|
2751
|
+
if (condition?.includes('%') && getSize(outFile) >= getSize(localUri)) {
|
|
2756
2752
|
queueMicrotask(() => {
|
|
2757
2753
|
this.deleteFile(outFile);
|
|
2758
2754
|
});
|
|
2759
2755
|
}
|
|
2760
2756
|
else {
|
|
2761
|
-
this.add(outFile, file,
|
|
2757
|
+
this.add(outFile, file, FILE_TYPE.COMPRESSED);
|
|
2762
2758
|
}
|
|
2763
2759
|
}
|
|
2764
2760
|
})
|
|
@@ -2819,13 +2815,13 @@ class FileManager extends core_1.Host {
|
|
|
2819
2815
|
}
|
|
2820
2816
|
}
|
|
2821
2817
|
}
|
|
2822
|
-
if (
|
|
2818
|
+
if (Image.isBinary(mimeType)) {
|
|
2823
2819
|
if (file.commands && this.Image) {
|
|
2824
2820
|
const handler = this.Image.get(mimeType) || this.Image.get('handler');
|
|
2825
2821
|
if (handler) {
|
|
2826
2822
|
const { instance } = handler;
|
|
2827
2823
|
for (const command of file.commands) {
|
|
2828
|
-
if (withinSizeRange(localUri, command, REGEXP_SIZERANGE) && instance.using && !data.aborted) {
|
|
2824
|
+
if (command && withinSizeRange(localUri, command, REGEXP_SIZERANGE) && instance.using && !data.aborted) {
|
|
2829
2825
|
if (instance.threadable) {
|
|
2830
2826
|
if (this.openThread(instance, data, this.getProcessTimeout(handler))) {
|
|
2831
2827
|
instance.using(data, command)
|
|
@@ -2865,7 +2861,7 @@ class FileManager extends core_1.Host {
|
|
|
2865
2861
|
if (!file.invalid) {
|
|
2866
2862
|
this.add(localUri, parent);
|
|
2867
2863
|
}
|
|
2868
|
-
else if (localUri &&
|
|
2864
|
+
else if (localUri && isEmpty(file.bundleId)) {
|
|
2869
2865
|
this.deleteFile(localUri, { emptyDir: true });
|
|
2870
2866
|
}
|
|
2871
2867
|
});
|
|
@@ -2875,7 +2871,7 @@ class FileManager extends core_1.Host {
|
|
|
2875
2871
|
if (this.aborted || data.aborted) {
|
|
2876
2872
|
return false;
|
|
2877
2873
|
}
|
|
2878
|
-
|
|
2874
|
+
AbortComponent.attach(data, instance.signal);
|
|
2879
2875
|
if (timeout > 0) {
|
|
2880
2876
|
this.addProcessTimeout(instance, data.file, timeout);
|
|
2881
2877
|
}
|
|
@@ -2888,7 +2884,7 @@ class FileManager extends core_1.Host {
|
|
|
2888
2884
|
return false;
|
|
2889
2885
|
}
|
|
2890
2886
|
if (instance) {
|
|
2891
|
-
|
|
2887
|
+
AbortComponent.detach(data, instance.signal);
|
|
2892
2888
|
this.removeProcessTimeout(instance, data.file);
|
|
2893
2889
|
}
|
|
2894
2890
|
if (typeof callback === 'function') {
|
|
@@ -2958,7 +2954,7 @@ class FileManager extends core_1.Host {
|
|
|
2958
2954
|
result = value;
|
|
2959
2955
|
}
|
|
2960
2956
|
else if (typeof value === 'string') {
|
|
2961
|
-
if ((result =
|
|
2957
|
+
if ((result = byteLength(value, encoding)) === 0) {
|
|
2962
2958
|
return 0;
|
|
2963
2959
|
}
|
|
2964
2960
|
}
|
|
@@ -2980,20 +2976,20 @@ class FileManager extends core_1.Host {
|
|
|
2980
2976
|
}
|
|
2981
2977
|
checkHash(checksum, data, uri) {
|
|
2982
2978
|
let algorithm, digestEncoding, value;
|
|
2983
|
-
if (
|
|
2984
|
-
({ algorithm, digestEncoding
|
|
2979
|
+
if (isObject(checksum)) {
|
|
2980
|
+
({ algorithm, digestEncoding, value } = checksum);
|
|
2985
2981
|
}
|
|
2986
2982
|
else {
|
|
2987
2983
|
value = checksum;
|
|
2988
2984
|
}
|
|
2989
2985
|
let output;
|
|
2990
|
-
if (
|
|
2986
|
+
if (isPlainObject(data)) {
|
|
2991
2987
|
({ data, uri, output } = data);
|
|
2992
2988
|
}
|
|
2993
|
-
else if (
|
|
2989
|
+
else if (isPlainObject(uri)) {
|
|
2994
2990
|
({ uri, output } = uri);
|
|
2995
2991
|
}
|
|
2996
|
-
if (
|
|
2992
|
+
if (isString(value)) {
|
|
2997
2993
|
algorithm ||= "sha256";
|
|
2998
2994
|
if (!data) {
|
|
2999
2995
|
if (!uri) {
|
|
@@ -3004,14 +3000,14 @@ class FileManager extends core_1.Host {
|
|
|
3004
3000
|
}
|
|
3005
3001
|
catch (err) {
|
|
3006
3002
|
this.addLog(3, err, { source: `${algorithm}:${value}` });
|
|
3007
|
-
return output ?
|
|
3003
|
+
return output ? isErrorCode(err, 'ENOENT') : false;
|
|
3008
3004
|
}
|
|
3009
3005
|
}
|
|
3010
|
-
if ((value = value.toLowerCase()) ===
|
|
3006
|
+
if ((value = value.toLowerCase()) === Host.asHash(data, algorithm, digestEncoding)) {
|
|
3011
3007
|
if (uri instanceof URL) {
|
|
3012
|
-
uri =
|
|
3008
|
+
uri = fileURLToPath(uri);
|
|
3013
3009
|
}
|
|
3014
|
-
this.formatMessage(32, algorithm, ["Checksum matched" + (output ? ' (output)' : ''), uri && path.basename(uri)], value, { ...
|
|
3010
|
+
this.formatMessage(32, algorithm, ["Checksum matched" + (output ? ' (output)' : ''), uri && path.basename(uri)], value, { ...Host.LOG_STYLE_INFO, queue: true });
|
|
3015
3011
|
return true;
|
|
3016
3012
|
}
|
|
3017
3013
|
return false;
|
|
@@ -3039,7 +3035,7 @@ class FileManager extends core_1.Host {
|
|
|
3039
3035
|
if (buffer) {
|
|
3040
3036
|
this.addDownload(Buffer.byteLength(buffer, encoding));
|
|
3041
3037
|
}
|
|
3042
|
-
else if (
|
|
3038
|
+
else if (isString(pipeTo) && Host.isPath(pipeTo, true)) {
|
|
3043
3039
|
this.addDownload(pipeTo);
|
|
3044
3040
|
}
|
|
3045
3041
|
return buffer;
|
|
@@ -3052,7 +3048,7 @@ class FileManager extends core_1.Host {
|
|
|
3052
3048
|
else {
|
|
3053
3049
|
options.pathname ||= this.baseDirectory;
|
|
3054
3050
|
}
|
|
3055
|
-
return
|
|
3051
|
+
return Request.isRclone(uri) ? this.Request.rclone(uri, options) : this.Request.aria2c(uri, options);
|
|
3056
3052
|
}
|
|
3057
3053
|
async start(emptyDir) {
|
|
3058
3054
|
if (this.aborted) {
|
|
@@ -3179,7 +3175,7 @@ class FileManager extends core_1.Host {
|
|
|
3179
3175
|
this.deleteFile(localUri, { id: file.id, emptyDir: true, all: true });
|
|
3180
3176
|
}
|
|
3181
3177
|
}
|
|
3182
|
-
(moduleName && this.find(moduleName) || this).formatFail(16384, "FAIL!", ["Unable to process file", moduleName || 'main'],
|
|
3178
|
+
(moduleName && this.find(moduleName) || this).formatFail(16384, "FAIL!", ["Unable to process file", moduleName || 'main'], errorValue(expired ? "Timeout was exceeded" : "Aborted", localUri), { queue: false, startTime: data.startTime });
|
|
3183
3179
|
processing.splice(i--, 1);
|
|
3184
3180
|
aborted = true;
|
|
3185
3181
|
}
|
|
@@ -3190,12 +3186,12 @@ class FileManager extends core_1.Host {
|
|
|
3190
3186
|
else if (aborted) {
|
|
3191
3187
|
this.performFinalize();
|
|
3192
3188
|
}
|
|
3193
|
-
},
|
|
3189
|
+
}, THRESHOLD.FILEMANAGER_INTERVAL);
|
|
3194
3190
|
const { assets, cacheToDisk, cacheToMemory, fetchedAssets } = this;
|
|
3195
3191
|
const downloadable = new Map();
|
|
3196
3192
|
const staging = this.#incremental === "staging";
|
|
3197
3193
|
const incremental = this.config.incremental;
|
|
3198
|
-
const checkDest = (src, localUri) => staging || !
|
|
3194
|
+
const checkDest = (src, localUri) => staging || !hasSameStat(src, localUri);
|
|
3199
3195
|
let cacheable = false, cacheOpen = false, cacheEtag = false;
|
|
3200
3196
|
if (!staging) {
|
|
3201
3197
|
cacheable = this.retryLimit === RETRY_LIMIT;
|
|
@@ -3211,9 +3207,9 @@ class FileManager extends core_1.Host {
|
|
|
3211
3207
|
}
|
|
3212
3208
|
const targeting = this._usingObjects.size > 0;
|
|
3213
3209
|
const groupData = new ProcessGroup();
|
|
3214
|
-
const imported = assets.filter(item => item.imported &&
|
|
3210
|
+
const imported = assets.filter(item => item.imported && isArray(item.imported));
|
|
3215
3211
|
for (let item of assets) {
|
|
3216
|
-
if (item.invalid ||
|
|
3212
|
+
if (item.invalid || ignoreFlag(item)) {
|
|
3217
3213
|
continue;
|
|
3218
3214
|
}
|
|
3219
3215
|
let download = this.setLocalUri(item), uri = item.uri;
|
|
@@ -3224,7 +3220,7 @@ class FileManager extends core_1.Host {
|
|
|
3224
3220
|
}
|
|
3225
3221
|
item.filename = '';
|
|
3226
3222
|
}
|
|
3227
|
-
if (targeting && !this.contains(item, (other) =>
|
|
3223
|
+
if (targeting && !this.contains(item, (other) => isEqual(item, other))) {
|
|
3228
3224
|
item.invalid = true;
|
|
3229
3225
|
continue;
|
|
3230
3226
|
}
|
|
@@ -3253,7 +3249,7 @@ class FileManager extends core_1.Host {
|
|
|
3253
3249
|
if (etag && imported.some(file => file.imported.includes(uri))) {
|
|
3254
3250
|
item.incremental = "none";
|
|
3255
3251
|
}
|
|
3256
|
-
else if (!
|
|
3252
|
+
else if (!mainFlag(item)) {
|
|
3257
3253
|
let cached;
|
|
3258
3254
|
const { bundleId, bundleIndex = -1 } = item;
|
|
3259
3255
|
const setBuffer = (target) => {
|
|
@@ -3264,12 +3260,12 @@ class FileManager extends core_1.Host {
|
|
|
3264
3260
|
}
|
|
3265
3261
|
return false;
|
|
3266
3262
|
};
|
|
3267
|
-
if ((!etag || item.fetchType === 1 && (
|
|
3263
|
+
if ((!etag || item.fetchType === 1 && (isEmpty(bundleId) || bundleIndex <= 0)) && (!this.Watch || !item.watch || setBuffer(item))) {
|
|
3268
3264
|
let childBundle, childDownload;
|
|
3269
|
-
if (!
|
|
3265
|
+
if (!isEmpty(bundleId) && bundleIndex > 0) {
|
|
3270
3266
|
const target = assets.find(parent => parent.bundleIndex === 0 && parent.bundleId === bundleId);
|
|
3271
3267
|
if (target) {
|
|
3272
|
-
if (
|
|
3268
|
+
if (existsFlag(target)) {
|
|
3273
3269
|
setBuffer(item);
|
|
3274
3270
|
item.invalid = true;
|
|
3275
3271
|
}
|
|
@@ -3300,10 +3296,10 @@ class FileManager extends core_1.Host {
|
|
|
3300
3296
|
setBuffer(item);
|
|
3301
3297
|
}
|
|
3302
3298
|
const checksumOutput = item.checksumOutput;
|
|
3303
|
-
if (
|
|
3299
|
+
if (Host.isPath(localUri) && (!checksumOutput || this.checkHash(checksumOutput, { uri: localUri, output: true }))) {
|
|
3304
3300
|
item.flags |= 128;
|
|
3305
3301
|
if (!etag || item.fetchType !== 1 || checksumOutput) {
|
|
3306
|
-
if (bundleIndex === 0 && !
|
|
3302
|
+
if (bundleIndex === 0 && !isEmpty(bundleId)) {
|
|
3307
3303
|
for (const target of assets.filter(child => child.bundleId === bundleId && child.bundleIndex > 0)) {
|
|
3308
3304
|
setBuffer(target);
|
|
3309
3305
|
target.invalid = true;
|
|
@@ -3323,7 +3319,7 @@ class FileManager extends core_1.Host {
|
|
|
3323
3319
|
if (item.willChange && Buffer.isBuffer(buffer)) {
|
|
3324
3320
|
item.buffer = buffer;
|
|
3325
3321
|
}
|
|
3326
|
-
if (!(checksumOutput &&
|
|
3322
|
+
if (!(checksumOutput && isEmpty(bundleId) && this.checkHash(checksumOutput, { data: buffer, uri: localUri, output: true }))) {
|
|
3327
3323
|
this.performAsyncTask();
|
|
3328
3324
|
const target = new ProcessFile(this, item, localUri, groupData);
|
|
3329
3325
|
target.received(null, incremental, true, false, true);
|
|
@@ -3336,14 +3332,14 @@ class FileManager extends core_1.Host {
|
|
|
3336
3332
|
}
|
|
3337
3333
|
}
|
|
3338
3334
|
}
|
|
3339
|
-
else if (
|
|
3335
|
+
else if (Host.isPath(localUri)) {
|
|
3340
3336
|
try {
|
|
3341
3337
|
const buffer = fs.readFileSync(localUri);
|
|
3342
3338
|
if (!etag) {
|
|
3343
|
-
|
|
3339
|
+
setInitialValue(item, false).buffer = buffer;
|
|
3344
3340
|
}
|
|
3345
3341
|
else if (uri && CACHE_ETAG.has(uri)) {
|
|
3346
|
-
const initialValue =
|
|
3342
|
+
const initialValue = setInitialValue(item, false);
|
|
3347
3343
|
initialValue.buffer = buffer;
|
|
3348
3344
|
initialValue.etag = CACHE_ETAG.get(uri);
|
|
3349
3345
|
}
|
|
@@ -3372,13 +3368,13 @@ class FileManager extends core_1.Host {
|
|
|
3372
3368
|
}
|
|
3373
3369
|
const { pathname, localUri } = download;
|
|
3374
3370
|
const target = new ProcessFile(this, item, localUri, groupData);
|
|
3375
|
-
if (diffSource &&
|
|
3371
|
+
if (diffSource && Host.isPath(localUri, true) && diffSource[0].some(pattern => typeof pattern === 'string' ? pattern === item.mimeType || pattern === item.mimeType?.split('/')[1] : pattern(localUri))) {
|
|
3376
3372
|
try {
|
|
3377
|
-
const encoding =
|
|
3373
|
+
const encoding = Image.isBinary(item.mimeType) ? 'base64' : item.encoding || 'utf8';
|
|
3378
3374
|
diffSource[1][localUri] ||= [fs.readFileSync(localUri, encoding), encoding];
|
|
3379
3375
|
}
|
|
3380
3376
|
catch (err) {
|
|
3381
|
-
this.formatMessage(32, "WARN!", ["Unable to read file", path.basename(localUri)], err, { ...
|
|
3377
|
+
this.formatMessage(32, "WARN!", ["Unable to read file", path.basename(localUri)], err, { ...Host.LOG_STYLE_WARN });
|
|
3382
3378
|
}
|
|
3383
3379
|
}
|
|
3384
3380
|
if (item.content) {
|
|
@@ -3425,7 +3421,7 @@ class FileManager extends core_1.Host {
|
|
|
3425
3421
|
target.received(err);
|
|
3426
3422
|
}).then(code => {
|
|
3427
3423
|
if (code === -1) {
|
|
3428
|
-
target.received(
|
|
3424
|
+
target.received(errorValue("Not able to read buffer", path.basename(localUri)));
|
|
3429
3425
|
}
|
|
3430
3426
|
});
|
|
3431
3427
|
}
|
|
@@ -3435,10 +3431,10 @@ class FileManager extends core_1.Host {
|
|
|
3435
3431
|
continue;
|
|
3436
3432
|
}
|
|
3437
3433
|
const type = item.fetchType || 0;
|
|
3438
|
-
const bundleMain = item.bundleIndex === 0 && !
|
|
3434
|
+
const bundleMain = item.bundleIndex === 0 && !isEmpty(item.bundleId);
|
|
3439
3435
|
if (type === 1 || type === 2) {
|
|
3440
|
-
let checkEtag;
|
|
3441
|
-
if (bundling[uri] &&
|
|
3436
|
+
let checkEtag = false;
|
|
3437
|
+
if (bundling[uri] && isEmpty(item.bundleId)) {
|
|
3442
3438
|
bundling[uri].push(item);
|
|
3443
3439
|
}
|
|
3444
3440
|
else if ((checkEtag = hasEtag(item, cacheable, cacheEtag)) || !target.queued(pathname, emptyDir, false)) {
|
|
@@ -3460,7 +3456,7 @@ class FileManager extends core_1.Host {
|
|
|
3460
3456
|
if (type === 1) {
|
|
3461
3457
|
cacheDir = cacheToDisk.has(url) && isCacheable(item);
|
|
3462
3458
|
cacheBuffer = cacheToMemory.has(url);
|
|
3463
|
-
mainEtag =
|
|
3459
|
+
mainEtag = mainFlag(item) && (cacheEtag || item.incremental === "etag");
|
|
3464
3460
|
}
|
|
3465
3461
|
const downloadUri = (request, etagDir) => {
|
|
3466
3462
|
if (checkEtag) {
|
|
@@ -3552,7 +3548,7 @@ class FileManager extends core_1.Host {
|
|
|
3552
3548
|
}
|
|
3553
3549
|
try {
|
|
3554
3550
|
let pipeAs;
|
|
3555
|
-
if (tempDir &&
|
|
3551
|
+
if (tempDir && hasSize(pipeAs = path.join(tempDir, etagDir, path.basename(localUri)))) {
|
|
3556
3552
|
if (!checkEtag) {
|
|
3557
3553
|
if (cacheBuffer && !buffer) {
|
|
3558
3554
|
buffer = fs.readFileSync(pipeAs, encoding);
|
|
@@ -3575,12 +3571,12 @@ class FileManager extends core_1.Host {
|
|
|
3575
3571
|
}
|
|
3576
3572
|
else {
|
|
3577
3573
|
fs.copyFileSync(pipeAs, localUri);
|
|
3578
|
-
this.addDownload(pipeAs,
|
|
3574
|
+
this.addDownload(pipeAs, DOWNLOAD_TYPE.CACHE);
|
|
3579
3575
|
}
|
|
3580
3576
|
}
|
|
3581
3577
|
if (buffer) {
|
|
3582
3578
|
fs.writeFileSync(localUri, buffer);
|
|
3583
|
-
this.addDownload(Buffer.byteLength(buffer, encoding),
|
|
3579
|
+
this.addDownload(Buffer.byteLength(buffer, encoding), DOWNLOAD_TYPE.CACHE);
|
|
3584
3580
|
}
|
|
3585
3581
|
}
|
|
3586
3582
|
if (item.willChange && buffer) {
|
|
@@ -3597,7 +3593,7 @@ class FileManager extends core_1.Host {
|
|
|
3597
3593
|
if (buffer) {
|
|
3598
3594
|
setContent(item, buffer);
|
|
3599
3595
|
fs.writeFileSync(localUri, buffer);
|
|
3600
|
-
this.addDownload(Buffer.byteLength(buffer, encoding),
|
|
3596
|
+
this.addDownload(Buffer.byteLength(buffer, encoding), DOWNLOAD_TYPE.CACHE);
|
|
3601
3597
|
if (checkEtag) {
|
|
3602
3598
|
item.flags &= ~128;
|
|
3603
3599
|
}
|
|
@@ -3620,13 +3616,13 @@ class FileManager extends core_1.Host {
|
|
|
3620
3616
|
const location = res.headers.location;
|
|
3621
3617
|
if (location && ++redirects <= HTTP_CLIENT.redirectLimit) {
|
|
3622
3618
|
try {
|
|
3623
|
-
checkHeaders(new URL(
|
|
3619
|
+
checkHeaders(new URL(fromURL(href, location)), redirects);
|
|
3624
3620
|
return;
|
|
3625
3621
|
}
|
|
3626
3622
|
catch {
|
|
3627
3623
|
}
|
|
3628
3624
|
}
|
|
3629
|
-
target.abort(
|
|
3625
|
+
target.abort(errorMessage(statusCode, "Exceeded redirect limit", url.toString()));
|
|
3630
3626
|
}
|
|
3631
3627
|
else {
|
|
3632
3628
|
downloadUri(opts, null);
|
|
@@ -3635,7 +3631,7 @@ class FileManager extends core_1.Host {
|
|
|
3635
3631
|
.on('error', err => {
|
|
3636
3632
|
--processTask.pending;
|
|
3637
3633
|
if (!client.destroyed) {
|
|
3638
|
-
if (
|
|
3634
|
+
if (checkRetryable(err)) {
|
|
3639
3635
|
downloadUri(opts, null);
|
|
3640
3636
|
}
|
|
3641
3637
|
else {
|
|
@@ -3665,7 +3661,7 @@ class FileManager extends core_1.Host {
|
|
|
3665
3661
|
}
|
|
3666
3662
|
else if (hasFiles(type, uri)) {
|
|
3667
3663
|
if (bundleMain && !item.mimeType) {
|
|
3668
|
-
target.abort(
|
|
3664
|
+
target.abort(errorValue("MIME not found", uri), true);
|
|
3669
3665
|
}
|
|
3670
3666
|
else if (!target.queued(pathname, emptyDir, false)) {
|
|
3671
3667
|
if (downloading[uri]) {
|
|
@@ -3688,7 +3684,7 @@ class FileManager extends core_1.Host {
|
|
|
3688
3684
|
}
|
|
3689
3685
|
void this.scheduleTask(src, options, (result) => {
|
|
3690
3686
|
if (result.length === 0) {
|
|
3691
|
-
target.abort(
|
|
3687
|
+
target.abort(errorValue("No files were successfully downloaded", uri));
|
|
3692
3688
|
}
|
|
3693
3689
|
else if (bundleMain) {
|
|
3694
3690
|
const encoding = item.encoding ||= 'utf8';
|
|
@@ -3719,7 +3715,7 @@ class FileManager extends core_1.Host {
|
|
|
3719
3715
|
const file = result[i];
|
|
3720
3716
|
if (index === i || !found && ext === path.extname(file)) {
|
|
3721
3717
|
try {
|
|
3722
|
-
if (file !== localUri && !
|
|
3718
|
+
if (file !== localUri && !Host.renameFile(file, localUri)) {
|
|
3723
3719
|
this.filesToRemove.add(file);
|
|
3724
3720
|
}
|
|
3725
3721
|
found = true;
|
|
@@ -3729,7 +3725,7 @@ class FileManager extends core_1.Host {
|
|
|
3729
3725
|
}
|
|
3730
3726
|
}
|
|
3731
3727
|
else {
|
|
3732
|
-
this.add(file, item,
|
|
3728
|
+
this.add(file, item, FILE_TYPE.TORRENT);
|
|
3733
3729
|
}
|
|
3734
3730
|
}
|
|
3735
3731
|
}
|
|
@@ -3759,7 +3755,7 @@ class FileManager extends core_1.Host {
|
|
|
3759
3755
|
if (checkDest(uri, localUri)) {
|
|
3760
3756
|
fs.copyFile(uri, localUri, err => {
|
|
3761
3757
|
if (!err) {
|
|
3762
|
-
this.addDownload(localUri,
|
|
3758
|
+
this.addDownload(localUri, DOWNLOAD_TYPE.DISK);
|
|
3763
3759
|
}
|
|
3764
3760
|
target.received(err);
|
|
3765
3761
|
});
|
|
@@ -3802,12 +3798,12 @@ class FileManager extends core_1.Host {
|
|
|
3802
3798
|
else if (processTask.updated + 100 > currentTime) {
|
|
3803
3799
|
return;
|
|
3804
3800
|
}
|
|
3805
|
-
const logCurrent =
|
|
3801
|
+
const logCurrent = getLogCurrent();
|
|
3806
3802
|
const statusHeight = status.length;
|
|
3807
3803
|
const barLength = processTask.barLength;
|
|
3808
3804
|
const barIncrement = 100 / barLength;
|
|
3809
3805
|
const initial = processTask.logCurrent !== logCurrent;
|
|
3810
|
-
let redraw = false, scrollHeight = 0, logDelayed =
|
|
3806
|
+
let redraw = false, scrollHeight = 0, logDelayed = Host.getLogDelayed();
|
|
3811
3807
|
if (logDelayed.length > 0) {
|
|
3812
3808
|
logDelayed = logDelayed.filter(item => typeof item[4].progressBar !== 'boolean');
|
|
3813
3809
|
scrollHeight = Math.min(logDelayed.length, LOGGER.PROGRESS_SCROLLBUFFER);
|
|
@@ -3887,7 +3883,7 @@ class FileManager extends core_1.Host {
|
|
|
3887
3883
|
}
|
|
3888
3884
|
const diffTime = currentTime - item.startTime;
|
|
3889
3885
|
const unit = receivedBytes < 1048576 ? 'KB' : receivedBytes < 1073741824 ? 'MB' : 'GB';
|
|
3890
|
-
const [time, size, speed] = formatSegment(endTime > 0 ? bars === 0 ? -1 : endTime : 0, formatMinutes(diffTime).padStart(LOGGER.TITLE_WIDTH),
|
|
3886
|
+
const [time, size, speed] = formatSegment(endTime > 0 ? bars === 0 ? -1 : endTime : 0, formatMinutes(diffTime).padStart(LOGGER.TITLE_WIDTH), formatSize(receivedBytes, { unit, unitSeparator: ' ', fixedDecimals: true, decimalPlaces: unit === 'KB' ? 0 : unit === 'MB' ? 1 : 2 }).padStart(8), getTransferRate(receivedBytes, item.dataTime ? Math.max(1, convertTime(process.hrtime.bigint() - item.dataTime, false) * 1000) : diffTime, ' ').padStart(10));
|
|
3891
3887
|
let output = time + ` ${chalk.blackBright(LOGGER.TITLE_SEP)} ` + (endTime > 0 && bars === 0 ? chalk.grey(item.url) : item.url) + spacer;
|
|
3892
3888
|
if (barLength === 1) {
|
|
3893
3889
|
output += ` ${endTime > 0 ? bars === 0 ? chalk.red('ERR!') : LOGGER.PROGRESS_COMPLETE : formatPercent(percent)} ` + spacer;
|
|
@@ -3906,7 +3902,7 @@ class FileManager extends core_1.Host {
|
|
|
3906
3902
|
}
|
|
3907
3903
|
output += '\n';
|
|
3908
3904
|
if (!LOGGER.PROGRESS_USECOLOR) {
|
|
3909
|
-
output =
|
|
3905
|
+
output = stripVTControlCharacters(output);
|
|
3910
3906
|
}
|
|
3911
3907
|
PROCESS_STDOUT.clearLine(0);
|
|
3912
3908
|
PROCESS_STDOUT.write(output);
|
|
@@ -3964,7 +3960,7 @@ class FileManager extends core_1.Host {
|
|
|
3964
3960
|
item[4] = options;
|
|
3965
3961
|
}
|
|
3966
3962
|
PROCESS_STDOUT.clearLine(0);
|
|
3967
|
-
|
|
3963
|
+
Host.formatMessage(...item);
|
|
3968
3964
|
output = true;
|
|
3969
3965
|
}
|
|
3970
3966
|
if (last) {
|
|
@@ -3981,7 +3977,7 @@ class FileManager extends core_1.Host {
|
|
|
3981
3977
|
}
|
|
3982
3978
|
}
|
|
3983
3979
|
else if (output) {
|
|
3984
|
-
processTask.logCurrent =
|
|
3980
|
+
processTask.logCurrent = getLogCurrent();
|
|
3985
3981
|
}
|
|
3986
3982
|
}
|
|
3987
3983
|
if (cleared) {
|
|
@@ -4010,7 +4006,7 @@ class FileManager extends core_1.Host {
|
|
|
4010
4006
|
return Promise.resolve(0);
|
|
4011
4007
|
}
|
|
4012
4008
|
let id = 0, target;
|
|
4013
|
-
if (
|
|
4009
|
+
if (isPlainObject(data)) {
|
|
4014
4010
|
++scheduler.count;
|
|
4015
4011
|
if ('pathname' in data || 'binOpts' in data) {
|
|
4016
4012
|
target = this.fetchFiles(uri, data);
|
|
@@ -4029,9 +4025,9 @@ class FileManager extends core_1.Host {
|
|
|
4029
4025
|
}
|
|
4030
4026
|
else {
|
|
4031
4027
|
if (data instanceof URL && data.protocol === 'file:') {
|
|
4032
|
-
data =
|
|
4028
|
+
data = fileURLToPath(data);
|
|
4033
4029
|
}
|
|
4034
|
-
if (
|
|
4030
|
+
if (isString(data) && Host.isPath(data, true) && this.canRead(data)) {
|
|
4035
4031
|
data = fs.createReadStream(data);
|
|
4036
4032
|
}
|
|
4037
4033
|
}
|
|
@@ -4082,12 +4078,12 @@ class FileManager extends core_1.Host {
|
|
|
4082
4078
|
}
|
|
4083
4079
|
const files = [[item.localUri, mimeType]];
|
|
4084
4080
|
if (item.transforms) {
|
|
4085
|
-
files.push(...item.transforms.map(img => [img,
|
|
4081
|
+
files.push(...item.transforms.map(img => [img, Host.lookupMime(img)]));
|
|
4086
4082
|
}
|
|
4087
4083
|
tasks.push(new Promise(async (resolve) => {
|
|
4088
4084
|
for (const [file, type] of files) {
|
|
4089
4085
|
const ext = type.split('/')[1].split('+')[0];
|
|
4090
|
-
const output = item.compress.filter(({ format, condition }) => (!format && type !==
|
|
4086
|
+
const output = item.compress.filter(({ format, condition }) => (!format && type !== Image.MIME_SVG || format === ext) && (!condition || withinSizeRange(file, condition)));
|
|
4091
4087
|
if (output.length > 0 && this.has(file)) {
|
|
4092
4088
|
for (let i = 0, length = output.length, buffer = null; i < length; ++i) {
|
|
4093
4089
|
const options = output[i];
|
|
@@ -4097,7 +4093,7 @@ class FileManager extends core_1.Host {
|
|
|
4097
4093
|
.then(result => {
|
|
4098
4094
|
if (result) {
|
|
4099
4095
|
if (file === item.localUri) {
|
|
4100
|
-
item.buffer =
|
|
4096
|
+
item.buffer = Compress.asBuffer(result);
|
|
4101
4097
|
}
|
|
4102
4098
|
if (i < length - 1) {
|
|
4103
4099
|
buffer = Buffer.from(result);
|
|
@@ -4143,7 +4139,7 @@ class FileManager extends core_1.Host {
|
|
|
4143
4139
|
async finalizeCloud() {
|
|
4144
4140
|
const instance = this.Cloud;
|
|
4145
4141
|
if (instance) {
|
|
4146
|
-
await
|
|
4142
|
+
await Cloud.finalize.call(this, instance).catch((err) => this.rejectModule(err, 64, { instance }));
|
|
4147
4143
|
}
|
|
4148
4144
|
}
|
|
4149
4145
|
async finalizeChecksum() {
|
|
@@ -4154,18 +4150,18 @@ class FileManager extends core_1.Host {
|
|
|
4154
4150
|
if (typeof checksum === 'boolean' || checksum === 1) {
|
|
4155
4151
|
checksum = { recursive: checksum };
|
|
4156
4152
|
}
|
|
4157
|
-
else if (
|
|
4153
|
+
else if (isString(checksum)) {
|
|
4158
4154
|
const items = checksum.split('.');
|
|
4159
4155
|
checksum = items.length > 1 ? { algorithm: items.at(-1), filename: checksum } : { algorithm: checksum };
|
|
4160
4156
|
}
|
|
4161
|
-
if (
|
|
4157
|
+
if (isPlainObject(checksum)) {
|
|
4162
4158
|
const baseDirectory = this.baseDirectory;
|
|
4163
4159
|
checksum.joinRoot = true;
|
|
4164
4160
|
checksum.throwsEmpty = true;
|
|
4165
4161
|
const sumTime = LOG_TIMEELAPSED ? process.hrtime.bigint() : 0;
|
|
4166
4162
|
const files = (await FileManager.writeChecksum(baseDirectory, checksum.filename, checksum));
|
|
4167
4163
|
if (sumTime) {
|
|
4168
|
-
this.writeTimeElapsed(checksum.algorithm || "sha256", [baseDirectory, files.length + (files.length === 1 ? ' file' : ' files')], sumTime, { ...
|
|
4164
|
+
this.writeTimeElapsed(checksum.algorithm || "sha256", [baseDirectory, files.length + (files.length === 1 ? ' file' : ' files')], sumTime, { ...Host.LOG_STYLE_WARN });
|
|
4169
4165
|
}
|
|
4170
4166
|
}
|
|
4171
4167
|
}
|
|
@@ -4187,17 +4183,17 @@ class FileManager extends core_1.Host {
|
|
|
4187
4183
|
}
|
|
4188
4184
|
async finalize() {
|
|
4189
4185
|
if (this.aborted) {
|
|
4190
|
-
return
|
|
4186
|
+
return createAbortError(true);
|
|
4191
4187
|
}
|
|
4192
4188
|
if (LOG_TIMEELAPSED) {
|
|
4193
|
-
this.writeTimeElapsed('READY', 'Finalizing assets...', this.startTime, { ...
|
|
4189
|
+
this.writeTimeElapsed('READY', 'Finalizing assets...', this.startTime, { ...Host.LOG_STYLE_WARN, showCpu: true });
|
|
4194
4190
|
}
|
|
4195
4191
|
const startTime = process.hrtime.bigint();
|
|
4196
4192
|
for (const [file, output] of this.filesToCompare) {
|
|
4197
4193
|
const localUri = file.localUri;
|
|
4198
|
-
let minFile = localUri, minSize =
|
|
4194
|
+
let minFile = localUri, minSize = getSize(minFile);
|
|
4199
4195
|
for (const other of output) {
|
|
4200
|
-
const size =
|
|
4196
|
+
const size = getSize(other);
|
|
4201
4197
|
if (minSize === 0 || size > 0 && size < minSize) {
|
|
4202
4198
|
this.filesToRemove.add(minFile);
|
|
4203
4199
|
minFile = other;
|
|
@@ -4214,11 +4210,11 @@ class FileManager extends core_1.Host {
|
|
|
4214
4210
|
this.removeFiles();
|
|
4215
4211
|
await this.finalizeCompress(this.assets.filter(item => item.compress && !ignoreAsset(item))).catch((err) => this.rejectModule(err, 8));
|
|
4216
4212
|
if (this.aborted) {
|
|
4217
|
-
return
|
|
4213
|
+
return createAbortError(true);
|
|
4218
4214
|
}
|
|
4219
4215
|
await this.finalizeDocument().catch((err) => this.rejectModule(err, 4));
|
|
4220
4216
|
if (this.aborted) {
|
|
4221
|
-
return
|
|
4217
|
+
return createAbortError(true);
|
|
4222
4218
|
}
|
|
4223
4219
|
for (const item of this.assets) {
|
|
4224
4220
|
if (item.sourceUTF8 && !ignoreAsset(item)) {
|
|
@@ -4233,7 +4229,7 @@ class FileManager extends core_1.Host {
|
|
|
4233
4229
|
this.removeFiles();
|
|
4234
4230
|
await this.finalizeTask(this.taskAssets.filter(item => item.tasks?.find(data => !data.preceding) && this.has(item.localUri) && !ignoreAsset(item))).catch((err) => this.rejectModule(err, 4));
|
|
4235
4231
|
if (this.aborted) {
|
|
4236
|
-
return
|
|
4232
|
+
return createAbortError(true);
|
|
4237
4233
|
}
|
|
4238
4234
|
for (const item of this.assets) {
|
|
4239
4235
|
if (item.checksumOutput && !ignoreAsset(item)) {
|
|
@@ -4241,14 +4237,14 @@ class FileManager extends core_1.Host {
|
|
|
4241
4237
|
if (!this.filesToRemove.has(localUri) && !this.checkHash(item.checksumOutput, { uri: localUri, output: true })) {
|
|
4242
4238
|
item.invalid = true;
|
|
4243
4239
|
this.filesToRemove.add(localUri);
|
|
4244
|
-
this.writeFail(["Checksum did not match", path.basename(localUri)],
|
|
4240
|
+
this.writeFail(["Checksum did not match", path.basename(localUri)], errorValue(localUri, "Invalid checksum"), { type: 32, startTime, queue: true });
|
|
4245
4241
|
}
|
|
4246
4242
|
}
|
|
4247
4243
|
}
|
|
4248
4244
|
this.removeFiles();
|
|
4249
4245
|
await this.finalizeCloud().catch((err) => this.rejectModule(err, 64));
|
|
4250
4246
|
if (this.aborted) {
|
|
4251
|
-
return
|
|
4247
|
+
return createAbortError(true);
|
|
4252
4248
|
}
|
|
4253
4249
|
this.removeFiles();
|
|
4254
4250
|
if (this.Compress) {
|
|
@@ -4307,7 +4303,7 @@ class FileManager extends core_1.Host {
|
|
|
4307
4303
|
}
|
|
4308
4304
|
startMessage() {
|
|
4309
4305
|
if (!this.silent) {
|
|
4310
|
-
this.formatMessage(128, 'START', [new Date().toLocaleString(), formatLength('asset', this.assets.length)], this.baseDirectory, { ...
|
|
4306
|
+
this.formatMessage(128, 'START', [new Date().toLocaleString(), formatLength('asset', this.assets.length)], this.baseDirectory, { ...Host.LOG_STYLE_SUCCESS });
|
|
4311
4307
|
}
|
|
4312
4308
|
}
|
|
4313
4309
|
closeMessage(startTime) {
|
|
@@ -4319,13 +4315,13 @@ class FileManager extends core_1.Host {
|
|
|
4319
4315
|
}
|
|
4320
4316
|
this.#downloadStats.forEach(([size, count], index) => {
|
|
4321
4317
|
if (count > 0) {
|
|
4322
|
-
message.push(`${
|
|
4318
|
+
message.push(`${DOWNLOAD_TYPE[index]} ` + (count > 1 && MEMORY.FILE_COUNT ? count + ' / ' : '') + formatSize(size));
|
|
4323
4319
|
}
|
|
4324
4320
|
});
|
|
4325
4321
|
if (MEMORY.SIZE > 0) {
|
|
4326
|
-
message.push('BUFFER ' + (MEMORY.CACHE.size > 1 && MEMORY.FILE_COUNT ? MEMORY.CACHE.size + ' / ' : '') +
|
|
4322
|
+
message.push('BUFFER ' + (MEMORY.CACHE.size > 1 && MEMORY.FILE_COUNT ? MEMORY.CACHE.size + ' / ' : '') + formatSize(MEMORY.SIZE));
|
|
4327
4323
|
}
|
|
4328
|
-
this.writeTimeElapsed('CLOSE', ['No further modifications', message.length > 0 ? message.join(chalk.blackBright(LOGGER.MESSAGE_SEP)) : ''], startTime, { ...
|
|
4324
|
+
this.writeTimeElapsed('CLOSE', ['No further modifications', message.length > 0 ? message.join(chalk.blackBright(LOGGER.MESSAGE_SEP)) : ''], startTime, { ...Host.LOG_STYLE_WARN });
|
|
4329
4325
|
}
|
|
4330
4326
|
}
|
|
4331
4327
|
diffMessage() {
|
|
@@ -4339,9 +4335,9 @@ class FileManager extends core_1.Host {
|
|
|
4339
4335
|
};
|
|
4340
4336
|
let divider = false;
|
|
4341
4337
|
for (const pathname in diffSource) {
|
|
4342
|
-
if (
|
|
4338
|
+
if (Host.isPath(pathname, true)) {
|
|
4343
4339
|
const [content, encoding] = diffSource[pathname];
|
|
4344
|
-
const hunks =
|
|
4340
|
+
const hunks = structuredPatch('', '', checkEOF(content), checkEOF(fs.readFileSync(pathname, encoding)), '', '', { context: 0 }).hunks;
|
|
4345
4341
|
const lastHunk = hunks.at(-1);
|
|
4346
4342
|
if (lastHunk) {
|
|
4347
4343
|
const oldMax = lastHunk.oldStart + lastHunk.oldLines;
|
|
@@ -4350,7 +4346,7 @@ class FileManager extends core_1.Host {
|
|
|
4350
4346
|
addHeader(pathname, formatLength('hunk', hunks.length));
|
|
4351
4347
|
for (const { lines, oldLines, oldStart, newStart, newLines } of hunks) {
|
|
4352
4348
|
for (let i = 0, j = oldStart, k = oldLines, l = 0, q = lines.length, added = false; i < q && k > 0; ++i) {
|
|
4353
|
-
const line = lines[i].
|
|
4349
|
+
const line = lines[i].slice(1);
|
|
4354
4350
|
output.push(` ${chalk[!line && k === 1 ? 'grey' : added ? 'green' : 'red']((j + l++).toString().padStart(posLength))} ${chalk[added ? 'green' : 'red'](line)}`);
|
|
4355
4351
|
if (--k === 0 && !added) {
|
|
4356
4352
|
j = newStart;
|
|
@@ -4373,18 +4369,18 @@ class FileManager extends core_1.Host {
|
|
|
4373
4369
|
output.push(chalk.blackBright('-'.repeat(LOGGER.MESSAGE_WIDTH)));
|
|
4374
4370
|
}
|
|
4375
4371
|
output.push('');
|
|
4376
|
-
if (this.broadcastId &&
|
|
4377
|
-
|
|
4372
|
+
if (this.broadcastId && Host.hasLogType(2)) {
|
|
4373
|
+
Host.formatMessage(2, '', '', output.join('\n'), { broadcastId: this.broadcastId, rawOutput: true });
|
|
4378
4374
|
}
|
|
4379
4375
|
else {
|
|
4380
4376
|
process.stdout.write(output.join('\n'));
|
|
4381
|
-
|
|
4377
|
+
setLogCurrent(null);
|
|
4382
4378
|
}
|
|
4383
4379
|
}
|
|
4384
4380
|
}
|
|
4385
4381
|
endMessage(errors) {
|
|
4386
4382
|
if (LOG_TIMEELAPSED) {
|
|
4387
|
-
this.writeTimeElapsed('END', this.baseDirectory, this.startTime, errors.length > 0 ? { failed: true, ...
|
|
4383
|
+
this.writeTimeElapsed('END', this.baseDirectory, this.startTime, errors.length > 0 ? { failed: true, ...Host.LOG_STYLE_FAIL } : { ...Host.LOG_STYLE_SUCCESS });
|
|
4388
4384
|
}
|
|
4389
4385
|
}
|
|
4390
4386
|
clearStorage() {
|
|
@@ -4398,7 +4394,7 @@ class FileManager extends core_1.Host {
|
|
|
4398
4394
|
const errors = instance.errors;
|
|
4399
4395
|
if (errors.length > 0) {
|
|
4400
4396
|
for (const value of errors) {
|
|
4401
|
-
outLog.push(`[${instance.moduleName}] ` + (
|
|
4397
|
+
outLog.push(`[${instance.moduleName}] ` + (Host.asString(value) || "Unknown"));
|
|
4402
4398
|
}
|
|
4403
4399
|
errors.length = 0;
|
|
4404
4400
|
}
|
|
@@ -4430,16 +4426,16 @@ class FileManager extends core_1.Host {
|
|
|
4430
4426
|
}
|
|
4431
4427
|
}
|
|
4432
4428
|
#tryPackage(target, name, type) {
|
|
4433
|
-
if (
|
|
4429
|
+
if (isString(target)) {
|
|
4434
4430
|
try {
|
|
4435
|
-
target =
|
|
4431
|
+
target = requireESM(target);
|
|
4436
4432
|
}
|
|
4437
4433
|
catch (err) {
|
|
4438
4434
|
this.checkPackage(err, target, ["Unable to load handler", this.moduleName], type);
|
|
4439
4435
|
return null;
|
|
4440
4436
|
}
|
|
4441
4437
|
}
|
|
4442
|
-
return
|
|
4438
|
+
return Host.constructorOf(target, name) ? target : null;
|
|
4443
4439
|
}
|
|
4444
4440
|
#collectErrors() {
|
|
4445
4441
|
const result = [];
|
|
@@ -4576,4 +4572,5 @@ class FileManager extends core_1.Host {
|
|
|
4576
4572
|
}
|
|
4577
4573
|
}
|
|
4578
4574
|
setLogMinWidth();
|
|
4575
|
+
|
|
4579
4576
|
module.exports = FileManager;
|