@e-mc/file-manager 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +4 -8
- package/README.md +5 -3
- package/index.js +160 -163
- package/package.json +12 -12
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Sukina
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
11
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint @typescript-eslint/no-explicit-any: "off" */
|
|
3
2
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
4
|
const path = require("path");
|
|
6
5
|
const fs = require("fs");
|
|
7
6
|
const pm = require("picomatch");
|
|
8
|
-
const lib_v4_1 = require("
|
|
9
|
-
const util_1 = require("
|
|
10
|
-
const asset_1 = require("
|
|
11
|
-
const util_2 = require("
|
|
12
|
-
const types_1 = require("
|
|
13
|
-
const core_1 = require("
|
|
14
|
-
const request_1 = require("
|
|
15
|
-
const document_1 = require("
|
|
16
|
-
const task_1 = require("
|
|
17
|
-
const image_1 = require("
|
|
18
|
-
const watch_1 = require("
|
|
19
|
-
const compress_1 = require("
|
|
20
|
-
const cloud_1 = require("
|
|
7
|
+
const lib_v4_1 = require("@e-mc/module/lib-v4");
|
|
8
|
+
const util_1 = require("@e-mc/request/util");
|
|
9
|
+
const asset_1 = require("@e-mc/document/asset");
|
|
10
|
+
const util_2 = require("@e-mc/document/util");
|
|
11
|
+
const types_1 = require("@e-mc/types");
|
|
12
|
+
const core_1 = require("@e-mc/core");
|
|
13
|
+
const request_1 = require("@e-mc/request");
|
|
14
|
+
const document_1 = require("@e-mc/document");
|
|
15
|
+
const task_1 = require("@e-mc/task");
|
|
16
|
+
const image_1 = require("@e-mc/image");
|
|
17
|
+
const watch_1 = require("@e-mc/watch");
|
|
18
|
+
const compress_1 = require("@e-mc/compress");
|
|
19
|
+
const cloud_1 = require("@e-mc/cloud");
|
|
21
20
|
const kBaseDirectory = Symbol('baseDirectory');
|
|
22
21
|
const kIncremental = Symbol('incremental');
|
|
23
22
|
const kRestarting = Symbol('restarting');
|
|
@@ -37,7 +36,7 @@ const CACHE_ETAG = {};
|
|
|
37
36
|
const DISK = {
|
|
38
37
|
ENABLED: false,
|
|
39
38
|
EXPIRES: 0,
|
|
40
|
-
LIMIT: (0, types_1.formatSize)("1gb"
|
|
39
|
+
LIMIT: (0, types_1.formatSize)("1gb"),
|
|
41
40
|
INCLUDE: [],
|
|
42
41
|
EXCLUDE: []
|
|
43
42
|
};
|
|
@@ -47,8 +46,8 @@ const MEMORY = {
|
|
|
47
46
|
SIZE: 0,
|
|
48
47
|
TOTAL: 0,
|
|
49
48
|
EXPIRES: 0,
|
|
50
|
-
LIMIT: (0, types_1.formatSize)("100mb"
|
|
51
|
-
LIMIT_ALL: (0, types_1.formatSize)("512mb"
|
|
49
|
+
LIMIT: (0, types_1.formatSize)("100mb"),
|
|
50
|
+
LIMIT_ALL: (0, types_1.formatSize)("512mb"),
|
|
52
51
|
INCLUDE: [],
|
|
53
52
|
EXCLUDE: [],
|
|
54
53
|
PURGE: 0.25,
|
|
@@ -62,11 +61,11 @@ let RECURSION_LIMIT = 10;
|
|
|
62
61
|
let LOG_TIMEELAPSED = true;
|
|
63
62
|
let LOG_TIMEPROCESS = true;
|
|
64
63
|
const HTTP_CLIENT = {
|
|
65
|
-
timeout: 60000
|
|
66
|
-
connectTimeout: 20 * 1000
|
|
64
|
+
timeout: 60000,
|
|
65
|
+
connectTimeout: 20 * 1000,
|
|
67
66
|
redirectLimit: 3,
|
|
68
|
-
retryWait: 1000
|
|
69
|
-
retryAfter: 30 * 1000
|
|
67
|
+
retryWait: 1000,
|
|
68
|
+
retryAfter: 30 * 1000,
|
|
70
69
|
retryLimit: 10
|
|
71
70
|
};
|
|
72
71
|
function applyTimeout(target, options) {
|
|
@@ -97,7 +96,7 @@ function withinSizeRange(uri, value, pattern) {
|
|
|
97
96
|
return true;
|
|
98
97
|
}
|
|
99
98
|
function startMessage() {
|
|
100
|
-
this.formatMessage(128
|
|
99
|
+
this.formatMessage(128, 'START', [new Date().toLocaleString(), this.assets.length + ' assets'], this.baseDirectory, { ...core_1.Host.LOG_STYLE_SUCCESS });
|
|
101
100
|
}
|
|
102
101
|
function clearAssets() {
|
|
103
102
|
this.assets.forEach(item => {
|
|
@@ -117,7 +116,7 @@ function bundleTorrent(files, mimeType, encoding) {
|
|
|
117
116
|
output += fs.readFileSync(file, encoding);
|
|
118
117
|
}
|
|
119
118
|
catch (err) {
|
|
120
|
-
this.writeFail(["Unable to read file"
|
|
119
|
+
this.writeFail(["Unable to read file", path.basename(file)], err, 32);
|
|
121
120
|
}
|
|
122
121
|
}
|
|
123
122
|
}
|
|
@@ -134,13 +133,13 @@ function recurseDir(output, subDirs, options) {
|
|
|
134
133
|
.sort((a, b) => {
|
|
135
134
|
if (sortBy > 0) {
|
|
136
135
|
if (a.isDirectory() && !b.isDirectory()) {
|
|
137
|
-
return sortBy & 1
|
|
136
|
+
return sortBy & 1 ? -1 : 1;
|
|
138
137
|
}
|
|
139
138
|
if (!a.isDirectory() && b.isDirectory()) {
|
|
140
|
-
return sortBy & 1
|
|
139
|
+
return sortBy & 1 ? 1 : -1;
|
|
141
140
|
}
|
|
142
141
|
}
|
|
143
|
-
return (a.name < b.name ? -1 : 1) * (2
|
|
142
|
+
return (a.name < b.name ? -1 : 1) * (2 & 2 ? -1 : 1);
|
|
144
143
|
});
|
|
145
144
|
for (const item of items) {
|
|
146
145
|
if (!item.isDirectory()) {
|
|
@@ -209,7 +208,7 @@ function filterPaths(values, include, exclude, dot) {
|
|
|
209
208
|
return values;
|
|
210
209
|
}
|
|
211
210
|
function abortedHost() {
|
|
212
|
-
if (this.finalizeState === 6
|
|
211
|
+
if (this.finalizeState === 6) {
|
|
213
212
|
this.restarting = false;
|
|
214
213
|
this.performFinalize(true);
|
|
215
214
|
return this.done;
|
|
@@ -231,7 +230,7 @@ function observeFile(instance) {
|
|
|
231
230
|
if (PLATFORM_WIN32) {
|
|
232
231
|
value = value.toLowerCase();
|
|
233
232
|
}
|
|
234
|
-
if (value
|
|
233
|
+
if (!value.endsWith(path.sep)) {
|
|
235
234
|
value += path.sep;
|
|
236
235
|
}
|
|
237
236
|
for (const name of this.files) {
|
|
@@ -253,7 +252,7 @@ function collectErrors() {
|
|
|
253
252
|
const clearModule = (instance) => {
|
|
254
253
|
const { moduleName, errors } = instance;
|
|
255
254
|
if (errors.length) {
|
|
256
|
-
errors.forEach(value => result.push(`[${moduleName}] ` + (core_1.Host.asString(value) || "Unknown"
|
|
255
|
+
errors.forEach(value => result.push(`[${moduleName}] ` + (core_1.Host.asString(value) || "Unknown")));
|
|
257
256
|
errors.length = 0;
|
|
258
257
|
}
|
|
259
258
|
};
|
|
@@ -275,12 +274,12 @@ function collectErrors() {
|
|
|
275
274
|
return result;
|
|
276
275
|
}
|
|
277
276
|
function rejectModule(err, type, hint) {
|
|
278
|
-
this.writeFail(["Handled rejection"
|
|
277
|
+
this.writeFail(["Handled rejection", this.moduleName + (hint ? ': ' + hint : '')], err, type);
|
|
279
278
|
}
|
|
280
|
-
const checksumFile = (algorithm) => "checksum"
|
|
281
|
-
const checksumError = (algorithm) => new Error("Invalid parameters"
|
|
279
|
+
const checksumFile = (algorithm) => "checksum" + '.' + ((0, types_1.isString)(algorithm) ? algorithm.toLowerCase() : "sha256");
|
|
280
|
+
const checksumError = (algorithm) => new Error("Invalid parameters" + ` (${algorithm || "sha256"})`);
|
|
282
281
|
const isFunction = (value) => typeof value === 'function';
|
|
283
|
-
const ignoreAsset = (item, exists) => item.invalid || (0, types_1.hasBit)(item.flags, 1
|
|
282
|
+
const ignoreAsset = (item, exists) => item.invalid || (0, types_1.hasBit)(item.flags, 1 | (!exists ? 128 : 0));
|
|
284
283
|
class HttpDiskCache {
|
|
285
284
|
constructor(host, enabled) {
|
|
286
285
|
this.host = host;
|
|
@@ -412,7 +411,7 @@ class HttpDiskCache {
|
|
|
412
411
|
}
|
|
413
412
|
class HttpMemoryCache extends HttpDiskCache {
|
|
414
413
|
constructor(host, enabled) {
|
|
415
|
-
super(host, enabled && core_1.Host.enabled("memory.settings.users"
|
|
414
|
+
super(host, enabled && core_1.Host.enabled("memory.settings.users", host.username));
|
|
416
415
|
this.limit = MEMORY.LIMIT;
|
|
417
416
|
this.expires = MEMORY.EXPIRES;
|
|
418
417
|
this.toDisk = [MEMORY.DISK_MIN, MEMORY.DISK_MAX];
|
|
@@ -593,8 +592,8 @@ class FileManager extends core_1.Host {
|
|
|
593
592
|
SESSION_LIMIT = Math.pow(10, value);
|
|
594
593
|
}
|
|
595
594
|
}
|
|
596
|
-
LOG_TIMEELAPSED = this.hasLogType(128
|
|
597
|
-
LOG_TIMEPROCESS = this.hasLogType(256
|
|
595
|
+
LOG_TIMEELAPSED = this.hasLogType(128);
|
|
596
|
+
LOG_TIMEPROCESS = this.hasLogType(256);
|
|
598
597
|
return true;
|
|
599
598
|
}
|
|
600
599
|
return false;
|
|
@@ -614,7 +613,7 @@ class FileManager extends core_1.Host {
|
|
|
614
613
|
for (const attr in item) {
|
|
615
614
|
switch (attr) {
|
|
616
615
|
case 'flags':
|
|
617
|
-
item.flags &= ~(128
|
|
616
|
+
item.flags &= ~(128 | 16);
|
|
618
617
|
break;
|
|
619
618
|
case 'watch':
|
|
620
619
|
if ((0, types_1.isPlainObject)(item.watch) && item.watch.assets) {
|
|
@@ -684,7 +683,7 @@ class FileManager extends core_1.Host {
|
|
|
684
683
|
if (options.throwsEmpty) {
|
|
685
684
|
throw err;
|
|
686
685
|
}
|
|
687
|
-
this.writeFail(["Unable to read directory"
|
|
686
|
+
this.writeFail(["Unable to read directory", root], err, 32);
|
|
688
687
|
return null;
|
|
689
688
|
}
|
|
690
689
|
return result;
|
|
@@ -722,7 +721,7 @@ class FileManager extends core_1.Host {
|
|
|
722
721
|
fail.push(pathname);
|
|
723
722
|
}
|
|
724
723
|
else if (verbose) {
|
|
725
|
-
process.stdout.write("+"
|
|
724
|
+
process.stdout.write("+" + ' ' + pathname + '\n');
|
|
726
725
|
}
|
|
727
726
|
valid = true;
|
|
728
727
|
}
|
|
@@ -734,7 +733,7 @@ class FileManager extends core_1.Host {
|
|
|
734
733
|
const nested = files.filter(value => path.basename(value) === filename);
|
|
735
734
|
if (nested.length) {
|
|
736
735
|
const current = items.map(item => item[1]);
|
|
737
|
-
const tasks = nested.map(pathname => this.verifyChecksum(path.dirname(pathname), filename, { ...options, ignore: current, joinRoot: true, verbose: (verbose ? 1 : 0) }));
|
|
736
|
+
const tasks = nested.map(async (pathname) => this.verifyChecksum(path.dirname(pathname), filename, { ...options, ignore: current, joinRoot: true, verbose: (verbose ? 1 : 0) }));
|
|
738
737
|
await Promise.all(tasks).then(group => {
|
|
739
738
|
for (const item of group) {
|
|
740
739
|
if (item) {
|
|
@@ -762,7 +761,7 @@ class FileManager extends core_1.Host {
|
|
|
762
761
|
if (options.throwsEmpty) {
|
|
763
762
|
throw err;
|
|
764
763
|
}
|
|
765
|
-
this.writeFail(["Unable to read directory"
|
|
764
|
+
this.writeFail(["Unable to read directory", root], err, 32);
|
|
766
765
|
return null;
|
|
767
766
|
}
|
|
768
767
|
if (parent) {
|
|
@@ -776,8 +775,8 @@ class FileManager extends core_1.Host {
|
|
|
776
775
|
if (verbose === true) {
|
|
777
776
|
const max = Math.max(...fail.concat(missing).map(item => item.length));
|
|
778
777
|
const writeLog = (items, symbol) => items.forEach((value, index) => process.stdout.write(`${symbol} ${value.padEnd(max)} (${(index + 1).toString()})\n`));
|
|
779
|
-
writeLog(fail, "-"
|
|
780
|
-
writeLog(missing, "?"
|
|
778
|
+
writeLog(fail, "-");
|
|
779
|
+
writeLog(missing, "?");
|
|
781
780
|
}
|
|
782
781
|
return [fail, missing];
|
|
783
782
|
}
|
|
@@ -850,7 +849,7 @@ class FileManager extends core_1.Host {
|
|
|
850
849
|
HTTP_CLIENT.connectTimeout = timeout;
|
|
851
850
|
}
|
|
852
851
|
if ((retry_wait = (0, util_1.fromSeconds)(retry_wait)) >= 0) {
|
|
853
|
-
HTTP_CLIENT.retryWait = Math.min(retry_wait, 600 * 1000
|
|
852
|
+
HTTP_CLIENT.retryWait = Math.min(retry_wait, 600 * 1000);
|
|
854
853
|
}
|
|
855
854
|
if ((retry_after = (0, util_1.fromSeconds)(retry_after)) >= 0) {
|
|
856
855
|
HTTP_CLIENT.retryAfter = Math.min(retry_after, this.MAX_TIMEOUT);
|
|
@@ -864,7 +863,7 @@ class FileManager extends core_1.Host {
|
|
|
864
863
|
}
|
|
865
864
|
constructor(baseDirectory, config, permission, postFinalize) {
|
|
866
865
|
super(config);
|
|
867
|
-
this.finalizeState = 0
|
|
866
|
+
this.finalizeState = 0;
|
|
868
867
|
this.processTimeout = PROCESS_TIMEOUT.filemanager;
|
|
869
868
|
this.Document = [];
|
|
870
869
|
this.Task = [];
|
|
@@ -966,7 +965,7 @@ class FileManager extends core_1.Host {
|
|
|
966
965
|
request.host = this;
|
|
967
966
|
this.Request = request;
|
|
968
967
|
if (this.aborted) {
|
|
969
|
-
this.finalizeState = 6
|
|
968
|
+
this.finalizeState = 6;
|
|
970
969
|
}
|
|
971
970
|
else {
|
|
972
971
|
request.init(config).apply({ client: HTTP_CLIENT });
|
|
@@ -1076,7 +1075,7 @@ class FileManager extends core_1.Host {
|
|
|
1076
1075
|
}
|
|
1077
1076
|
if (this.restartable && (!recursive || --this[kRecursionLimit] >= 0)) {
|
|
1078
1077
|
if (this.reset()) {
|
|
1079
|
-
this.finalizeState = 5
|
|
1078
|
+
this.finalizeState = 5;
|
|
1080
1079
|
FileManager.sanitizeAssets(this.assets, exclusions);
|
|
1081
1080
|
for (const { instance } of this.Document) {
|
|
1082
1081
|
instance.restart();
|
|
@@ -1124,7 +1123,7 @@ class FileManager extends core_1.Host {
|
|
|
1124
1123
|
}
|
|
1125
1124
|
}
|
|
1126
1125
|
reset() {
|
|
1127
|
-
if (this.finalizeState === 1
|
|
1126
|
+
if (this.finalizeState === 1) {
|
|
1128
1127
|
return false;
|
|
1129
1128
|
}
|
|
1130
1129
|
super.reset();
|
|
@@ -1146,7 +1145,7 @@ class FileManager extends core_1.Host {
|
|
|
1146
1145
|
clearAssets.call(this);
|
|
1147
1146
|
this.cleared = false;
|
|
1148
1147
|
this[kDelayed] = 0;
|
|
1149
|
-
this.finalizeState = 0
|
|
1148
|
+
this.finalizeState = 0;
|
|
1150
1149
|
return true;
|
|
1151
1150
|
}
|
|
1152
1151
|
deleteFile(value, options = {}, callback) {
|
|
@@ -1171,11 +1170,11 @@ class FileManager extends core_1.Host {
|
|
|
1171
1170
|
}
|
|
1172
1171
|
resumeThread(options) {
|
|
1173
1172
|
if (this.aborted || options.aborted) {
|
|
1174
|
-
this.finalizeState = 0
|
|
1173
|
+
this.finalizeState = 0;
|
|
1175
1174
|
this.performFinalize(true);
|
|
1176
1175
|
return;
|
|
1177
1176
|
}
|
|
1178
|
-
this.finalizeState = 5
|
|
1177
|
+
this.finalizeState = 5;
|
|
1179
1178
|
startMessage.call(this);
|
|
1180
1179
|
this.processAssets(...options.args);
|
|
1181
1180
|
}
|
|
@@ -1211,7 +1210,7 @@ class FileManager extends core_1.Host {
|
|
|
1211
1210
|
if (typeof target === 'string') {
|
|
1212
1211
|
const module = args.shift();
|
|
1213
1212
|
if ((0, types_1.isObject)(module)) {
|
|
1214
|
-
if (target === "@e-mc/cloud"
|
|
1213
|
+
if (target === "@e-mc/cloud") {
|
|
1215
1214
|
instance = new cloud_1.default(module, database);
|
|
1216
1215
|
}
|
|
1217
1216
|
else {
|
|
@@ -1221,11 +1220,11 @@ class FileManager extends core_1.Host {
|
|
|
1221
1220
|
instance = new Handler(module, database);
|
|
1222
1221
|
}
|
|
1223
1222
|
else {
|
|
1224
|
-
throw (0, types_1.errorMessage)(this.moduleName, "Not a Cloud constructor"
|
|
1223
|
+
throw (0, types_1.errorMessage)(this.moduleName, "Not a Cloud constructor", target);
|
|
1225
1224
|
}
|
|
1226
1225
|
}
|
|
1227
1226
|
catch (err) {
|
|
1228
|
-
this.checkPackage(err, target, ["Unable to load handler"
|
|
1227
|
+
this.checkPackage(err, target, ["Unable to load handler", this.moduleName], 64);
|
|
1229
1228
|
}
|
|
1230
1229
|
}
|
|
1231
1230
|
}
|
|
@@ -1269,17 +1268,20 @@ class FileManager extends core_1.Host {
|
|
|
1269
1268
|
manager.install('cloud', this.Cloud.module);
|
|
1270
1269
|
}
|
|
1271
1270
|
if (this.Image) {
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1271
|
+
const mimeMap = new Map();
|
|
1272
|
+
let params = [];
|
|
1273
|
+
for (const [mimeType, handler] of this.Image) {
|
|
1274
|
+
const { constructor, params: trailing } = handler;
|
|
1275
|
+
if (params.length === 0 || mimeType === 'handler') {
|
|
1276
|
+
params = trailing;
|
|
1278
1277
|
}
|
|
1278
|
+
mimeMap.set(mimeType, constructor);
|
|
1279
1279
|
}
|
|
1280
|
-
manager.
|
|
1280
|
+
manager.install('image', mimeMap, ...params);
|
|
1281
|
+
}
|
|
1282
|
+
if (this.Compress) {
|
|
1283
|
+
manager.install('compress', this.Compress.module);
|
|
1281
1284
|
}
|
|
1282
|
-
manager.Compress = this.Compress;
|
|
1283
1285
|
manager.sessionId = this.sessionId;
|
|
1284
1286
|
manager.permission = this.permission;
|
|
1285
1287
|
manager.cacheToDisk = this.cacheToDisk;
|
|
@@ -1289,7 +1291,7 @@ class FileManager extends core_1.Host {
|
|
|
1289
1291
|
manager.processAssets();
|
|
1290
1292
|
}
|
|
1291
1293
|
catch (err) {
|
|
1292
|
-
manager.writeFail("Unknown"
|
|
1294
|
+
manager.writeFail("Unknown", err, { startTime: manager.startTime });
|
|
1293
1295
|
}
|
|
1294
1296
|
}
|
|
1295
1297
|
return manager;
|
|
@@ -1347,7 +1349,7 @@ class FileManager extends core_1.Host {
|
|
|
1347
1349
|
if (value) {
|
|
1348
1350
|
const isSame = (a, b) => a === b || decodeURIComponent(a) === decodeURIComponent(b);
|
|
1349
1351
|
const result = (assets || this.assets).filter(item => {
|
|
1350
|
-
|
|
1352
|
+
const { uri, flags } = item;
|
|
1351
1353
|
if (uri && (!instance || this.hasDocument(instance, item.document)) && (!item.invalid || assets || (0, types_1.mainFlag)(flags) || (0, types_1.usingFlag)(flags) || (0, types_1.cloneFlag)(flags) || (0, types_1.watchFlag)(flags))) {
|
|
1352
1354
|
if (origin) {
|
|
1353
1355
|
if (!item.url) {
|
|
@@ -1369,13 +1371,7 @@ class FileManager extends core_1.Host {
|
|
|
1369
1371
|
const indexA = uri.indexOf('#');
|
|
1370
1372
|
const indexB = value.indexOf('#');
|
|
1371
1373
|
if (indexA !== -1 || indexB !== -1) {
|
|
1372
|
-
|
|
1373
|
-
uri = uri.substring(0, indexA);
|
|
1374
|
-
}
|
|
1375
|
-
if (indexB !== -1) {
|
|
1376
|
-
value = value.substring(0, indexB);
|
|
1377
|
-
}
|
|
1378
|
-
return isSame(uri, value);
|
|
1374
|
+
return isSame(indexA !== -1 ? uri.substring(0, indexA) : uri, indexB !== -1 ? value.substring(0, indexB) : value);
|
|
1379
1375
|
}
|
|
1380
1376
|
}
|
|
1381
1377
|
return false;
|
|
@@ -1456,7 +1452,7 @@ class FileManager extends core_1.Host {
|
|
|
1456
1452
|
}
|
|
1457
1453
|
}
|
|
1458
1454
|
catch (err) {
|
|
1459
|
-
this.writeFail(["Unable to rename file"
|
|
1455
|
+
this.writeFail(["Unable to rename file", name], err, 32);
|
|
1460
1456
|
return false;
|
|
1461
1457
|
}
|
|
1462
1458
|
}
|
|
@@ -1477,7 +1473,7 @@ class FileManager extends core_1.Host {
|
|
|
1477
1473
|
file.pathname = pathname;
|
|
1478
1474
|
file.filename = filename;
|
|
1479
1475
|
this.setLocalUri(file, true);
|
|
1480
|
-
this.writeFail(["Unable to rename file"
|
|
1476
|
+
this.writeFail(["Unable to rename file", name], err, 32);
|
|
1481
1477
|
return false;
|
|
1482
1478
|
}
|
|
1483
1479
|
}
|
|
@@ -1514,7 +1510,7 @@ class FileManager extends core_1.Host {
|
|
|
1514
1510
|
}
|
|
1515
1511
|
}
|
|
1516
1512
|
catch (err) {
|
|
1517
|
-
this.writeFail(["Unable to rename file"
|
|
1513
|
+
this.writeFail(["Unable to rename file", path.basename(value)], err, 32);
|
|
1518
1514
|
return false;
|
|
1519
1515
|
}
|
|
1520
1516
|
if (!copy) {
|
|
@@ -1542,25 +1538,25 @@ class FileManager extends core_1.Host {
|
|
|
1542
1538
|
this.performFinalize();
|
|
1543
1539
|
}
|
|
1544
1540
|
if (err) {
|
|
1545
|
-
this.writeFail(["Unknown"
|
|
1541
|
+
this.writeFail(["Unknown", uri], err, 32);
|
|
1546
1542
|
}
|
|
1547
1543
|
}
|
|
1548
1544
|
performFinalize(override) {
|
|
1549
1545
|
const state = this.finalizeState;
|
|
1550
|
-
if (state === 0
|
|
1546
|
+
if (state === 0 && (this.cleared && this[kDelayed] <= 0 || override) || (this.aborted || state === 3) && override) {
|
|
1551
1547
|
this.clearProcessTimeout();
|
|
1552
1548
|
this[kDelayed] = Infinity;
|
|
1553
1549
|
const resetState = () => {
|
|
1554
|
-
this.finalizeState = 2
|
|
1550
|
+
this.finalizeState = 2;
|
|
1555
1551
|
this._pendingResult = null;
|
|
1556
1552
|
};
|
|
1557
1553
|
const aborted = (err) => {
|
|
1558
1554
|
if (!this.restarting) {
|
|
1559
|
-
this.writeFail(["Transaction was not completed"
|
|
1555
|
+
this.writeFail(["Transaction was not completed", this.baseDirectory], err);
|
|
1560
1556
|
resetState();
|
|
1561
1557
|
}
|
|
1562
1558
|
else {
|
|
1563
|
-
this.finalizeState = 4
|
|
1559
|
+
this.finalizeState = 4;
|
|
1564
1560
|
}
|
|
1565
1561
|
this.emit('end', [], collectErrors.call(this), this.collectLog());
|
|
1566
1562
|
if (!this.restarting) {
|
|
@@ -1571,16 +1567,16 @@ class FileManager extends core_1.Host {
|
|
|
1571
1567
|
aborted((0, types_1.createAbortError)());
|
|
1572
1568
|
return;
|
|
1573
1569
|
}
|
|
1574
|
-
this.finalizeState = 1
|
|
1570
|
+
this.finalizeState = 1;
|
|
1575
1571
|
this.finalize()
|
|
1576
1572
|
.then(() => {
|
|
1577
1573
|
const errors = collectErrors.call(this);
|
|
1578
1574
|
const files = Array.from(this.files).sort((a, b) => {
|
|
1579
1575
|
const sep = path.sep;
|
|
1580
|
-
if (a.
|
|
1576
|
+
if (a.includes(sep) && !b.includes(sep)) {
|
|
1581
1577
|
return -1;
|
|
1582
1578
|
}
|
|
1583
|
-
if (a.
|
|
1579
|
+
if (!a.includes(sep) && b.includes(sep)) {
|
|
1584
1580
|
return 1;
|
|
1585
1581
|
}
|
|
1586
1582
|
return a < b ? -1 : 1;
|
|
@@ -1621,7 +1617,7 @@ class FileManager extends core_1.Host {
|
|
|
1621
1617
|
file.uri = file.url.toString();
|
|
1622
1618
|
}
|
|
1623
1619
|
catch (err) {
|
|
1624
|
-
this.writeFail(['Unable to parse URL', uri], err, 1024
|
|
1620
|
+
this.writeFail(['Unable to parse URL', uri], err, 1024);
|
|
1625
1621
|
return { pathname: '', localUri: '' };
|
|
1626
1622
|
}
|
|
1627
1623
|
}
|
|
@@ -1645,7 +1641,7 @@ class FileManager extends core_1.Host {
|
|
|
1645
1641
|
}
|
|
1646
1642
|
}
|
|
1647
1643
|
catch (err) {
|
|
1648
|
-
this.writeFail(['Unable to resolve file location', uri], err, 32
|
|
1644
|
+
this.writeFail(['Unable to resolve file location', uri], err, 32);
|
|
1649
1645
|
return { pathname: '', localUri: '' };
|
|
1650
1646
|
}
|
|
1651
1647
|
}
|
|
@@ -1654,18 +1650,18 @@ class FileManager extends core_1.Host {
|
|
|
1654
1650
|
let type;
|
|
1655
1651
|
if (url) {
|
|
1656
1652
|
if (url.protocol.startsWith('http')) {
|
|
1657
|
-
type = 1
|
|
1653
|
+
type = 1;
|
|
1658
1654
|
}
|
|
1659
1655
|
else if (file.socketPath && url.protocol === 'file:') {
|
|
1660
|
-
type = 2
|
|
1656
|
+
type = 2;
|
|
1661
1657
|
}
|
|
1662
1658
|
}
|
|
1663
1659
|
if (!type && uri) {
|
|
1664
1660
|
if (core_1.Host.isFile(uri, 'torrent')) {
|
|
1665
|
-
type = 4
|
|
1661
|
+
type = 4;
|
|
1666
1662
|
}
|
|
1667
1663
|
else if (core_1.Host.isFile(uri, 's/ftp')) {
|
|
1668
|
-
type = 3
|
|
1664
|
+
type = 3;
|
|
1669
1665
|
}
|
|
1670
1666
|
}
|
|
1671
1667
|
file.fetchType = type;
|
|
@@ -1716,7 +1712,7 @@ class FileManager extends core_1.Host {
|
|
|
1716
1712
|
sourceUTF8 = fs.readFileSync(uri, file.encoding);
|
|
1717
1713
|
}
|
|
1718
1714
|
catch (err) {
|
|
1719
|
-
this.writeFail(["Unable to read file"
|
|
1715
|
+
this.writeFail(["Unable to read file", path.basename(uri)], err, 32);
|
|
1720
1716
|
}
|
|
1721
1717
|
}
|
|
1722
1718
|
if (sourceUTF8?.[0] === '\uFEFF' && file.encoding !== 'utf16le') {
|
|
@@ -1736,7 +1732,7 @@ class FileManager extends core_1.Host {
|
|
|
1736
1732
|
return fs.readFileSync(uri);
|
|
1737
1733
|
}
|
|
1738
1734
|
catch (err) {
|
|
1739
|
-
this.writeFail(["Unable to read file"
|
|
1735
|
+
this.writeFail(["Unable to read file", path.basename(uri)], err, 32);
|
|
1740
1736
|
}
|
|
1741
1737
|
}
|
|
1742
1738
|
return file.base64 ? Buffer.from(file.base64, 'base64') : null;
|
|
@@ -1838,7 +1834,7 @@ class FileManager extends core_1.Host {
|
|
|
1838
1834
|
return file.buffer = buffer;
|
|
1839
1835
|
}
|
|
1840
1836
|
catch (err) {
|
|
1841
|
-
this.writeFail(["Unable to write file"
|
|
1837
|
+
this.writeFail(["Unable to write file", path.basename(localUri)], err, 8192);
|
|
1842
1838
|
}
|
|
1843
1839
|
}
|
|
1844
1840
|
return null;
|
|
@@ -1879,7 +1875,7 @@ class FileManager extends core_1.Host {
|
|
|
1879
1875
|
fs.copyFileSync(localUri, output);
|
|
1880
1876
|
}
|
|
1881
1877
|
catch (err) {
|
|
1882
|
-
this.writeFail(["Unable to copy file"
|
|
1878
|
+
this.writeFail(["Unable to copy file", path.basename(localUri)], err, 32);
|
|
1883
1879
|
return;
|
|
1884
1880
|
}
|
|
1885
1881
|
}
|
|
@@ -1909,7 +1905,7 @@ class FileManager extends core_1.Host {
|
|
|
1909
1905
|
}
|
|
1910
1906
|
}
|
|
1911
1907
|
catch (err) {
|
|
1912
|
-
this.writeFail(["Unable to read buffer"
|
|
1908
|
+
this.writeFail(["Unable to read buffer", path.basename(localUri)], err, 32);
|
|
1913
1909
|
}
|
|
1914
1910
|
if (rename) {
|
|
1915
1911
|
if (!ext) {
|
|
@@ -1926,7 +1922,7 @@ class FileManager extends core_1.Host {
|
|
|
1926
1922
|
}
|
|
1927
1923
|
}
|
|
1928
1924
|
catch (err) {
|
|
1929
|
-
this.writeFail(["Unable to rename file"
|
|
1925
|
+
this.writeFail(["Unable to rename file", path.basename(output)], err, 32);
|
|
1930
1926
|
}
|
|
1931
1927
|
}
|
|
1932
1928
|
}
|
|
@@ -1936,7 +1932,7 @@ class FileManager extends core_1.Host {
|
|
|
1936
1932
|
}
|
|
1937
1933
|
return mimeType;
|
|
1938
1934
|
}
|
|
1939
|
-
compressFile(file, overwrite = true) {
|
|
1935
|
+
async compressFile(file, overwrite = true) {
|
|
1940
1936
|
const { localUri, compress } = file;
|
|
1941
1937
|
const instance = this.Compress;
|
|
1942
1938
|
if (instance && compress && localUri && (this.has(localUri) || (0, types_1.existsFlag)(file.flags))) {
|
|
@@ -1968,7 +1964,7 @@ class FileManager extends core_1.Host {
|
|
|
1968
1964
|
config.timeout = this[kProcessTimeout].compress ?? PROCESS_TIMEOUT.compress;
|
|
1969
1965
|
tasks.push(instance.tryFile(file.buffer || localUri, output, config, (err, result) => {
|
|
1970
1966
|
if (err) {
|
|
1971
|
-
this.writeFail(["Unable to compress file"
|
|
1967
|
+
this.writeFail(["Unable to compress file", path.basename(localUri)], err, { type: 8, startTime: config.startTime });
|
|
1972
1968
|
}
|
|
1973
1969
|
else if ((0, types_1.isString)(result)) {
|
|
1974
1970
|
if (condition?.includes('%') && (0, lib_v4_1.getSize)(result) >= (0, lib_v4_1.getSize)(localUri)) {
|
|
@@ -1982,7 +1978,7 @@ class FileManager extends core_1.Host {
|
|
|
1982
1978
|
}
|
|
1983
1979
|
}
|
|
1984
1980
|
catch (err) {
|
|
1985
|
-
this.writeFail(["Unable to read file"
|
|
1981
|
+
this.writeFail(["Unable to read file", path.basename(output)], err, 32);
|
|
1986
1982
|
}
|
|
1987
1983
|
}
|
|
1988
1984
|
}
|
|
@@ -2002,7 +1998,7 @@ class FileManager extends core_1.Host {
|
|
|
2002
1998
|
file.mimeType = mimeType;
|
|
2003
1999
|
data.mimeType = mimeType;
|
|
2004
2000
|
}
|
|
2005
|
-
const errorAsset = (instance, err, type = 4
|
|
2001
|
+
const errorAsset = (instance, err, type = 4) => rejectModule.call(instance, err, type, path.basename(localUri));
|
|
2006
2002
|
if (file.tasks) {
|
|
2007
2003
|
const taskName = [];
|
|
2008
2004
|
for (const { task, handler: moduleName, preceding } of file.tasks) {
|
|
@@ -2051,7 +2047,7 @@ class FileManager extends core_1.Host {
|
|
|
2051
2047
|
.then(() => this.closeThread(instance, data))
|
|
2052
2048
|
.catch(err => {
|
|
2053
2049
|
this.closeThread(instance, data);
|
|
2054
|
-
errorAsset(instance, err, 2048
|
|
2050
|
+
errorAsset(instance, err, 2048);
|
|
2055
2051
|
});
|
|
2056
2052
|
}
|
|
2057
2053
|
}
|
|
@@ -2061,7 +2057,7 @@ class FileManager extends core_1.Host {
|
|
|
2061
2057
|
}
|
|
2062
2058
|
}
|
|
2063
2059
|
catch (err) {
|
|
2064
|
-
errorAsset(instance, err, 2048
|
|
2060
|
+
errorAsset(instance, err, 2048);
|
|
2065
2061
|
}
|
|
2066
2062
|
}
|
|
2067
2063
|
}
|
|
@@ -2141,7 +2137,7 @@ class FileManager extends core_1.Host {
|
|
|
2141
2137
|
task();
|
|
2142
2138
|
}
|
|
2143
2139
|
catch (err) {
|
|
2144
|
-
this.writeFail(["Unable to perform task"
|
|
2140
|
+
this.writeFail(["Unable to perform task", path.basename(this.getLocalUri(data))], err);
|
|
2145
2141
|
}
|
|
2146
2142
|
this.removeAsyncTask();
|
|
2147
2143
|
});
|
|
@@ -2211,14 +2207,14 @@ class FileManager extends core_1.Host {
|
|
|
2211
2207
|
getDownload(type = 0) {
|
|
2212
2208
|
return this[kDownloadStats][type];
|
|
2213
2209
|
}
|
|
2214
|
-
fetchObject(uri, options) {
|
|
2210
|
+
async fetchObject(uri, options) {
|
|
2215
2211
|
if (!(0, types_1.isObject)(options)) {
|
|
2216
2212
|
options = { format: options };
|
|
2217
2213
|
}
|
|
2218
2214
|
options.format || (options.format = 'json');
|
|
2219
|
-
return this.
|
|
2215
|
+
return this.Request.get(uri, options).then(data => typeof data === 'object' ? data : null);
|
|
2220
2216
|
}
|
|
2221
|
-
fetchBuffer(uri, options) {
|
|
2217
|
+
async fetchBuffer(uri, options) {
|
|
2222
2218
|
if (options) {
|
|
2223
2219
|
options.format = undefined;
|
|
2224
2220
|
}
|
|
@@ -2236,14 +2232,14 @@ class FileManager extends core_1.Host {
|
|
|
2236
2232
|
return buffer;
|
|
2237
2233
|
});
|
|
2238
2234
|
}
|
|
2239
|
-
fetchFiles(uri, options) {
|
|
2235
|
+
async fetchFiles(uri, options) {
|
|
2240
2236
|
if (!(0, types_1.isObject)(options)) {
|
|
2241
2237
|
options = { pathname: options };
|
|
2242
2238
|
}
|
|
2243
2239
|
options.pathname || (options.pathname = this.baseDirectory);
|
|
2244
2240
|
return this.Request.aria2c(uri, options);
|
|
2245
2241
|
}
|
|
2246
|
-
start(emptyDir) {
|
|
2242
|
+
async start(emptyDir) {
|
|
2247
2243
|
const listener = (resolve) => {
|
|
2248
2244
|
const callback = (files, errors, status) => {
|
|
2249
2245
|
if (!this.restarting) {
|
|
@@ -2272,19 +2268,19 @@ class FileManager extends core_1.Host {
|
|
|
2272
2268
|
});
|
|
2273
2269
|
}
|
|
2274
2270
|
switch (this.finalizeState) {
|
|
2275
|
-
case 0
|
|
2271
|
+
case 0:
|
|
2276
2272
|
if (this.delayed === 0 && !this.cleared) {
|
|
2277
2273
|
break;
|
|
2278
2274
|
}
|
|
2279
|
-
case 1
|
|
2280
|
-
case 3
|
|
2281
|
-
case 5
|
|
2282
|
-
case 4
|
|
2275
|
+
case 1:
|
|
2276
|
+
case 3:
|
|
2277
|
+
case 5:
|
|
2278
|
+
case 4:
|
|
2283
2279
|
if (this._pendingResult) {
|
|
2284
2280
|
return this._pendingResult;
|
|
2285
2281
|
}
|
|
2286
|
-
this.finalizeState = 0
|
|
2287
|
-
case 2
|
|
2282
|
+
this.finalizeState = 0;
|
|
2283
|
+
case 2:
|
|
2288
2284
|
resetAssets.call(this);
|
|
2289
2285
|
break;
|
|
2290
2286
|
}
|
|
@@ -2304,14 +2300,14 @@ class FileManager extends core_1.Host {
|
|
|
2304
2300
|
abortedHost.call(this);
|
|
2305
2301
|
return;
|
|
2306
2302
|
}
|
|
2307
|
-
if (this.finalizeState === 5
|
|
2303
|
+
if (this.finalizeState === 5) {
|
|
2308
2304
|
this.restarting = false;
|
|
2309
2305
|
}
|
|
2310
2306
|
else if (this._pendingResult) {
|
|
2311
2307
|
return;
|
|
2312
2308
|
}
|
|
2313
2309
|
if (!this.canWrite(this.baseDirectory, { ownPermissionOnly: true })) {
|
|
2314
|
-
this.writeFail("Unsupported access"
|
|
2310
|
+
this.writeFail("Unsupported access", new Error(this.baseDirectory), 8192);
|
|
2315
2311
|
this.cleared = true;
|
|
2316
2312
|
if (this.queued) {
|
|
2317
2313
|
this.joinQueue({ reject: true });
|
|
@@ -2319,15 +2315,15 @@ class FileManager extends core_1.Host {
|
|
|
2319
2315
|
return;
|
|
2320
2316
|
}
|
|
2321
2317
|
switch (this.finalizeState) {
|
|
2322
|
-
case 0
|
|
2318
|
+
case 0:
|
|
2323
2319
|
if (this.delayed === 0 && !this.cleared) {
|
|
2324
2320
|
break;
|
|
2325
2321
|
}
|
|
2326
|
-
case 1
|
|
2327
|
-
case 3
|
|
2328
|
-
case 4
|
|
2322
|
+
case 1:
|
|
2323
|
+
case 3:
|
|
2324
|
+
case 4:
|
|
2329
2325
|
return;
|
|
2330
|
-
case 2
|
|
2326
|
+
case 2:
|
|
2331
2327
|
resetAssets.call(this);
|
|
2332
2328
|
break;
|
|
2333
2329
|
}
|
|
@@ -2338,7 +2334,7 @@ class FileManager extends core_1.Host {
|
|
|
2338
2334
|
args[i] = arguments[i];
|
|
2339
2335
|
}
|
|
2340
2336
|
if (this.joinQueue({ args })) {
|
|
2341
|
-
this.finalizeState = 4
|
|
2337
|
+
this.finalizeState = 4;
|
|
2342
2338
|
return;
|
|
2343
2339
|
}
|
|
2344
2340
|
}
|
|
@@ -2348,7 +2344,7 @@ class FileManager extends core_1.Host {
|
|
|
2348
2344
|
this.clearProcessTimeout();
|
|
2349
2345
|
this[KTimerMain] = setInterval(() => {
|
|
2350
2346
|
const { processing, processTimeout, finalizeState } = this;
|
|
2351
|
-
if (finalizeState === 4
|
|
2347
|
+
if (finalizeState === 4) {
|
|
2352
2348
|
return;
|
|
2353
2349
|
}
|
|
2354
2350
|
const currentTime = Date.now();
|
|
@@ -2381,7 +2377,7 @@ class FileManager extends core_1.Host {
|
|
|
2381
2377
|
this.deleteFile(localUri, { id: file.id, emptyDir: true, all: true });
|
|
2382
2378
|
}
|
|
2383
2379
|
}
|
|
2384
|
-
(moduleName && this.find(moduleName) || this).formatFail(16384
|
|
2380
|
+
(moduleName && this.find(moduleName) || this).formatFail(16384, "FAIL!", ["Unable to process file", moduleName || 'main'], (0, types_1.errorValue)(expired ? "Timeout was exceeded" : "Aborted", localUri), { queue: false, startTime: data.startTime });
|
|
2385
2381
|
processing.splice(i--, 1);
|
|
2386
2382
|
aborted = true;
|
|
2387
2383
|
}
|
|
@@ -2467,11 +2463,11 @@ class FileManager extends core_1.Host {
|
|
|
2467
2463
|
if (bundleIndex > 0) {
|
|
2468
2464
|
items[bundleIndex - 1] = file;
|
|
2469
2465
|
let url, parent;
|
|
2470
|
-
if (file.fetchType === 1
|
|
2466
|
+
if (file.fetchType === 1 && (cacheToDisk.has(url = file.url) || cacheToMemory.has(url)) && (parent = assets.find(item => item.bundleIndex === 0 && item.bundleId === bundleId))) {
|
|
2471
2467
|
(parent.bundleQueue || (parent.bundleQueue = [])).push(new Promise(resolve => {
|
|
2472
2468
|
this.Request.open(url, { method: 'HEAD', httpVersion: 1 })
|
|
2473
2469
|
.on('response', res => {
|
|
2474
|
-
if (res.statusCode < 300
|
|
2470
|
+
if (res.statusCode < 300) {
|
|
2475
2471
|
applyHeaders(file, res.headers);
|
|
2476
2472
|
}
|
|
2477
2473
|
resolve(file);
|
|
@@ -2535,7 +2531,7 @@ class FileManager extends core_1.Host {
|
|
|
2535
2531
|
}
|
|
2536
2532
|
catch (err) {
|
|
2537
2533
|
items.forEach(queue => queue.invalid = true);
|
|
2538
|
-
this.writeFail([buffer ? "Unable to write buffer"
|
|
2534
|
+
this.writeFail([buffer ? "Unable to write buffer" : "Unable to copy file", path.basename(file.localUri)], err, 32);
|
|
2539
2535
|
}
|
|
2540
2536
|
}
|
|
2541
2537
|
};
|
|
@@ -2585,7 +2581,7 @@ class FileManager extends core_1.Host {
|
|
|
2585
2581
|
checkEtag = false;
|
|
2586
2582
|
}
|
|
2587
2583
|
else if (uri) {
|
|
2588
|
-
if (type === 1
|
|
2584
|
+
if (type === 1 || type === 2) {
|
|
2589
2585
|
const url = queue.url;
|
|
2590
2586
|
const options = {
|
|
2591
2587
|
url,
|
|
@@ -2593,7 +2589,7 @@ class FileManager extends core_1.Host {
|
|
|
2593
2589
|
statusMessage: uri + ` (${queue.bundleIndex})`
|
|
2594
2590
|
};
|
|
2595
2591
|
let etag, pipeTo;
|
|
2596
|
-
if (type === 2
|
|
2592
|
+
if (type === 2) {
|
|
2597
2593
|
options.socketPath = queue.socketPath;
|
|
2598
2594
|
options.httpVersion = 1;
|
|
2599
2595
|
}
|
|
@@ -2679,7 +2675,7 @@ class FileManager extends core_1.Host {
|
|
|
2679
2675
|
const pathname = this.getTempDir({ uuidDir: true });
|
|
2680
2676
|
if (!pathname || !mimeType) {
|
|
2681
2677
|
queue.invalid = true;
|
|
2682
|
-
tasks.push(Promise.reject(!pathname ? new Error("Unable to create temp directory"
|
|
2678
|
+
tasks.push(Promise.reject(!pathname ? new Error("Unable to create temp directory") : (0, types_1.errorValue)("MIME not found", uri)));
|
|
2683
2679
|
break;
|
|
2684
2680
|
}
|
|
2685
2681
|
tasks.push(this.fetchFiles(queue.url || uri, { pathname, binOpts: queue.binOpts || file.binOpts })
|
|
@@ -2717,7 +2713,7 @@ class FileManager extends core_1.Host {
|
|
|
2717
2713
|
success = await Promise.all(tasks)
|
|
2718
2714
|
.then(() => true)
|
|
2719
2715
|
.catch(err => {
|
|
2720
|
-
this.writeFail(["Unable to download file"
|
|
2716
|
+
this.writeFail(["Unable to download file", 'bundle: ' + path.basename(localUri)], err, 1024);
|
|
2721
2717
|
return false;
|
|
2722
2718
|
});
|
|
2723
2719
|
}
|
|
@@ -2783,10 +2779,10 @@ class FileManager extends core_1.Host {
|
|
|
2783
2779
|
if (!preceding) {
|
|
2784
2780
|
this.completeAsyncTask();
|
|
2785
2781
|
}
|
|
2786
|
-
this.writeFail(["Unable to download file"
|
|
2782
|
+
this.writeFail(["Unable to download file", uri], err, err instanceof Error && err.message.startsWith("Timeout was exceeded") ? 16384 : 1024);
|
|
2787
2783
|
};
|
|
2788
2784
|
const errorPermission = (file) => {
|
|
2789
|
-
this.writeFail(["Unable to read file"
|
|
2785
|
+
this.writeFail(["Unable to read file", file.uri], (0, types_1.errorValue)('Operation not permitted', file.uri || "Unknown"), 8192);
|
|
2790
2786
|
file.invalid = true;
|
|
2791
2787
|
};
|
|
2792
2788
|
const createFolder = (file, pathname) => {
|
|
@@ -2799,7 +2795,7 @@ class FileManager extends core_1.Host {
|
|
|
2799
2795
|
}
|
|
2800
2796
|
else {
|
|
2801
2797
|
file.invalid = true;
|
|
2802
|
-
this.writeFail("Unable to create directory"
|
|
2798
|
+
this.writeFail("Unable to create directory", (0, types_1.errorValue)('Path not found', pathname));
|
|
2803
2799
|
return false;
|
|
2804
2800
|
}
|
|
2805
2801
|
}
|
|
@@ -2807,7 +2803,7 @@ class FileManager extends core_1.Host {
|
|
|
2807
2803
|
};
|
|
2808
2804
|
const fileReceived = (item, localUri, err, fetched, binary) => {
|
|
2809
2805
|
if (item.checksum && !err && !checkHash(item.buffer || localUri, !!item.buffer, item.checksum)) {
|
|
2810
|
-
err = (0, types_1.errorValue)("Checksum did not match"
|
|
2806
|
+
err = (0, types_1.errorValue)("Checksum did not match", item.uri);
|
|
2811
2807
|
this.filesToRemove.add(localUri);
|
|
2812
2808
|
}
|
|
2813
2809
|
if (err) {
|
|
@@ -2883,7 +2879,7 @@ class FileManager extends core_1.Host {
|
|
|
2883
2879
|
}
|
|
2884
2880
|
return false;
|
|
2885
2881
|
};
|
|
2886
|
-
if ((!etag || item.fetchType === 1
|
|
2882
|
+
if ((!etag || item.fetchType === 1 && ((0, types_1.isEmpty)(bundleId) || bundleIndex <= 0)) && (!watch || !item.watch || setBuffer(item))) {
|
|
2887
2883
|
let childBundle, childDownload;
|
|
2888
2884
|
if (!(0, types_1.isEmpty)(bundleId) && bundleIndex > 0) {
|
|
2889
2885
|
const target = assets.find(parent => parent.bundleId === bundleId && parent.bundleIndex === 0);
|
|
@@ -2919,8 +2915,8 @@ class FileManager extends core_1.Host {
|
|
|
2919
2915
|
setBuffer(item);
|
|
2920
2916
|
}
|
|
2921
2917
|
if (core_1.Host.isPath(localUri) && (!item.checksumOutput || checkHash(localUri, false, item.checksumOutput))) {
|
|
2922
|
-
item.flags |= 128
|
|
2923
|
-
if (!etag || item.fetchType !== 1
|
|
2918
|
+
item.flags |= 128;
|
|
2919
|
+
if (!etag || item.fetchType !== 1) {
|
|
2924
2920
|
if (!(0, types_1.isEmpty)(bundleId) && bundleIndex === 0) {
|
|
2925
2921
|
assets.filter(child => child.bundleId === bundleId && child.bundleIndex > 0).forEach(child => {
|
|
2926
2922
|
setBuffer(child);
|
|
@@ -3014,10 +3010,10 @@ class FileManager extends core_1.Host {
|
|
|
3014
3010
|
continue;
|
|
3015
3011
|
}
|
|
3016
3012
|
const checkDest = (src) => staging || !(0, lib_v4_1.hasSameStat)(src, localUri);
|
|
3017
|
-
const type = item.fetchType || 0
|
|
3013
|
+
const type = item.fetchType || 0;
|
|
3018
3014
|
const bundleMain = !(0, types_1.isEmpty)(item.bundleId) && item.bundleIndex === 0;
|
|
3019
|
-
const isHttp = type === 1
|
|
3020
|
-
if (isHttp || type === 2
|
|
3015
|
+
const isHttp = type === 1;
|
|
3016
|
+
if (isHttp || type === 2) {
|
|
3021
3017
|
let checkEtag;
|
|
3022
3018
|
if ((0, types_1.isEmpty)(item.bundleId) && bundling[uri]) {
|
|
3023
3019
|
bundling[uri].push(item);
|
|
@@ -3046,7 +3042,7 @@ class FileManager extends core_1.Host {
|
|
|
3046
3042
|
const closeResponse = () => client?.destroy();
|
|
3047
3043
|
const downloadUri = (request, etagDir) => {
|
|
3048
3044
|
if (checkEtag) {
|
|
3049
|
-
item.flags &= ~128
|
|
3045
|
+
item.flags &= ~128;
|
|
3050
3046
|
}
|
|
3051
3047
|
closeResponse();
|
|
3052
3048
|
const location = request.url.toString();
|
|
@@ -3063,6 +3059,7 @@ class FileManager extends core_1.Host {
|
|
|
3063
3059
|
}
|
|
3064
3060
|
else {
|
|
3065
3061
|
request.socketPath = item.socketPath;
|
|
3062
|
+
request.method = undefined;
|
|
3066
3063
|
request.httpVersion = 1;
|
|
3067
3064
|
}
|
|
3068
3065
|
this.fetchBuffer(request.url, request)
|
|
@@ -3097,7 +3094,7 @@ class FileManager extends core_1.Host {
|
|
|
3097
3094
|
(client = request.open(href, target))
|
|
3098
3095
|
.on('response', res => {
|
|
3099
3096
|
const statusCode = res.statusCode;
|
|
3100
|
-
if (statusCode < 300
|
|
3097
|
+
if (statusCode < 300) {
|
|
3101
3098
|
const etag = applyHeaders(item, res.headers, false, mainEtag);
|
|
3102
3099
|
let tempDir, etagDir;
|
|
3103
3100
|
if (etag) {
|
|
@@ -3169,7 +3166,7 @@ class FileManager extends core_1.Host {
|
|
|
3169
3166
|
fs.writeFileSync(localUri, buffer);
|
|
3170
3167
|
this.addDownload(Buffer.byteLength(buffer, encoding), types_1.DOWNLOAD_TYPE.CACHE);
|
|
3171
3168
|
if (checkEtag) {
|
|
3172
|
-
item.flags &= ~128
|
|
3169
|
+
item.flags &= ~128;
|
|
3173
3170
|
}
|
|
3174
3171
|
fileReceived(item, localUri, null, true);
|
|
3175
3172
|
closeResponse();
|
|
@@ -3185,7 +3182,7 @@ class FileManager extends core_1.Host {
|
|
|
3185
3182
|
}
|
|
3186
3183
|
downloadUri(target, etagDir);
|
|
3187
3184
|
}
|
|
3188
|
-
else if (statusCode < 400
|
|
3185
|
+
else if (statusCode < 400) {
|
|
3189
3186
|
closeResponse();
|
|
3190
3187
|
const location = res.headers.location;
|
|
3191
3188
|
if (location && ++redirects <= HTTP_CLIENT.redirectLimit) {
|
|
@@ -3231,7 +3228,7 @@ class FileManager extends core_1.Host {
|
|
|
3231
3228
|
}
|
|
3232
3229
|
else if (type) {
|
|
3233
3230
|
if (bundleMain && !item.mimeType) {
|
|
3234
|
-
errorRequest(item, (0, types_1.errorValue)("MIME not found"
|
|
3231
|
+
errorRequest(item, (0, types_1.errorValue)("MIME not found", uri), true);
|
|
3235
3232
|
}
|
|
3236
3233
|
else if (!checkQueue(item, localUri, pathname, false)) {
|
|
3237
3234
|
if (downloading[uri]) {
|
|
@@ -3269,7 +3266,7 @@ class FileManager extends core_1.Host {
|
|
|
3269
3266
|
found = true;
|
|
3270
3267
|
}
|
|
3271
3268
|
catch (err) {
|
|
3272
|
-
this.writeFail(["Unable to rename file"
|
|
3269
|
+
this.writeFail(["Unable to rename file", item.filename], err, 32);
|
|
3273
3270
|
}
|
|
3274
3271
|
}
|
|
3275
3272
|
else {
|
|
@@ -3351,7 +3348,7 @@ class FileManager extends core_1.Host {
|
|
|
3351
3348
|
item.buffer = result;
|
|
3352
3349
|
}
|
|
3353
3350
|
})
|
|
3354
|
-
.catch(err => this.writeFail(["Unable to compress file"
|
|
3351
|
+
.catch(err => this.writeFail(["Unable to compress file", path.basename(file)], err, { type: 8, startTime: options.startTime })));
|
|
3355
3352
|
}
|
|
3356
3353
|
}
|
|
3357
3354
|
}
|
|
@@ -3362,7 +3359,7 @@ class FileManager extends core_1.Host {
|
|
|
3362
3359
|
async finalizeDocument() {
|
|
3363
3360
|
for (const { instance, constructor } of this.Document) {
|
|
3364
3361
|
if (constructor.finalize && instance.assets.length) {
|
|
3365
|
-
await constructor.finalize.call(this, instance).catch(err => rejectModule.call(instance, err, 4
|
|
3362
|
+
await constructor.finalize.call(this, instance).catch(err => rejectModule.call(instance, err, 4));
|
|
3366
3363
|
if (this.aborted) {
|
|
3367
3364
|
return;
|
|
3368
3365
|
}
|
|
@@ -3374,7 +3371,7 @@ class FileManager extends core_1.Host {
|
|
|
3374
3371
|
for (const { instance, constructor } of this.Task) {
|
|
3375
3372
|
const items = assets.filter(item => item.tasks.find(data => data.handler === instance.moduleName));
|
|
3376
3373
|
if (items.length) {
|
|
3377
|
-
await (constructor.using || constructor.finalize).call(this, instance, items).catch(err => rejectModule.call(instance, err, 4
|
|
3374
|
+
await (constructor.using || constructor.finalize).call(this, instance, items).catch(err => rejectModule.call(instance, err, 4));
|
|
3378
3375
|
if (this.aborted) {
|
|
3379
3376
|
return;
|
|
3380
3377
|
}
|
|
@@ -3382,9 +3379,9 @@ class FileManager extends core_1.Host {
|
|
|
3382
3379
|
}
|
|
3383
3380
|
}
|
|
3384
3381
|
}
|
|
3385
|
-
finalizeCloud() {
|
|
3382
|
+
async finalizeCloud() {
|
|
3386
3383
|
const cloud = this.Cloud;
|
|
3387
|
-
return cloud ? cloud_1.default.finalize.call(this, cloud).catch(err => rejectModule.call(cloud, err, 64
|
|
3384
|
+
return cloud ? cloud_1.default.finalize.call(this, cloud).catch(err => rejectModule.call(cloud, err, 64)) : Promise.resolve();
|
|
3388
3385
|
}
|
|
3389
3386
|
async finalizeCleanup() {
|
|
3390
3387
|
if (this.emptyDir.size) {
|
|
@@ -3398,7 +3395,7 @@ class FileManager extends core_1.Host {
|
|
|
3398
3395
|
}
|
|
3399
3396
|
for (const { instance, constructor } of this.Document) {
|
|
3400
3397
|
if (constructor.cleanup && instance.assets.length) {
|
|
3401
|
-
await constructor.cleanup.call(this, instance).catch(err => rejectModule.call(instance, err, 4
|
|
3398
|
+
await constructor.cleanup.call(this, instance).catch(err => rejectModule.call(instance, err, 4));
|
|
3402
3399
|
}
|
|
3403
3400
|
}
|
|
3404
3401
|
}
|
|
@@ -3436,11 +3433,11 @@ class FileManager extends core_1.Host {
|
|
|
3436
3433
|
}
|
|
3437
3434
|
}
|
|
3438
3435
|
removeFiles();
|
|
3439
|
-
await this.finalizeCompress(this.assets.filter(item => item.compress && !ignoreAsset(item))).catch(err => rejectModule.call(this, err, 8
|
|
3436
|
+
await this.finalizeCompress(this.assets.filter(item => item.compress && !ignoreAsset(item))).catch(err => rejectModule.call(this, err, 8));
|
|
3440
3437
|
if (this.aborted) {
|
|
3441
3438
|
return Promise.reject((0, types_1.createAbortError)());
|
|
3442
3439
|
}
|
|
3443
|
-
await this.finalizeDocument().catch(err => rejectModule.call(this, err, 4
|
|
3440
|
+
await this.finalizeDocument().catch(err => rejectModule.call(this, err, 4));
|
|
3444
3441
|
if (this.aborted) {
|
|
3445
3442
|
return Promise.reject((0, types_1.createAbortError)());
|
|
3446
3443
|
}
|
|
@@ -3450,12 +3447,12 @@ class FileManager extends core_1.Host {
|
|
|
3450
3447
|
fs.writeFileSync(item.localUri, item.sourceUTF8, item.encoding || (item.encoding = 'utf-8'));
|
|
3451
3448
|
}
|
|
3452
3449
|
catch (err) {
|
|
3453
|
-
this.writeFail(["Unable to write file"
|
|
3450
|
+
this.writeFail(["Unable to write file", path.basename(item.localUri)], err, { type: 32, startTime });
|
|
3454
3451
|
}
|
|
3455
3452
|
}
|
|
3456
3453
|
}
|
|
3457
3454
|
removeFiles();
|
|
3458
|
-
await this.finalizeTask(this.taskAssets.filter(item => item.tasks?.find(data => !data.preceding) && item.localUri && this.has(item.localUri) && !ignoreAsset(item))).catch(err => rejectModule.call(this, err, 4
|
|
3455
|
+
await this.finalizeTask(this.taskAssets.filter(item => item.tasks?.find(data => !data.preceding) && item.localUri && this.has(item.localUri) && !ignoreAsset(item))).catch(err => rejectModule.call(this, err, 4));
|
|
3459
3456
|
if (this.aborted) {
|
|
3460
3457
|
return Promise.reject((0, types_1.createAbortError)());
|
|
3461
3458
|
}
|
|
@@ -3466,12 +3463,12 @@ class FileManager extends core_1.Host {
|
|
|
3466
3463
|
if (!checkHash(localUri, false, item.checksumOutput)) {
|
|
3467
3464
|
item.invalid = true;
|
|
3468
3465
|
filesToRemove.add(localUri);
|
|
3469
|
-
this.writeFail(["Invalid checksum"
|
|
3466
|
+
this.writeFail(["Invalid checksum", path.basename(localUri)], (0, types_1.errorValue)("Checksum did not match", localUri), { type: 32, startTime });
|
|
3470
3467
|
}
|
|
3471
3468
|
}
|
|
3472
3469
|
}
|
|
3473
3470
|
removeFiles();
|
|
3474
|
-
await this.finalizeCloud().catch(err => rejectModule.call(this, err, 64
|
|
3471
|
+
await this.finalizeCloud().catch(err => rejectModule.call(this, err, 64));
|
|
3475
3472
|
if (this.aborted) {
|
|
3476
3473
|
return Promise.reject((0, types_1.createAbortError)());
|
|
3477
3474
|
}
|
|
@@ -3500,22 +3497,22 @@ class FileManager extends core_1.Host {
|
|
|
3500
3497
|
try {
|
|
3501
3498
|
const files = (await FileManager.writeChecksum(baseDirectory, checksum.filename, checksum));
|
|
3502
3499
|
if (sumTime) {
|
|
3503
|
-
this.writeTimeElapsed(checksum.algorithm || "sha256"
|
|
3500
|
+
this.writeTimeElapsed(checksum.algorithm || "sha256", [baseDirectory, files.length + (files.length === 1 ? ' file' : ' files')], sumTime, { ...core_1.Host.LOG_STYLE_WARN });
|
|
3504
3501
|
}
|
|
3505
3502
|
}
|
|
3506
3503
|
catch (err) {
|
|
3507
|
-
this.writeFail(["Unable to read directory"
|
|
3504
|
+
this.writeFail(["Unable to read directory", path.basename(baseDirectory)], err, { type: 32, startTime });
|
|
3508
3505
|
}
|
|
3509
3506
|
}
|
|
3510
3507
|
}
|
|
3511
|
-
await this.finalizeCleanup().catch(err => rejectModule.call(this, err, 1
|
|
3508
|
+
await this.finalizeCleanup().catch(err => rejectModule.call(this, err, 1));
|
|
3512
3509
|
removeFiles();
|
|
3513
3510
|
if (LOG_TIMEELAPSED) {
|
|
3514
3511
|
const [h, d, c] = this[kDownloadStats];
|
|
3515
3512
|
const errorCount = this.errorCount;
|
|
3516
3513
|
const message = [];
|
|
3517
3514
|
if (errorCount) {
|
|
3518
|
-
message.push('ERROR ' + errorCount);
|
|
3515
|
+
message.push('ERROR ' + errorCount);
|
|
3519
3516
|
}
|
|
3520
3517
|
let [size, count] = h;
|
|
3521
3518
|
if (count) {
|
|
@@ -3541,7 +3538,7 @@ class FileManager extends core_1.Host {
|
|
|
3541
3538
|
this.Request.close();
|
|
3542
3539
|
}
|
|
3543
3540
|
set restarting(value) {
|
|
3544
|
-
this.finalizeState = (this[kRestarting] = value) ? 3
|
|
3541
|
+
this.finalizeState = (this[kRestarting] = value) ? 3 : 0;
|
|
3545
3542
|
}
|
|
3546
3543
|
get restarting() {
|
|
3547
3544
|
return this[kRestarting];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/file-manager",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "FileManager constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/e-mc.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/e-mc.git",
|
|
13
13
|
"directory": "src/file-manager"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -17,18 +17,18 @@
|
|
|
17
17
|
"squared-functions"
|
|
18
18
|
],
|
|
19
19
|
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "
|
|
20
|
+
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "0.7.
|
|
24
|
-
"@e-mc/compress": "0.7.
|
|
25
|
-
"@e-mc/core": "0.7.
|
|
26
|
-
"@e-mc/document": "0.7.
|
|
27
|
-
"@e-mc/image": "0.7.
|
|
28
|
-
"@e-mc/request": "0.7.
|
|
29
|
-
"@e-mc/task": "0.7.
|
|
30
|
-
"@e-mc/types": "0.7.
|
|
31
|
-
"@e-mc/watch": "0.7.
|
|
23
|
+
"@e-mc/cloud": "0.7.3",
|
|
24
|
+
"@e-mc/compress": "0.7.3",
|
|
25
|
+
"@e-mc/core": "0.7.3",
|
|
26
|
+
"@e-mc/document": "0.7.3",
|
|
27
|
+
"@e-mc/image": "0.7.3",
|
|
28
|
+
"@e-mc/request": "0.7.3",
|
|
29
|
+
"@e-mc/task": "0.7.3",
|
|
30
|
+
"@e-mc/types": "0.7.3",
|
|
31
|
+
"@e-mc/watch": "0.7.3",
|
|
32
32
|
"picomatch": "^3.0.1"
|
|
33
33
|
}
|
|
34
34
|
}
|