@e-mc/file-manager 0.7.0 → 0.7.2

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.
Files changed (5) hide show
  1. package/LICENSE +10 -10
  2. package/README.md +5 -3
  3. package/index.d.ts +5 -5
  4. package/index.js +177 -168
  5. package/package.json +13 -12
package/LICENSE CHANGED
@@ -1,11 +1,11 @@
1
- Copyright 2023 An Pham
2
-
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
-
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
-
7
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
-
9
- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
-
1
+ Copyright 2023 Wit Studio
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
11
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
- ### @e-mc/file-manager
1
+ # @e-mc/file-manager
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever Mikasa
4
4
 
5
- BSD 3-Clause
5
+ ## LICENSE
6
+
7
+ MIT
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { FileManagerConstructor } from '../types/lib';
2
- import type { ExternalAsset } from '../types/lib/asset';
3
-
4
- declare const FileManager: FileManagerConstructor<ExternalAsset>;
5
-
1
+ import type { FileManagerConstructor } from '../types/lib';
2
+ import type { ExternalAsset } from '../types/lib/asset';
3
+
4
+ declare const FileManager: FileManagerConstructor<ExternalAsset>;
5
+
6
6
  export = FileManager;
package/index.js CHANGED
@@ -1,22 +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
- const lib_v4_1 = require("../module/lib-v4");
8
- const util_1 = require("../request/util");
9
- const asset_1 = require("../document/asset");
10
- const util_2 = require("../document/util");
11
- const types_1 = require("../types");
12
- const core_1 = require("../core");
13
- const request_1 = require("../request");
14
- const document_1 = require("../document");
15
- const task_1 = require("../task");
16
- const image_1 = require("../image");
17
- const watch_1 = require("../watch");
18
- const compress_1 = require("../compress");
19
- const cloud_1 = require("../cloud");
6
+ const pm = require("picomatch");
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");
20
20
  const kBaseDirectory = Symbol('baseDirectory');
21
21
  const kIncremental = Symbol('incremental');
22
22
  const kRestarting = Symbol('restarting');
@@ -36,7 +36,7 @@ const CACHE_ETAG = {};
36
36
  const DISK = {
37
37
  ENABLED: false,
38
38
  EXPIRES: 0,
39
- LIMIT: (0, types_1.formatSize)("1gb" /* CACHE_SIZE.FILE_MANAGER_DISK_LIMIT */),
39
+ LIMIT: (0, types_1.formatSize)("1gb"),
40
40
  INCLUDE: [],
41
41
  EXCLUDE: []
42
42
  };
@@ -46,8 +46,8 @@ const MEMORY = {
46
46
  SIZE: 0,
47
47
  TOTAL: 0,
48
48
  EXPIRES: 0,
49
- LIMIT: (0, types_1.formatSize)("100mb" /* CACHE_SIZE.FILE_MANAGER_MEMORY_LIMIT */),
50
- LIMIT_ALL: (0, types_1.formatSize)("512mb" /* CACHE_SIZE.FILE_MANAGER_MEMORY_LIMIT_ALL */),
49
+ LIMIT: (0, types_1.formatSize)("100mb"),
50
+ LIMIT_ALL: (0, types_1.formatSize)("512mb"),
51
51
  INCLUDE: [],
52
52
  EXCLUDE: [],
53
53
  PURGE: 0.25,
@@ -61,11 +61,11 @@ let RECURSION_LIMIT = 10;
61
61
  let LOG_TIMEELAPSED = true;
62
62
  let LOG_TIMEPROCESS = true;
63
63
  const HTTP_CLIENT = {
64
- timeout: 60000 /* TIME.m */,
65
- connectTimeout: 20 * 1000 /* TIME.S */,
64
+ timeout: 60000,
65
+ connectTimeout: 20 * 1000,
66
66
  redirectLimit: 3,
67
- retryWait: 1000 /* TIME.S */,
68
- retryAfter: 30 * 1000 /* TIME.S */,
67
+ retryWait: 1000,
68
+ retryAfter: 30 * 1000,
69
69
  retryLimit: 10
70
70
  };
71
71
  function applyTimeout(target, options) {
@@ -96,7 +96,7 @@ function withinSizeRange(uri, value, pattern) {
96
96
  return true;
97
97
  }
98
98
  function startMessage() {
99
- this.formatMessage(128 /* LOG_TYPE.TIME_ELAPSED */, 'START', [new Date().toLocaleString(), this.assets.length + ' assets'], this.baseDirectory, { ...core_1.Host.LOG_STYLE_SUCCESS });
99
+ this.formatMessage(128, 'START', [new Date().toLocaleString(), this.assets.length + ' assets'], this.baseDirectory, { ...core_1.Host.LOG_STYLE_SUCCESS });
100
100
  }
101
101
  function clearAssets() {
102
102
  this.assets.forEach(item => {
@@ -116,7 +116,7 @@ function bundleTorrent(files, mimeType, encoding) {
116
116
  output += fs.readFileSync(file, encoding);
117
117
  }
118
118
  catch (err) {
119
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(file)], err, 32 /* LOG_TYPE.FILE */);
119
+ this.writeFail(["Unable to read file", path.basename(file)], err, 32);
120
120
  }
121
121
  }
122
122
  }
@@ -133,13 +133,13 @@ function recurseDir(output, subDirs, options) {
133
133
  .sort((a, b) => {
134
134
  if (sortBy > 0) {
135
135
  if (a.isDirectory() && !b.isDirectory()) {
136
- return sortBy & 1 /* READDIR_SORT.DIRECTORY */ ? -1 : 1;
136
+ return sortBy & 1 ? -1 : 1;
137
137
  }
138
138
  if (!a.isDirectory() && b.isDirectory()) {
139
- return sortBy & 1 /* READDIR_SORT.DIRECTORY */ ? 1 : -1;
139
+ return sortBy & 1 ? 1 : -1;
140
140
  }
141
141
  }
142
- return (a.name < b.name ? -1 : 1) * (2 /* READDIR_SORT.DESCENDING */ & 2 ? -1 : 1);
142
+ return (a.name < b.name ? -1 : 1) * (2 & 2 ? -1 : 1);
143
143
  });
144
144
  for (const item of items) {
145
145
  if (!item.isDirectory()) {
@@ -177,13 +177,24 @@ function checkHash(data, fromBuffer, options) {
177
177
  }
178
178
  return true;
179
179
  }
180
- function filterPaths(values, include, exclude) {
180
+ function validatePaths(values, patterns, include, dot) {
181
+ const items = patterns.map(value => !value.startsWith('*') && /[\\/]/.test(value) ? [core_1.Permission.toPosix(path.resolve(value)), { nocase: PLATFORM_WIN32, dot }] : [value.replace(/\\/g, '/'), { matchBase: true, nocase: PLATFORM_WIN32, dot }]);
182
+ return values.filter(value => {
183
+ for (const [pattern, options] of items) {
184
+ if (pm.isMatch(core_1.Permission.toPosix(value), pattern, options)) {
185
+ return include;
186
+ }
187
+ }
188
+ return !include;
189
+ });
190
+ }
191
+ function filterPaths(values, include, exclude, dot) {
181
192
  if (include) {
182
193
  if ((0, types_1.isString)(include)) {
183
194
  include = [include];
184
195
  }
185
196
  if ((0, types_1.isArray)(include)) {
186
- return values.filter(value => core_1.Permission.match(value, include));
197
+ return validatePaths(values, include, true, dot);
187
198
  }
188
199
  }
189
200
  if (exclude) {
@@ -191,13 +202,13 @@ function filterPaths(values, include, exclude) {
191
202
  exclude = [exclude];
192
203
  }
193
204
  if ((0, types_1.isArray)(exclude)) {
194
- return values.filter(value => !core_1.Permission.match(value, exclude));
205
+ return validatePaths(values, exclude, false, dot);
195
206
  }
196
207
  }
197
208
  return values;
198
209
  }
199
210
  function abortedHost() {
200
- if (this.finalizeState === 6 /* FINALIZE_STATE.ABORTED */) {
211
+ if (this.finalizeState === 6) {
201
212
  this.restarting = false;
202
213
  this.performFinalize(true);
203
214
  return this.done;
@@ -219,7 +230,7 @@ function observeFile(instance) {
219
230
  if (PLATFORM_WIN32) {
220
231
  value = value.toLowerCase();
221
232
  }
222
- if (value[value.length - 1] !== path.sep) {
233
+ if (!value.endsWith(path.sep)) {
223
234
  value += path.sep;
224
235
  }
225
236
  for (const name of this.files) {
@@ -241,7 +252,7 @@ function collectErrors() {
241
252
  const clearModule = (instance) => {
242
253
  const { moduleName, errors } = instance;
243
254
  if (errors.length) {
244
- errors.forEach(value => result.push(`[${moduleName}] ` + (core_1.Host.asString(value) || "Unknown" /* ERR_MESSAGE.UNKNOWN */)));
255
+ errors.forEach(value => result.push(`[${moduleName}] ` + (core_1.Host.asString(value) || "Unknown")));
245
256
  errors.length = 0;
246
257
  }
247
258
  };
@@ -263,12 +274,12 @@ function collectErrors() {
263
274
  return result;
264
275
  }
265
276
  function rejectModule(err, type, hint) {
266
- this.writeFail(["Handled rejection" /* ERR_MESSAGE.HANDLED_REJECTION */, this.moduleName + (hint ? ': ' + hint : '')], err, type);
277
+ this.writeFail(["Handled rejection", this.moduleName + (hint ? ': ' + hint : '')], err, type);
267
278
  }
268
- const checksumFile = (algorithm) => "checksum" /* HASH_OUTPUT.FILENAME */ + '.' + ((0, types_1.isString)(algorithm) ? algorithm.toLowerCase() : "sha256" /* HASH_OUTPUT.ALGORITHM */);
269
- const checksumError = (algorithm) => new Error("Invalid parameters" /* ERR_MESSAGE.PARAMETERS */ + ` (${algorithm || "sha256" /* HASH_OUTPUT.ALGORITHM */})`);
279
+ const checksumFile = (algorithm) => "checksum" + '.' + ((0, types_1.isString)(algorithm) ? algorithm.toLowerCase() : "sha256");
280
+ const checksumError = (algorithm) => new Error("Invalid parameters" + ` (${algorithm || "sha256"})`);
270
281
  const isFunction = (value) => typeof value === 'function';
271
- const ignoreAsset = (item, exists) => item.invalid || (0, types_1.hasBit)(item.flags, 1 /* ASSET_FLAG.IGNORE */ | (!exists ? 128 /* ASSET_FLAG.EXISTS */ : 0));
282
+ const ignoreAsset = (item, exists) => item.invalid || (0, types_1.hasBit)(item.flags, 1 | (!exists ? 128 : 0));
272
283
  class HttpDiskCache {
273
284
  constructor(host, enabled) {
274
285
  this.host = host;
@@ -400,7 +411,7 @@ class HttpDiskCache {
400
411
  }
401
412
  class HttpMemoryCache extends HttpDiskCache {
402
413
  constructor(host, enabled) {
403
- super(host, enabled && core_1.Host.enabled("memory.settings.users" /* KEY_NAME.MEMORY_SETTINGS_USERS */, host.username));
414
+ super(host, enabled && core_1.Host.enabled("memory.settings.users", host.username));
404
415
  this.limit = MEMORY.LIMIT;
405
416
  this.expires = MEMORY.EXPIRES;
406
417
  this.toDisk = [MEMORY.DISK_MIN, MEMORY.DISK_MAX];
@@ -581,8 +592,8 @@ class FileManager extends core_1.Host {
581
592
  SESSION_LIMIT = Math.pow(10, value);
582
593
  }
583
594
  }
584
- LOG_TIMEELAPSED = this.hasLogType(128 /* LOG_TYPE.TIME_ELAPSED */);
585
- LOG_TIMEPROCESS = this.hasLogType(256 /* LOG_TYPE.TIME_PROCESS */);
595
+ LOG_TIMEELAPSED = this.hasLogType(128);
596
+ LOG_TIMEPROCESS = this.hasLogType(256);
586
597
  return true;
587
598
  }
588
599
  return false;
@@ -602,7 +613,7 @@ class FileManager extends core_1.Host {
602
613
  for (const attr in item) {
603
614
  switch (attr) {
604
615
  case 'flags':
605
- item.flags &= ~(128 /* ASSET_FLAG.EXISTS */ | 16 /* ASSET_FLAG.MODIFIED */);
616
+ item.flags &= ~(128 | 16);
606
617
  break;
607
618
  case 'watch':
608
619
  if ((0, types_1.isPlainObject)(item.watch) && item.watch.assets) {
@@ -645,7 +656,7 @@ class FileManager extends core_1.Host {
645
656
  to = joinRoot ? path.join(root, to) : path.resolve(to);
646
657
  recurseDir(result, [root], { ignore: [...ignore, to], sortBy, recursive });
647
658
  const output = [];
648
- for (const pathname of result = filterPaths(result, include, exclude)) {
659
+ for (const pathname of result = filterPaths(result, include, exclude, options.dot)) {
649
660
  if (recursive === 1 && path.basename(pathname) === filename) {
650
661
  continue;
651
662
  }
@@ -672,7 +683,7 @@ class FileManager extends core_1.Host {
672
683
  if (options.throwsEmpty) {
673
684
  throw err;
674
685
  }
675
- this.writeFail(["Unable to read directory" /* ERR_MESSAGE.READ_DIRECTORY */, root], err, 32 /* LOG_TYPE.FILE */);
686
+ this.writeFail(["Unable to read directory", root], err, 32);
676
687
  return null;
677
688
  }
678
689
  return result;
@@ -698,7 +709,7 @@ class FileManager extends core_1.Host {
698
709
  const index = item.indexOf(' ');
699
710
  return [item.substring(0, index), path.join(root, item.substring(index + 1))];
700
711
  });
701
- const checked = include || exclude ? filterPaths(items.map(item => item[1]), include, exclude) : null;
712
+ const checked = include || exclude ? filterPaths(items.map(item => item[1]), include, exclude, options.dot) : null;
702
713
  let valid;
703
714
  for (const [previous, pathname] of items) {
704
715
  if (checked !== null && !checked.includes(pathname) || recursive === 1 && path.basename(pathname) === filename) {
@@ -710,7 +721,7 @@ class FileManager extends core_1.Host {
710
721
  fail.push(pathname);
711
722
  }
712
723
  else if (verbose) {
713
- process.stdout.write("+" /* SUMDIR_STATUS.PASS */ + ' ' + pathname + '\n');
724
+ process.stdout.write("+" + ' ' + pathname + '\n');
714
725
  }
715
726
  valid = true;
716
727
  }
@@ -722,7 +733,7 @@ class FileManager extends core_1.Host {
722
733
  const nested = files.filter(value => path.basename(value) === filename);
723
734
  if (nested.length) {
724
735
  const current = items.map(item => item[1]);
725
- const tasks = nested.map(pathname => this.verifyChecksum(path.dirname(pathname), filename, { ...options, ignore: current, joinRoot: true, verbose: (verbose ? 1 : 0) }));
736
+ const tasks = nested.map(async (pathname) => this.verifyChecksum(path.dirname(pathname), filename, { ...options, ignore: current, joinRoot: true, verbose: (verbose ? 1 : 0) }));
726
737
  await Promise.all(tasks).then(group => {
727
738
  for (const item of group) {
728
739
  if (item) {
@@ -750,7 +761,7 @@ class FileManager extends core_1.Host {
750
761
  if (options.throwsEmpty) {
751
762
  throw err;
752
763
  }
753
- this.writeFail(["Unable to read directory" /* ERR_MESSAGE.READ_DIRECTORY */, root], err, 32 /* LOG_TYPE.FILE */);
764
+ this.writeFail(["Unable to read directory", root], err, 32);
754
765
  return null;
755
766
  }
756
767
  if (parent) {
@@ -764,8 +775,8 @@ class FileManager extends core_1.Host {
764
775
  if (verbose === true) {
765
776
  const max = Math.max(...fail.concat(missing).map(item => item.length));
766
777
  const writeLog = (items, symbol) => items.forEach((value, index) => process.stdout.write(`${symbol} ${value.padEnd(max)} (${(index + 1).toString()})\n`));
767
- writeLog(fail, "-" /* SUMDIR_STATUS.FAIL */);
768
- writeLog(missing, "?" /* SUMDIR_STATUS.MISSING */);
778
+ writeLog(fail, "-");
779
+ writeLog(missing, "?");
769
780
  }
770
781
  return [fail, missing];
771
782
  }
@@ -838,7 +849,7 @@ class FileManager extends core_1.Host {
838
849
  HTTP_CLIENT.connectTimeout = timeout;
839
850
  }
840
851
  if ((retry_wait = (0, util_1.fromSeconds)(retry_wait)) >= 0) {
841
- HTTP_CLIENT.retryWait = Math.min(retry_wait, 600 * 1000 /* TIME.S */);
852
+ HTTP_CLIENT.retryWait = Math.min(retry_wait, 600 * 1000);
842
853
  }
843
854
  if ((retry_after = (0, util_1.fromSeconds)(retry_after)) >= 0) {
844
855
  HTTP_CLIENT.retryAfter = Math.min(retry_after, this.MAX_TIMEOUT);
@@ -852,7 +863,7 @@ class FileManager extends core_1.Host {
852
863
  }
853
864
  constructor(baseDirectory, config, permission, postFinalize) {
854
865
  super(config);
855
- this.finalizeState = 0 /* FINALIZE_STATE.READY */;
866
+ this.finalizeState = 0;
856
867
  this.processTimeout = PROCESS_TIMEOUT.filemanager;
857
868
  this.Document = [];
858
869
  this.Task = [];
@@ -954,7 +965,7 @@ class FileManager extends core_1.Host {
954
965
  request.host = this;
955
966
  this.Request = request;
956
967
  if (this.aborted) {
957
- this.finalizeState = 6 /* FINALIZE_STATE.ABORTED */;
968
+ this.finalizeState = 6;
958
969
  }
959
970
  else {
960
971
  request.init(config).apply({ client: HTTP_CLIENT });
@@ -1064,7 +1075,7 @@ class FileManager extends core_1.Host {
1064
1075
  }
1065
1076
  if (this.restartable && (!recursive || --this[kRecursionLimit] >= 0)) {
1066
1077
  if (this.reset()) {
1067
- this.finalizeState = 5 /* FINALIZE_STATE.RESTARTED */;
1078
+ this.finalizeState = 5;
1068
1079
  FileManager.sanitizeAssets(this.assets, exclusions);
1069
1080
  for (const { instance } of this.Document) {
1070
1081
  instance.restart();
@@ -1112,7 +1123,7 @@ class FileManager extends core_1.Host {
1112
1123
  }
1113
1124
  }
1114
1125
  reset() {
1115
- if (this.finalizeState === 1 /* FINALIZE_STATE.COMMIT */) {
1126
+ if (this.finalizeState === 1) {
1116
1127
  return false;
1117
1128
  }
1118
1129
  super.reset();
@@ -1134,7 +1145,7 @@ class FileManager extends core_1.Host {
1134
1145
  clearAssets.call(this);
1135
1146
  this.cleared = false;
1136
1147
  this[kDelayed] = 0;
1137
- this.finalizeState = 0 /* FINALIZE_STATE.READY */;
1148
+ this.finalizeState = 0;
1138
1149
  return true;
1139
1150
  }
1140
1151
  deleteFile(value, options = {}, callback) {
@@ -1159,11 +1170,11 @@ class FileManager extends core_1.Host {
1159
1170
  }
1160
1171
  resumeThread(options) {
1161
1172
  if (this.aborted || options.aborted) {
1162
- this.finalizeState = 0 /* FINALIZE_STATE.READY */;
1173
+ this.finalizeState = 0;
1163
1174
  this.performFinalize(true);
1164
1175
  return;
1165
1176
  }
1166
- this.finalizeState = 5 /* FINALIZE_STATE.RESTARTED */;
1177
+ this.finalizeState = 5;
1167
1178
  startMessage.call(this);
1168
1179
  this.processAssets(...options.args);
1169
1180
  }
@@ -1199,7 +1210,7 @@ class FileManager extends core_1.Host {
1199
1210
  if (typeof target === 'string') {
1200
1211
  const module = args.shift();
1201
1212
  if ((0, types_1.isObject)(module)) {
1202
- if (target === "@e-mc/cloud" /* PACKAGE_NAME.CLOUD */) {
1213
+ if (target === "@e-mc/cloud") {
1203
1214
  instance = new cloud_1.default(module, database);
1204
1215
  }
1205
1216
  else {
@@ -1209,11 +1220,11 @@ class FileManager extends core_1.Host {
1209
1220
  instance = new Handler(module, database);
1210
1221
  }
1211
1222
  else {
1212
- throw (0, types_1.errorMessage)(this.moduleName, "Not a Cloud constructor" /* ERR_CLOUD.CONSTRUCTOR */, target);
1223
+ throw (0, types_1.errorMessage)(this.moduleName, "Not a Cloud constructor", target);
1213
1224
  }
1214
1225
  }
1215
1226
  catch (err) {
1216
- this.checkPackage(err, target, ["Unable to load handler" /* ERR_MESSAGE.LOAD_HANDLER */, this.moduleName], 64 /* LOG_TYPE.CLOUD */);
1227
+ this.checkPackage(err, target, ["Unable to load handler", this.moduleName], 64);
1217
1228
  }
1218
1229
  }
1219
1230
  }
@@ -1257,17 +1268,20 @@ class FileManager extends core_1.Host {
1257
1268
  manager.install('cloud', this.Cloud.module);
1258
1269
  }
1259
1270
  if (this.Image) {
1260
- for (const handler of this.Image) {
1261
- if ((0, types_1.isPlainObject)(handler)) {
1262
- const image = handler.instance;
1263
- image.reset();
1264
- image.host = manager;
1265
- observeFile.call(manager, image);
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;
1266
1277
  }
1278
+ mimeMap.set(mimeType, constructor);
1267
1279
  }
1268
- manager.Image = this.Image;
1280
+ manager.install('image', mimeMap, ...params);
1281
+ }
1282
+ if (this.Compress) {
1283
+ manager.install('compress', this.Compress.module);
1269
1284
  }
1270
- manager.Compress = this.Compress;
1271
1285
  manager.sessionId = this.sessionId;
1272
1286
  manager.permission = this.permission;
1273
1287
  manager.cacheToDisk = this.cacheToDisk;
@@ -1277,7 +1291,7 @@ class FileManager extends core_1.Host {
1277
1291
  manager.processAssets();
1278
1292
  }
1279
1293
  catch (err) {
1280
- manager.writeFail("Unknown" /* ERR_MESSAGE.UNKNOWN */, err, { startTime: manager.startTime });
1294
+ manager.writeFail("Unknown", err, { startTime: manager.startTime });
1281
1295
  }
1282
1296
  }
1283
1297
  return manager;
@@ -1335,7 +1349,7 @@ class FileManager extends core_1.Host {
1335
1349
  if (value) {
1336
1350
  const isSame = (a, b) => a === b || decodeURIComponent(a) === decodeURIComponent(b);
1337
1351
  const result = (assets || this.assets).filter(item => {
1338
- let { uri, flags } = item;
1352
+ const { uri, flags } = item;
1339
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))) {
1340
1354
  if (origin) {
1341
1355
  if (!item.url) {
@@ -1357,13 +1371,7 @@ class FileManager extends core_1.Host {
1357
1371
  const indexA = uri.indexOf('#');
1358
1372
  const indexB = value.indexOf('#');
1359
1373
  if (indexA !== -1 || indexB !== -1) {
1360
- if (indexA !== -1) {
1361
- uri = uri.substring(0, indexA);
1362
- }
1363
- if (indexB !== -1) {
1364
- value = value.substring(0, indexB);
1365
- }
1366
- return isSame(uri, value);
1374
+ return isSame(indexA !== -1 ? uri.substring(0, indexA) : uri, indexB !== -1 ? value.substring(0, indexB) : value);
1367
1375
  }
1368
1376
  }
1369
1377
  return false;
@@ -1444,7 +1452,7 @@ class FileManager extends core_1.Host {
1444
1452
  }
1445
1453
  }
1446
1454
  catch (err) {
1447
- this.writeFail(["Unable to rename file" /* ERR_MESSAGE.RENAME_FILE */, name], err, 32 /* LOG_TYPE.FILE */);
1455
+ this.writeFail(["Unable to rename file", name], err, 32);
1448
1456
  return false;
1449
1457
  }
1450
1458
  }
@@ -1465,7 +1473,7 @@ class FileManager extends core_1.Host {
1465
1473
  file.pathname = pathname;
1466
1474
  file.filename = filename;
1467
1475
  this.setLocalUri(file, true);
1468
- this.writeFail(["Unable to rename file" /* ERR_MESSAGE.RENAME_FILE */, name], err, 32 /* LOG_TYPE.FILE */);
1476
+ this.writeFail(["Unable to rename file", name], err, 32);
1469
1477
  return false;
1470
1478
  }
1471
1479
  }
@@ -1502,7 +1510,7 @@ class FileManager extends core_1.Host {
1502
1510
  }
1503
1511
  }
1504
1512
  catch (err) {
1505
- this.writeFail(["Unable to rename file" /* ERR_MESSAGE.RENAME_FILE */, path.basename(value)], err, 32 /* LOG_TYPE.FILE */);
1513
+ this.writeFail(["Unable to rename file", path.basename(value)], err, 32);
1506
1514
  return false;
1507
1515
  }
1508
1516
  if (!copy) {
@@ -1530,25 +1538,25 @@ class FileManager extends core_1.Host {
1530
1538
  this.performFinalize();
1531
1539
  }
1532
1540
  if (err) {
1533
- this.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, uri], err, 32 /* LOG_TYPE.FILE */);
1541
+ this.writeFail(["Unknown", uri], err, 32);
1534
1542
  }
1535
1543
  }
1536
1544
  performFinalize(override) {
1537
1545
  const state = this.finalizeState;
1538
- if (state === 0 /* FINALIZE_STATE.READY */ && (this.cleared && this[kDelayed] <= 0 || override) || (this.aborted || state === 3 /* FINALIZE_STATE.RESTART */) && override) {
1546
+ if (state === 0 && (this.cleared && this[kDelayed] <= 0 || override) || (this.aborted || state === 3) && override) {
1539
1547
  this.clearProcessTimeout();
1540
1548
  this[kDelayed] = Infinity;
1541
1549
  const resetState = () => {
1542
- this.finalizeState = 2 /* FINALIZE_STATE.END */;
1550
+ this.finalizeState = 2;
1543
1551
  this._pendingResult = null;
1544
1552
  };
1545
1553
  const aborted = (err) => {
1546
1554
  if (!this.restarting) {
1547
- this.writeFail(["Transaction was not completed" /* ERR_MESSAGE.INCOMPLETE */, this.baseDirectory], err);
1555
+ this.writeFail(["Transaction was not completed", this.baseDirectory], err);
1548
1556
  resetState();
1549
1557
  }
1550
1558
  else {
1551
- this.finalizeState = 4 /* FINALIZE_STATE.QUEUED */;
1559
+ this.finalizeState = 4;
1552
1560
  }
1553
1561
  this.emit('end', [], collectErrors.call(this), this.collectLog());
1554
1562
  if (!this.restarting) {
@@ -1559,16 +1567,16 @@ class FileManager extends core_1.Host {
1559
1567
  aborted((0, types_1.createAbortError)());
1560
1568
  return;
1561
1569
  }
1562
- this.finalizeState = 1 /* FINALIZE_STATE.COMMIT */;
1570
+ this.finalizeState = 1;
1563
1571
  this.finalize()
1564
1572
  .then(() => {
1565
1573
  const errors = collectErrors.call(this);
1566
1574
  const files = Array.from(this.files).sort((a, b) => {
1567
1575
  const sep = path.sep;
1568
- if (a.indexOf(sep) !== -1 && b.indexOf(sep) === -1) {
1576
+ if (a.includes(sep) && !b.includes(sep)) {
1569
1577
  return -1;
1570
1578
  }
1571
- if (a.indexOf(sep) === -1 && b.indexOf(sep) !== -1) {
1579
+ if (!a.includes(sep) && b.includes(sep)) {
1572
1580
  return 1;
1573
1581
  }
1574
1582
  return a < b ? -1 : 1;
@@ -1609,7 +1617,7 @@ class FileManager extends core_1.Host {
1609
1617
  file.uri = file.url.toString();
1610
1618
  }
1611
1619
  catch (err) {
1612
- this.writeFail(['Unable to parse URL', uri], err, 1024 /* LOG_TYPE.HTTP */);
1620
+ this.writeFail(['Unable to parse URL', uri], err, 1024);
1613
1621
  return { pathname: '', localUri: '' };
1614
1622
  }
1615
1623
  }
@@ -1633,7 +1641,7 @@ class FileManager extends core_1.Host {
1633
1641
  }
1634
1642
  }
1635
1643
  catch (err) {
1636
- this.writeFail(['Unable to resolve file location', uri], err, 32 /* LOG_TYPE.FILE */);
1644
+ this.writeFail(['Unable to resolve file location', uri], err, 32);
1637
1645
  return { pathname: '', localUri: '' };
1638
1646
  }
1639
1647
  }
@@ -1642,18 +1650,18 @@ class FileManager extends core_1.Host {
1642
1650
  let type;
1643
1651
  if (url) {
1644
1652
  if (url.protocol.startsWith('http')) {
1645
- type = 1 /* FETCH_TYPE.HTTP */;
1653
+ type = 1;
1646
1654
  }
1647
1655
  else if (file.socketPath && url.protocol === 'file:') {
1648
- type = 2 /* FETCH_TYPE.UNIX_SOCKET */;
1656
+ type = 2;
1649
1657
  }
1650
1658
  }
1651
1659
  if (!type && uri) {
1652
1660
  if (core_1.Host.isFile(uri, 'torrent')) {
1653
- type = 4 /* FETCH_TYPE.TORRENT */;
1661
+ type = 4;
1654
1662
  }
1655
1663
  else if (core_1.Host.isFile(uri, 's/ftp')) {
1656
- type = 3 /* FETCH_TYPE.FTP */;
1664
+ type = 3;
1657
1665
  }
1658
1666
  }
1659
1667
  file.fetchType = type;
@@ -1704,7 +1712,7 @@ class FileManager extends core_1.Host {
1704
1712
  sourceUTF8 = fs.readFileSync(uri, file.encoding);
1705
1713
  }
1706
1714
  catch (err) {
1707
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(uri)], err, 32 /* LOG_TYPE.FILE */);
1715
+ this.writeFail(["Unable to read file", path.basename(uri)], err, 32);
1708
1716
  }
1709
1717
  }
1710
1718
  if (sourceUTF8?.[0] === '\uFEFF' && file.encoding !== 'utf16le') {
@@ -1724,7 +1732,7 @@ class FileManager extends core_1.Host {
1724
1732
  return fs.readFileSync(uri);
1725
1733
  }
1726
1734
  catch (err) {
1727
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(uri)], err, 32 /* LOG_TYPE.FILE */);
1735
+ this.writeFail(["Unable to read file", path.basename(uri)], err, 32);
1728
1736
  }
1729
1737
  }
1730
1738
  return file.base64 ? Buffer.from(file.base64, 'base64') : null;
@@ -1826,7 +1834,7 @@ class FileManager extends core_1.Host {
1826
1834
  return file.buffer = buffer;
1827
1835
  }
1828
1836
  catch (err) {
1829
- this.writeFail(["Unable to write file" /* ERR_MESSAGE.WRITE_FILE */, path.basename(localUri)], err, 8192 /* LOG_TYPE.PERMISSION */);
1837
+ this.writeFail(["Unable to write file", path.basename(localUri)], err, 8192);
1830
1838
  }
1831
1839
  }
1832
1840
  return null;
@@ -1867,7 +1875,7 @@ class FileManager extends core_1.Host {
1867
1875
  fs.copyFileSync(localUri, output);
1868
1876
  }
1869
1877
  catch (err) {
1870
- this.writeFail(["Unable to copy file" /* ERR_MESSAGE.COPY_FILE */, path.basename(localUri)], err, 32 /* LOG_TYPE.FILE */);
1878
+ this.writeFail(["Unable to copy file", path.basename(localUri)], err, 32);
1871
1879
  return;
1872
1880
  }
1873
1881
  }
@@ -1897,7 +1905,7 @@ class FileManager extends core_1.Host {
1897
1905
  }
1898
1906
  }
1899
1907
  catch (err) {
1900
- this.writeFail(["Unable to read buffer" /* ERR_MESSAGE.READ_BUFFER */, path.basename(localUri)], err, 32 /* LOG_TYPE.FILE */);
1908
+ this.writeFail(["Unable to read buffer", path.basename(localUri)], err, 32);
1901
1909
  }
1902
1910
  if (rename) {
1903
1911
  if (!ext) {
@@ -1914,7 +1922,7 @@ class FileManager extends core_1.Host {
1914
1922
  }
1915
1923
  }
1916
1924
  catch (err) {
1917
- this.writeFail(["Unable to rename file" /* ERR_MESSAGE.RENAME_FILE */, path.basename(output)], err, 32 /* LOG_TYPE.FILE */);
1925
+ this.writeFail(["Unable to rename file", path.basename(output)], err, 32);
1918
1926
  }
1919
1927
  }
1920
1928
  }
@@ -1924,7 +1932,7 @@ class FileManager extends core_1.Host {
1924
1932
  }
1925
1933
  return mimeType;
1926
1934
  }
1927
- compressFile(file, overwrite = true) {
1935
+ async compressFile(file, overwrite = true) {
1928
1936
  const { localUri, compress } = file;
1929
1937
  const instance = this.Compress;
1930
1938
  if (instance && compress && localUri && (this.has(localUri) || (0, types_1.existsFlag)(file.flags))) {
@@ -1956,7 +1964,7 @@ class FileManager extends core_1.Host {
1956
1964
  config.timeout = this[kProcessTimeout].compress ?? PROCESS_TIMEOUT.compress;
1957
1965
  tasks.push(instance.tryFile(file.buffer || localUri, output, config, (err, result) => {
1958
1966
  if (err) {
1959
- this.writeFail(["Unable to compress file" /* ERR_MESSAGE.COMPRESS_FILE */, path.basename(localUri)], err, { type: 8 /* LOG_TYPE.COMPRESS */, startTime: config.startTime });
1967
+ this.writeFail(["Unable to compress file", path.basename(localUri)], err, { type: 8, startTime: config.startTime });
1960
1968
  }
1961
1969
  else if ((0, types_1.isString)(result)) {
1962
1970
  if (condition?.includes('%') && (0, lib_v4_1.getSize)(result) >= (0, lib_v4_1.getSize)(localUri)) {
@@ -1970,7 +1978,7 @@ class FileManager extends core_1.Host {
1970
1978
  }
1971
1979
  }
1972
1980
  catch (err) {
1973
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(output)], err, 32 /* LOG_TYPE.FILE */);
1981
+ this.writeFail(["Unable to read file", path.basename(output)], err, 32);
1974
1982
  }
1975
1983
  }
1976
1984
  }
@@ -1990,7 +1998,7 @@ class FileManager extends core_1.Host {
1990
1998
  file.mimeType = mimeType;
1991
1999
  data.mimeType = mimeType;
1992
2000
  }
1993
- const errorAsset = (instance, err, type = 4 /* LOG_TYPE.PROCESS */) => rejectModule.call(instance, err, type, path.basename(localUri));
2001
+ const errorAsset = (instance, err, type = 4) => rejectModule.call(instance, err, type, path.basename(localUri));
1994
2002
  if (file.tasks) {
1995
2003
  const taskName = [];
1996
2004
  for (const { task, handler: moduleName, preceding } of file.tasks) {
@@ -2039,7 +2047,7 @@ class FileManager extends core_1.Host {
2039
2047
  .then(() => this.closeThread(instance, data))
2040
2048
  .catch(err => {
2041
2049
  this.closeThread(instance, data);
2042
- errorAsset(instance, err, 2048 /* LOG_TYPE.IMAGE */);
2050
+ errorAsset(instance, err, 2048);
2043
2051
  });
2044
2052
  }
2045
2053
  }
@@ -2049,7 +2057,7 @@ class FileManager extends core_1.Host {
2049
2057
  }
2050
2058
  }
2051
2059
  catch (err) {
2052
- errorAsset(instance, err, 2048 /* LOG_TYPE.IMAGE */);
2060
+ errorAsset(instance, err, 2048);
2053
2061
  }
2054
2062
  }
2055
2063
  }
@@ -2129,7 +2137,7 @@ class FileManager extends core_1.Host {
2129
2137
  task();
2130
2138
  }
2131
2139
  catch (err) {
2132
- this.writeFail(["Unable to perform task" /* ERR_MESSAGE.PERFORM_TASK */, path.basename(this.getLocalUri(data))], err);
2140
+ this.writeFail(["Unable to perform task", path.basename(this.getLocalUri(data))], err);
2133
2141
  }
2134
2142
  this.removeAsyncTask();
2135
2143
  });
@@ -2199,14 +2207,14 @@ class FileManager extends core_1.Host {
2199
2207
  getDownload(type = 0) {
2200
2208
  return this[kDownloadStats][type];
2201
2209
  }
2202
- fetchObject(uri, options) {
2210
+ async fetchObject(uri, options) {
2203
2211
  if (!(0, types_1.isObject)(options)) {
2204
2212
  options = { format: options };
2205
2213
  }
2206
2214
  options.format || (options.format = 'json');
2207
- return this.fetchBuffer(uri, options).then(data => typeof data === 'object' ? data : null).catch(() => null);
2215
+ return this.Request.get(uri, options).then(data => typeof data === 'object' ? data : null);
2208
2216
  }
2209
- fetchBuffer(uri, options) {
2217
+ async fetchBuffer(uri, options) {
2210
2218
  if (options) {
2211
2219
  options.format = undefined;
2212
2220
  }
@@ -2224,14 +2232,14 @@ class FileManager extends core_1.Host {
2224
2232
  return buffer;
2225
2233
  });
2226
2234
  }
2227
- fetchFiles(uri, options) {
2235
+ async fetchFiles(uri, options) {
2228
2236
  if (!(0, types_1.isObject)(options)) {
2229
2237
  options = { pathname: options };
2230
2238
  }
2231
2239
  options.pathname || (options.pathname = this.baseDirectory);
2232
2240
  return this.Request.aria2c(uri, options);
2233
2241
  }
2234
- start(emptyDir) {
2242
+ async start(emptyDir) {
2235
2243
  const listener = (resolve) => {
2236
2244
  const callback = (files, errors, status) => {
2237
2245
  if (!this.restarting) {
@@ -2260,19 +2268,19 @@ class FileManager extends core_1.Host {
2260
2268
  });
2261
2269
  }
2262
2270
  switch (this.finalizeState) {
2263
- case 0 /* FINALIZE_STATE.READY */:
2271
+ case 0:
2264
2272
  if (this.delayed === 0 && !this.cleared) {
2265
2273
  break;
2266
2274
  }
2267
- case 1 /* FINALIZE_STATE.COMMIT */:
2268
- case 3 /* FINALIZE_STATE.RESTART */:
2269
- case 5 /* FINALIZE_STATE.RESTARTED */:
2270
- case 4 /* FINALIZE_STATE.QUEUED */:
2275
+ case 1:
2276
+ case 3:
2277
+ case 5:
2278
+ case 4:
2271
2279
  if (this._pendingResult) {
2272
2280
  return this._pendingResult;
2273
2281
  }
2274
- this.finalizeState = 0 /* FINALIZE_STATE.READY */;
2275
- case 2 /* FINALIZE_STATE.END */:
2282
+ this.finalizeState = 0;
2283
+ case 2:
2276
2284
  resetAssets.call(this);
2277
2285
  break;
2278
2286
  }
@@ -2292,14 +2300,14 @@ class FileManager extends core_1.Host {
2292
2300
  abortedHost.call(this);
2293
2301
  return;
2294
2302
  }
2295
- if (this.finalizeState === 5 /* FINALIZE_STATE.RESTARTED */) {
2303
+ if (this.finalizeState === 5) {
2296
2304
  this.restarting = false;
2297
2305
  }
2298
2306
  else if (this._pendingResult) {
2299
2307
  return;
2300
2308
  }
2301
2309
  if (!this.canWrite(this.baseDirectory, { ownPermissionOnly: true })) {
2302
- this.writeFail("Unsupported access" /* ERR_MESSAGE.UNSUPPORTED_ACCESS */, new Error(this.baseDirectory), 8192 /* LOG_TYPE.PERMISSION */);
2310
+ this.writeFail("Unsupported access", new Error(this.baseDirectory), 8192);
2303
2311
  this.cleared = true;
2304
2312
  if (this.queued) {
2305
2313
  this.joinQueue({ reject: true });
@@ -2307,15 +2315,15 @@ class FileManager extends core_1.Host {
2307
2315
  return;
2308
2316
  }
2309
2317
  switch (this.finalizeState) {
2310
- case 0 /* FINALIZE_STATE.READY */:
2318
+ case 0:
2311
2319
  if (this.delayed === 0 && !this.cleared) {
2312
2320
  break;
2313
2321
  }
2314
- case 1 /* FINALIZE_STATE.COMMIT */:
2315
- case 3 /* FINALIZE_STATE.RESTART */:
2316
- case 4 /* FINALIZE_STATE.QUEUED */:
2322
+ case 1:
2323
+ case 3:
2324
+ case 4:
2317
2325
  return;
2318
- case 2 /* FINALIZE_STATE.END */:
2326
+ case 2:
2319
2327
  resetAssets.call(this);
2320
2328
  break;
2321
2329
  }
@@ -2326,7 +2334,7 @@ class FileManager extends core_1.Host {
2326
2334
  args[i] = arguments[i];
2327
2335
  }
2328
2336
  if (this.joinQueue({ args })) {
2329
- this.finalizeState = 4 /* FINALIZE_STATE.QUEUED */;
2337
+ this.finalizeState = 4;
2330
2338
  return;
2331
2339
  }
2332
2340
  }
@@ -2336,7 +2344,7 @@ class FileManager extends core_1.Host {
2336
2344
  this.clearProcessTimeout();
2337
2345
  this[KTimerMain] = setInterval(() => {
2338
2346
  const { processing, processTimeout, finalizeState } = this;
2339
- if (finalizeState === 4 /* FINALIZE_STATE.QUEUED */) {
2347
+ if (finalizeState === 4) {
2340
2348
  return;
2341
2349
  }
2342
2350
  const currentTime = Date.now();
@@ -2369,7 +2377,7 @@ class FileManager extends core_1.Host {
2369
2377
  this.deleteFile(localUri, { id: file.id, emptyDir: true, all: true });
2370
2378
  }
2371
2379
  }
2372
- (moduleName && this.find(moduleName) || this).formatFail(16384 /* LOG_TYPE.TIMEOUT */, "FAIL!" /* ERR_MESSAGE.FAIL */, ["Unable to process file" /* ERR_MESSAGE.PROCESS_FILE */, moduleName || 'main'], (0, types_1.errorValue)(expired ? "Timeout was exceeded" /* ERR_MESSAGE.TIMEOUT */ : "Aborted" /* ERR_MESSAGE.ABORTED */, localUri), { queue: false, startTime: data.startTime });
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 });
2373
2381
  processing.splice(i--, 1);
2374
2382
  aborted = true;
2375
2383
  }
@@ -2455,11 +2463,11 @@ class FileManager extends core_1.Host {
2455
2463
  if (bundleIndex > 0) {
2456
2464
  items[bundleIndex - 1] = file;
2457
2465
  let url, parent;
2458
- if (file.fetchType === 1 /* FETCH_TYPE.HTTP */ && (cacheToDisk.has(url = file.url) || cacheToMemory.has(url)) && (parent = assets.find(item => item.bundleIndex === 0 && item.bundleId === bundleId))) {
2466
+ if (file.fetchType === 1 && (cacheToDisk.has(url = file.url) || cacheToMemory.has(url)) && (parent = assets.find(item => item.bundleIndex === 0 && item.bundleId === bundleId))) {
2459
2467
  (parent.bundleQueue || (parent.bundleQueue = [])).push(new Promise(resolve => {
2460
2468
  this.Request.open(url, { method: 'HEAD', httpVersion: 1 })
2461
2469
  .on('response', res => {
2462
- if (res.statusCode < 300 /* HTTP_STATUS.MULTIPLE_CHOICES */) {
2470
+ if (res.statusCode < 300) {
2463
2471
  applyHeaders(file, res.headers);
2464
2472
  }
2465
2473
  resolve(file);
@@ -2523,7 +2531,7 @@ class FileManager extends core_1.Host {
2523
2531
  }
2524
2532
  catch (err) {
2525
2533
  items.forEach(queue => queue.invalid = true);
2526
- this.writeFail([buffer ? "Unable to write buffer" /* ERR_MESSAGE.WRITE_BUFFER */ : "Unable to copy file" /* ERR_MESSAGE.COPY_FILE */, path.basename(file.localUri)], err, 32 /* LOG_TYPE.FILE */);
2534
+ this.writeFail([buffer ? "Unable to write buffer" : "Unable to copy file", path.basename(file.localUri)], err, 32);
2527
2535
  }
2528
2536
  }
2529
2537
  };
@@ -2573,7 +2581,7 @@ class FileManager extends core_1.Host {
2573
2581
  checkEtag = false;
2574
2582
  }
2575
2583
  else if (uri) {
2576
- if (type === 1 /* FETCH_TYPE.HTTP */ || type === 2 /* FETCH_TYPE.UNIX_SOCKET */) {
2584
+ if (type === 1 || type === 2) {
2577
2585
  const url = queue.url;
2578
2586
  const options = {
2579
2587
  url,
@@ -2581,7 +2589,7 @@ class FileManager extends core_1.Host {
2581
2589
  statusMessage: uri + ` (${queue.bundleIndex})`
2582
2590
  };
2583
2591
  let etag, pipeTo;
2584
- if (type === 2 /* FETCH_TYPE.UNIX_SOCKET */) {
2592
+ if (type === 2) {
2585
2593
  options.socketPath = queue.socketPath;
2586
2594
  options.httpVersion = 1;
2587
2595
  }
@@ -2667,7 +2675,7 @@ class FileManager extends core_1.Host {
2667
2675
  const pathname = this.getTempDir({ uuidDir: true });
2668
2676
  if (!pathname || !mimeType) {
2669
2677
  queue.invalid = true;
2670
- tasks.push(Promise.reject(!pathname ? new Error("Unable to create temp directory" /* ERR_MESSAGE.TEMP_DIRECTORY */) : (0, types_1.errorValue)("MIME not found" /* ERR_MESSAGE.NOTFOUND_MIME */, uri)));
2678
+ tasks.push(Promise.reject(!pathname ? new Error("Unable to create temp directory") : (0, types_1.errorValue)("MIME not found", uri)));
2671
2679
  break;
2672
2680
  }
2673
2681
  tasks.push(this.fetchFiles(queue.url || uri, { pathname, binOpts: queue.binOpts || file.binOpts })
@@ -2705,7 +2713,7 @@ class FileManager extends core_1.Host {
2705
2713
  success = await Promise.all(tasks)
2706
2714
  .then(() => true)
2707
2715
  .catch(err => {
2708
- this.writeFail(["Unable to download file" /* ERR_MESSAGE.DOWNLOAD_FILE */, 'bundle: ' + path.basename(localUri)], err, 1024 /* LOG_TYPE.HTTP */);
2716
+ this.writeFail(["Unable to download file", 'bundle: ' + path.basename(localUri)], err, 1024);
2709
2717
  return false;
2710
2718
  });
2711
2719
  }
@@ -2771,10 +2779,10 @@ class FileManager extends core_1.Host {
2771
2779
  if (!preceding) {
2772
2780
  this.completeAsyncTask();
2773
2781
  }
2774
- this.writeFail(["Unable to download file" /* ERR_MESSAGE.DOWNLOAD_FILE */, uri], err, err instanceof Error && err.message.startsWith("Timeout was exceeded" /* ERR_MESSAGE.TIMEOUT */) ? 16384 /* LOG_TYPE.TIMEOUT */ : 1024 /* LOG_TYPE.HTTP */);
2782
+ this.writeFail(["Unable to download file", uri], err, err instanceof Error && err.message.startsWith("Timeout was exceeded") ? 16384 : 1024);
2775
2783
  };
2776
2784
  const errorPermission = (file) => {
2777
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, file.uri], (0, types_1.errorValue)('Operation not permitted', file.uri || "Unknown" /* ERR_MESSAGE.UNKNOWN */), 8192 /* LOG_TYPE.PERMISSION */);
2785
+ this.writeFail(["Unable to read file", file.uri], (0, types_1.errorValue)('Operation not permitted', file.uri || "Unknown"), 8192);
2778
2786
  file.invalid = true;
2779
2787
  };
2780
2788
  const createFolder = (file, pathname) => {
@@ -2787,7 +2795,7 @@ class FileManager extends core_1.Host {
2787
2795
  }
2788
2796
  else {
2789
2797
  file.invalid = true;
2790
- this.writeFail("Unable to create directory" /* ERR_MESSAGE.CREATE_DIRECTORY */, (0, types_1.errorValue)('Path not found', pathname));
2798
+ this.writeFail("Unable to create directory", (0, types_1.errorValue)('Path not found', pathname));
2791
2799
  return false;
2792
2800
  }
2793
2801
  }
@@ -2795,7 +2803,7 @@ class FileManager extends core_1.Host {
2795
2803
  };
2796
2804
  const fileReceived = (item, localUri, err, fetched, binary) => {
2797
2805
  if (item.checksum && !err && !checkHash(item.buffer || localUri, !!item.buffer, item.checksum)) {
2798
- err = (0, types_1.errorValue)("Checksum did not match" /* ERR_MESSAGE.FAILED_CHECKSUM */, item.uri);
2806
+ err = (0, types_1.errorValue)("Checksum did not match", item.uri);
2799
2807
  this.filesToRemove.add(localUri);
2800
2808
  }
2801
2809
  if (err) {
@@ -2871,7 +2879,7 @@ class FileManager extends core_1.Host {
2871
2879
  }
2872
2880
  return false;
2873
2881
  };
2874
- if ((!etag || item.fetchType === 1 /* FETCH_TYPE.HTTP */ && ((0, types_1.isEmpty)(bundleId) || bundleIndex <= 0)) && (!watch || !item.watch || setBuffer(item))) {
2882
+ if ((!etag || item.fetchType === 1 && ((0, types_1.isEmpty)(bundleId) || bundleIndex <= 0)) && (!watch || !item.watch || setBuffer(item))) {
2875
2883
  let childBundle, childDownload;
2876
2884
  if (!(0, types_1.isEmpty)(bundleId) && bundleIndex > 0) {
2877
2885
  const target = assets.find(parent => parent.bundleId === bundleId && parent.bundleIndex === 0);
@@ -2907,8 +2915,8 @@ class FileManager extends core_1.Host {
2907
2915
  setBuffer(item);
2908
2916
  }
2909
2917
  if (core_1.Host.isPath(localUri) && (!item.checksumOutput || checkHash(localUri, false, item.checksumOutput))) {
2910
- item.flags |= 128 /* ASSET_FLAG.EXISTS */;
2911
- if (!etag || item.fetchType !== 1 /* FETCH_TYPE.HTTP */) {
2918
+ item.flags |= 128;
2919
+ if (!etag || item.fetchType !== 1) {
2912
2920
  if (!(0, types_1.isEmpty)(bundleId) && bundleIndex === 0) {
2913
2921
  assets.filter(child => child.bundleId === bundleId && child.bundleIndex > 0).forEach(child => {
2914
2922
  setBuffer(child);
@@ -3002,10 +3010,10 @@ class FileManager extends core_1.Host {
3002
3010
  continue;
3003
3011
  }
3004
3012
  const checkDest = (src) => staging || !(0, lib_v4_1.hasSameStat)(src, localUri);
3005
- const type = item.fetchType || 0 /* FETCH_TYPE.UNKNOWN */;
3013
+ const type = item.fetchType || 0;
3006
3014
  const bundleMain = !(0, types_1.isEmpty)(item.bundleId) && item.bundleIndex === 0;
3007
- const isHttp = type === 1 /* FETCH_TYPE.HTTP */;
3008
- if (isHttp || type === 2 /* FETCH_TYPE.UNIX_SOCKET */) {
3015
+ const isHttp = type === 1;
3016
+ if (isHttp || type === 2) {
3009
3017
  let checkEtag;
3010
3018
  if ((0, types_1.isEmpty)(item.bundleId) && bundling[uri]) {
3011
3019
  bundling[uri].push(item);
@@ -3034,7 +3042,7 @@ class FileManager extends core_1.Host {
3034
3042
  const closeResponse = () => client?.destroy();
3035
3043
  const downloadUri = (request, etagDir) => {
3036
3044
  if (checkEtag) {
3037
- item.flags &= ~128 /* ASSET_FLAG.EXISTS */;
3045
+ item.flags &= ~128;
3038
3046
  }
3039
3047
  closeResponse();
3040
3048
  const location = request.url.toString();
@@ -3051,6 +3059,7 @@ class FileManager extends core_1.Host {
3051
3059
  }
3052
3060
  else {
3053
3061
  request.socketPath = item.socketPath;
3062
+ request.method = undefined;
3054
3063
  request.httpVersion = 1;
3055
3064
  }
3056
3065
  this.fetchBuffer(request.url, request)
@@ -3085,7 +3094,7 @@ class FileManager extends core_1.Host {
3085
3094
  (client = request.open(href, target))
3086
3095
  .on('response', res => {
3087
3096
  const statusCode = res.statusCode;
3088
- if (statusCode < 300 /* HTTP_STATUS.MULTIPLE_CHOICES */) {
3097
+ if (statusCode < 300) {
3089
3098
  const etag = applyHeaders(item, res.headers, false, mainEtag);
3090
3099
  let tempDir, etagDir;
3091
3100
  if (etag) {
@@ -3157,7 +3166,7 @@ class FileManager extends core_1.Host {
3157
3166
  fs.writeFileSync(localUri, buffer);
3158
3167
  this.addDownload(Buffer.byteLength(buffer, encoding), types_1.DOWNLOAD_TYPE.CACHE);
3159
3168
  if (checkEtag) {
3160
- item.flags &= ~128 /* ASSET_FLAG.EXISTS */;
3169
+ item.flags &= ~128;
3161
3170
  }
3162
3171
  fileReceived(item, localUri, null, true);
3163
3172
  closeResponse();
@@ -3173,7 +3182,7 @@ class FileManager extends core_1.Host {
3173
3182
  }
3174
3183
  downloadUri(target, etagDir);
3175
3184
  }
3176
- else if (statusCode < 400 /* HTTP_STATUS.BAD_REQUEST */) {
3185
+ else if (statusCode < 400) {
3177
3186
  closeResponse();
3178
3187
  const location = res.headers.location;
3179
3188
  if (location && ++redirects <= HTTP_CLIENT.redirectLimit) {
@@ -3219,7 +3228,7 @@ class FileManager extends core_1.Host {
3219
3228
  }
3220
3229
  else if (type) {
3221
3230
  if (bundleMain && !item.mimeType) {
3222
- errorRequest(item, (0, types_1.errorValue)("MIME not found" /* ERR_MESSAGE.NOTFOUND_MIME */, uri), true);
3231
+ errorRequest(item, (0, types_1.errorValue)("MIME not found", uri), true);
3223
3232
  }
3224
3233
  else if (!checkQueue(item, localUri, pathname, false)) {
3225
3234
  if (downloading[uri]) {
@@ -3257,7 +3266,7 @@ class FileManager extends core_1.Host {
3257
3266
  found = true;
3258
3267
  }
3259
3268
  catch (err) {
3260
- this.writeFail(["Unable to rename file" /* ERR_MESSAGE.RENAME_FILE */, item.filename], err, 32 /* LOG_TYPE.FILE */);
3269
+ this.writeFail(["Unable to rename file", item.filename], err, 32);
3261
3270
  }
3262
3271
  }
3263
3272
  else {
@@ -3339,7 +3348,7 @@ class FileManager extends core_1.Host {
3339
3348
  item.buffer = result;
3340
3349
  }
3341
3350
  })
3342
- .catch(err => this.writeFail(["Unable to compress file" /* ERR_MESSAGE.COMPRESS_FILE */, path.basename(file)], err, { type: 8 /* LOG_TYPE.COMPRESS */, startTime: options.startTime })));
3351
+ .catch(err => this.writeFail(["Unable to compress file", path.basename(file)], err, { type: 8, startTime: options.startTime })));
3343
3352
  }
3344
3353
  }
3345
3354
  }
@@ -3350,7 +3359,7 @@ class FileManager extends core_1.Host {
3350
3359
  async finalizeDocument() {
3351
3360
  for (const { instance, constructor } of this.Document) {
3352
3361
  if (constructor.finalize && instance.assets.length) {
3353
- await constructor.finalize.call(this, instance).catch(err => rejectModule.call(instance, err, 4 /* LOG_TYPE.PROCESS */));
3362
+ await constructor.finalize.call(this, instance).catch(err => rejectModule.call(instance, err, 4));
3354
3363
  if (this.aborted) {
3355
3364
  return;
3356
3365
  }
@@ -3362,7 +3371,7 @@ class FileManager extends core_1.Host {
3362
3371
  for (const { instance, constructor } of this.Task) {
3363
3372
  const items = assets.filter(item => item.tasks.find(data => data.handler === instance.moduleName));
3364
3373
  if (items.length) {
3365
- await (constructor.using || constructor.finalize).call(this, instance, items).catch(err => rejectModule.call(instance, err, 4 /* LOG_TYPE.PROCESS */));
3374
+ await (constructor.using || constructor.finalize).call(this, instance, items).catch(err => rejectModule.call(instance, err, 4));
3366
3375
  if (this.aborted) {
3367
3376
  return;
3368
3377
  }
@@ -3370,9 +3379,9 @@ class FileManager extends core_1.Host {
3370
3379
  }
3371
3380
  }
3372
3381
  }
3373
- finalizeCloud() {
3382
+ async finalizeCloud() {
3374
3383
  const cloud = this.Cloud;
3375
- return cloud ? cloud_1.default.finalize.call(this, cloud).catch(err => rejectModule.call(cloud, err, 64 /* LOG_TYPE.CLOUD */)) : Promise.resolve();
3384
+ return cloud ? cloud_1.default.finalize.call(this, cloud).catch(err => rejectModule.call(cloud, err, 64)) : Promise.resolve();
3376
3385
  }
3377
3386
  async finalizeCleanup() {
3378
3387
  if (this.emptyDir.size) {
@@ -3386,7 +3395,7 @@ class FileManager extends core_1.Host {
3386
3395
  }
3387
3396
  for (const { instance, constructor } of this.Document) {
3388
3397
  if (constructor.cleanup && instance.assets.length) {
3389
- await constructor.cleanup.call(this, instance).catch(err => rejectModule.call(instance, err, 4 /* LOG_TYPE.PROCESS */));
3398
+ await constructor.cleanup.call(this, instance).catch(err => rejectModule.call(instance, err, 4));
3390
3399
  }
3391
3400
  }
3392
3401
  }
@@ -3424,11 +3433,11 @@ class FileManager extends core_1.Host {
3424
3433
  }
3425
3434
  }
3426
3435
  removeFiles();
3427
- await this.finalizeCompress(this.assets.filter(item => item.compress && !ignoreAsset(item))).catch(err => rejectModule.call(this, err, 8 /* LOG_TYPE.COMPRESS */));
3436
+ await this.finalizeCompress(this.assets.filter(item => item.compress && !ignoreAsset(item))).catch(err => rejectModule.call(this, err, 8));
3428
3437
  if (this.aborted) {
3429
3438
  return Promise.reject((0, types_1.createAbortError)());
3430
3439
  }
3431
- await this.finalizeDocument().catch(err => rejectModule.call(this, err, 4 /* LOG_TYPE.PROCESS */));
3440
+ await this.finalizeDocument().catch(err => rejectModule.call(this, err, 4));
3432
3441
  if (this.aborted) {
3433
3442
  return Promise.reject((0, types_1.createAbortError)());
3434
3443
  }
@@ -3438,12 +3447,12 @@ class FileManager extends core_1.Host {
3438
3447
  fs.writeFileSync(item.localUri, item.sourceUTF8, item.encoding || (item.encoding = 'utf-8'));
3439
3448
  }
3440
3449
  catch (err) {
3441
- this.writeFail(["Unable to write file" /* ERR_MESSAGE.WRITE_FILE */, path.basename(item.localUri)], err, { type: 32 /* LOG_TYPE.FILE */, startTime });
3450
+ this.writeFail(["Unable to write file", path.basename(item.localUri)], err, { type: 32, startTime });
3442
3451
  }
3443
3452
  }
3444
3453
  }
3445
3454
  removeFiles();
3446
- 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 /* LOG_TYPE.PROCESS */));
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));
3447
3456
  if (this.aborted) {
3448
3457
  return Promise.reject((0, types_1.createAbortError)());
3449
3458
  }
@@ -3454,12 +3463,12 @@ class FileManager extends core_1.Host {
3454
3463
  if (!checkHash(localUri, false, item.checksumOutput)) {
3455
3464
  item.invalid = true;
3456
3465
  filesToRemove.add(localUri);
3457
- this.writeFail(["Invalid checksum" /* ERR_MESSAGE.CHECKSUM */, path.basename(localUri)], (0, types_1.errorValue)("Checksum did not match" /* ERR_MESSAGE.FAILED_CHECKSUM */, localUri), { type: 32 /* LOG_TYPE.FILE */, startTime });
3466
+ this.writeFail(["Invalid checksum", path.basename(localUri)], (0, types_1.errorValue)("Checksum did not match", localUri), { type: 32, startTime });
3458
3467
  }
3459
3468
  }
3460
3469
  }
3461
3470
  removeFiles();
3462
- await this.finalizeCloud().catch(err => rejectModule.call(this, err, 64 /* LOG_TYPE.CLOUD */));
3471
+ await this.finalizeCloud().catch(err => rejectModule.call(this, err, 64));
3463
3472
  if (this.aborted) {
3464
3473
  return Promise.reject((0, types_1.createAbortError)());
3465
3474
  }
@@ -3488,22 +3497,22 @@ class FileManager extends core_1.Host {
3488
3497
  try {
3489
3498
  const files = (await FileManager.writeChecksum(baseDirectory, checksum.filename, checksum));
3490
3499
  if (sumTime) {
3491
- this.writeTimeElapsed(checksum.algorithm || "sha256" /* HASH_OUTPUT.ALGORITHM */, [baseDirectory, files.length + (files.length === 1 ? ' file' : ' files')], sumTime, { ...core_1.Host.LOG_STYLE_WARN });
3500
+ this.writeTimeElapsed(checksum.algorithm || "sha256", [baseDirectory, files.length + (files.length === 1 ? ' file' : ' files')], sumTime, { ...core_1.Host.LOG_STYLE_WARN });
3492
3501
  }
3493
3502
  }
3494
3503
  catch (err) {
3495
- this.writeFail(["Unable to read directory" /* ERR_MESSAGE.READ_DIRECTORY */, path.basename(baseDirectory)], err, { type: 32 /* LOG_TYPE.FILE */, startTime });
3504
+ this.writeFail(["Unable to read directory", path.basename(baseDirectory)], err, { type: 32, startTime });
3496
3505
  }
3497
3506
  }
3498
3507
  }
3499
- await this.finalizeCleanup().catch(err => rejectModule.call(this, err, 1 /* LOG_TYPE.SYSTEM */));
3508
+ await this.finalizeCleanup().catch(err => rejectModule.call(this, err, 1));
3500
3509
  removeFiles();
3501
3510
  if (LOG_TIMEELAPSED) {
3502
3511
  const [h, d, c] = this[kDownloadStats];
3503
3512
  const errorCount = this.errorCount;
3504
3513
  const message = [];
3505
3514
  if (errorCount) {
3506
- message.push('ERROR ' + errorCount); // eslint-disable-line @typescript-eslint/no-base-to-string
3515
+ message.push('ERROR ' + errorCount);
3507
3516
  }
3508
3517
  let [size, count] = h;
3509
3518
  if (count) {
@@ -3529,7 +3538,7 @@ class FileManager extends core_1.Host {
3529
3538
  this.Request.close();
3530
3539
  }
3531
3540
  set restarting(value) {
3532
- this.finalizeState = (this[kRestarting] = value) ? 3 /* FINALIZE_STATE.RESTART */ : 0 /* FINALIZE_STATE.READY */;
3541
+ this.finalizeState = (this[kRestarting] = value) ? 3 : 0;
3533
3542
  }
3534
3543
  get restarting() {
3535
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.0",
3
+ "version": "0.7.2",
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,17 +17,18 @@
17
17
  "squared-functions"
18
18
  ],
19
19
  "author": "An Pham <anpham6@gmail.com>",
20
- "license": "BSD 3-Clause",
20
+ "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "0.7.0",
24
- "@e-mc/compress": "0.7.0",
25
- "@e-mc/core": "0.7.0",
26
- "@e-mc/document": "0.7.0",
27
- "@e-mc/image": "0.7.0",
28
- "@e-mc/request": "0.7.0",
29
- "@e-mc/task": "0.7.0",
30
- "@e-mc/types": "0.7.0",
31
- "@e-mc/watch": "0.7.0"
23
+ "@e-mc/cloud": "0.7.2",
24
+ "@e-mc/compress": "0.7.2",
25
+ "@e-mc/core": "0.7.2",
26
+ "@e-mc/document": "0.7.2",
27
+ "@e-mc/image": "0.7.2",
28
+ "@e-mc/request": "0.7.2",
29
+ "@e-mc/task": "0.7.2",
30
+ "@e-mc/types": "0.7.2",
31
+ "@e-mc/watch": "0.7.2",
32
+ "picomatch": "^3.0.1"
32
33
  }
33
34
  }