@e-mc/file-manager 0.6.0 → 0.6.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 +7 -11
  2. package/README.md +5 -3
  3. package/index.d.ts +5 -5
  4. package/index.js +145 -148
  5. package/package.json +11 -11
package/LICENSE CHANGED
@@ -1,11 +1,7 @@
1
- Copyright 2023 An Pham
2
-
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
-
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
-
7
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
-
9
- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
-
11
- 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.
1
+ Copyright 2023 Ninja Scroll
2
+
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
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
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
@@ -1,5 +1,7 @@
1
- ### @e-mc/file-manager
1
+ # @e-mc/file-manager
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever Kagerō
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,21 @@
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 lib_v4_1 = require("@e-mc/module/lib-v4");
7
+ const util_1 = require("@e-mc/request/util");
8
+ const asset_1 = require("@e-mc/document/asset");
9
+ const util_2 = require("@e-mc/document/util");
10
+ const types_1 = require("@e-mc/types");
11
+ const core_1 = require("@e-mc/core");
12
+ const request_1 = require("@e-mc/request");
13
+ const document_1 = require("@e-mc/document");
14
+ const task_1 = require("@e-mc/task");
15
+ const image_1 = require("@e-mc/image");
16
+ const watch_1 = require("@e-mc/watch");
17
+ const compress_1 = require("@e-mc/compress");
18
+ const cloud_1 = require("@e-mc/cloud");
20
19
  const kBaseDirectory = Symbol('baseDirectory');
21
20
  const kIncremental = Symbol('incremental');
22
21
  const kRestarting = Symbol('restarting');
@@ -36,7 +35,7 @@ const CACHE_ETAG = {};
36
35
  const DISK = {
37
36
  ENABLED: false,
38
37
  EXPIRES: 0,
39
- LIMIT: (0, types_1.formatSize)("1gb" /* CACHE_SIZE.FILE_MANAGER_DISK_LIMIT */),
38
+ LIMIT: (0, types_1.formatSize)("1gb"),
40
39
  INCLUDE: [],
41
40
  EXCLUDE: []
42
41
  };
@@ -46,8 +45,8 @@ const MEMORY = {
46
45
  SIZE: 0,
47
46
  TOTAL: 0,
48
47
  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 */),
48
+ LIMIT: (0, types_1.formatSize)("100mb"),
49
+ LIMIT_ALL: (0, types_1.formatSize)("512mb"),
51
50
  INCLUDE: [],
52
51
  EXCLUDE: [],
53
52
  PURGE: 0.25,
@@ -61,11 +60,11 @@ let RECURSION_LIMIT = 10;
61
60
  let LOG_TIMEELAPSED = true;
62
61
  let LOG_TIMEPROCESS = true;
63
62
  const HTTP_CLIENT = {
64
- timeout: 60000 /* TIME.m */,
65
- connectTimeout: 20 * 1000 /* TIME.S */,
63
+ timeout: 60000,
64
+ connectTimeout: 20 * 1000,
66
65
  redirectLimit: 3,
67
- retryWait: 1000 /* TIME.S */,
68
- retryAfter: 30 * 1000 /* TIME.S */,
66
+ retryWait: 1000,
67
+ retryAfter: 30 * 1000,
69
68
  retryLimit: 10
70
69
  };
71
70
  function applyTimeout(target, options) {
@@ -96,7 +95,7 @@ function withinSizeRange(uri, value, pattern) {
96
95
  return true;
97
96
  }
98
97
  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 });
98
+ this.formatMessage(128, 'START', [new Date().toLocaleString(), this.assets.length + ' assets'], this.baseDirectory, { ...core_1.Host.LOG_STYLE_SUCCESS });
100
99
  }
101
100
  function clearAssets() {
102
101
  this.assets.forEach(item => {
@@ -116,7 +115,7 @@ function bundleTorrent(files, mimeType, encoding) {
116
115
  output += fs.readFileSync(file, encoding);
117
116
  }
118
117
  catch (err) {
119
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(file)], err, 32 /* LOG_TYPE.FILE */);
118
+ this.writeFail(["Unable to read file", path.basename(file)], err, 32);
120
119
  }
121
120
  }
122
121
  }
@@ -127,7 +126,7 @@ function resetAssets() {
127
126
  FileManager.sanitizeAssets(this.assets);
128
127
  }
129
128
  function abortedHost() {
130
- if (this.finalizeState === 6 /* FINALIZE_STATE.ABORTED */) {
129
+ if (this.finalizeState === 6) {
131
130
  this.restarting = false;
132
131
  this.performFinalize(true);
133
132
  return this.done;
@@ -149,7 +148,7 @@ function observeFile(instance) {
149
148
  if (PLATFORM_WIN32) {
150
149
  value = value.toLowerCase();
151
150
  }
152
- if (value[value.length - 1] !== path.sep) {
151
+ if (!value.endsWith(path.sep)) {
153
152
  value += path.sep;
154
153
  }
155
154
  for (const name of this.files) {
@@ -171,7 +170,7 @@ function collectErrors() {
171
170
  const clearModule = (instance) => {
172
171
  const { moduleName, errors } = instance;
173
172
  if (errors.length) {
174
- errors.forEach(value => result.push(`[${moduleName}] ` + (core_1.Host.asString(value) || "Unknown" /* ERR_MESSAGE.UNKNOWN */)));
173
+ errors.forEach(value => result.push(`[${moduleName}] ` + (core_1.Host.asString(value) || "Unknown")));
175
174
  errors.length = 0;
176
175
  }
177
176
  };
@@ -193,10 +192,10 @@ function collectErrors() {
193
192
  return result;
194
193
  }
195
194
  function rejectModule(err, type, hint) {
196
- this.writeFail(["Handled rejection" /* ERR_MESSAGE.HANDLED_REJECTION */, this.moduleName + (hint ? ': ' + hint : '')], err, type);
195
+ this.writeFail(["Handled rejection", this.moduleName + (hint ? ': ' + hint : '')], err, type);
197
196
  }
198
197
  const isFunction = (value) => typeof value === 'function';
199
- const ignoreAsset = (item, exists) => item.invalid || (0, types_1.hasBit)(item.flags, 1 /* ASSET_FLAG.IGNORE */ | (!exists ? 128 /* ASSET_FLAG.EXISTS */ : 0));
198
+ const ignoreAsset = (item, exists) => item.invalid || (0, types_1.hasBit)(item.flags, 1 | (!exists ? 128 : 0));
200
199
  class HttpDiskCache {
201
200
  constructor(host, enabled) {
202
201
  this.host = host;
@@ -328,7 +327,7 @@ class HttpDiskCache {
328
327
  }
329
328
  class HttpMemoryCache extends HttpDiskCache {
330
329
  constructor(host, enabled) {
331
- super(host, enabled && core_1.Host.enabled("memory.settings.users" /* KEY_NAME.MEMORY_SETTINGS_USERS */, host.username));
330
+ super(host, enabled && core_1.Host.enabled("memory.settings.users", host.username));
332
331
  this.limit = MEMORY.LIMIT;
333
332
  this.expires = MEMORY.EXPIRES;
334
333
  this.toDisk = [MEMORY.DISK_MIN, MEMORY.DISK_MAX];
@@ -509,8 +508,8 @@ class FileManager extends core_1.Host {
509
508
  SESSION_LIMIT = Math.pow(10, value);
510
509
  }
511
510
  }
512
- LOG_TIMEELAPSED = this.hasLogType(128 /* LOG_TYPE.TIME_ELAPSED */);
513
- LOG_TIMEPROCESS = this.hasLogType(256 /* LOG_TYPE.TIME_PROCESS */);
511
+ LOG_TIMEELAPSED = this.hasLogType(128);
512
+ LOG_TIMEPROCESS = this.hasLogType(256);
514
513
  return true;
515
514
  }
516
515
  return false;
@@ -530,7 +529,7 @@ class FileManager extends core_1.Host {
530
529
  for (const attr in item) {
531
530
  switch (attr) {
532
531
  case 'flags':
533
- item.flags &= ~(128 /* ASSET_FLAG.EXISTS */ | 16 /* ASSET_FLAG.MODIFIED */);
532
+ item.flags &= ~(128 | 16);
534
533
  break;
535
534
  case 'watch':
536
535
  if ((0, types_1.isPlainObject)(item.watch) && item.watch.assets) {
@@ -626,7 +625,7 @@ class FileManager extends core_1.Host {
626
625
  HTTP_CLIENT.connectTimeout = timeout;
627
626
  }
628
627
  if ((retry_wait = (0, util_1.fromSeconds)(retry_wait)) >= 0) {
629
- HTTP_CLIENT.retryWait = Math.min(retry_wait, 600 * 1000 /* TIME.S */);
628
+ HTTP_CLIENT.retryWait = Math.min(retry_wait, 600 * 1000);
630
629
  }
631
630
  if ((retry_after = (0, util_1.fromSeconds)(retry_after)) >= 0) {
632
631
  HTTP_CLIENT.retryAfter = Math.min(retry_after, this.MAX_TIMEOUT);
@@ -640,7 +639,7 @@ class FileManager extends core_1.Host {
640
639
  }
641
640
  constructor(baseDirectory, config, permission, postFinalize) {
642
641
  super(config);
643
- this.finalizeState = 0 /* FINALIZE_STATE.READY */;
642
+ this.finalizeState = 0;
644
643
  this.processTimeout = PROCESS_TIMEOUT.filemanager;
645
644
  this.Document = [];
646
645
  this.Task = [];
@@ -742,7 +741,7 @@ class FileManager extends core_1.Host {
742
741
  request.host = this;
743
742
  this.Request = request;
744
743
  if (this.aborted) {
745
- this.finalizeState = 6 /* FINALIZE_STATE.ABORTED */;
744
+ this.finalizeState = 6;
746
745
  }
747
746
  else {
748
747
  request.init(config).apply({ client: HTTP_CLIENT });
@@ -852,7 +851,7 @@ class FileManager extends core_1.Host {
852
851
  }
853
852
  if (this.restartable && (!recursive || --this[kRecursionLimit] >= 0)) {
854
853
  if (this.reset()) {
855
- this.finalizeState = 5 /* FINALIZE_STATE.RESTARTED */;
854
+ this.finalizeState = 5;
856
855
  FileManager.sanitizeAssets(this.assets, exclusions);
857
856
  for (const { instance } of this.Document) {
858
857
  instance.restart();
@@ -900,7 +899,7 @@ class FileManager extends core_1.Host {
900
899
  }
901
900
  }
902
901
  reset() {
903
- if (this.finalizeState === 1 /* FINALIZE_STATE.COMMIT */) {
902
+ if (this.finalizeState === 1) {
904
903
  return false;
905
904
  }
906
905
  super.reset();
@@ -922,7 +921,7 @@ class FileManager extends core_1.Host {
922
921
  clearAssets.call(this);
923
922
  this.cleared = false;
924
923
  this[kDelayed] = 0;
925
- this.finalizeState = 0 /* FINALIZE_STATE.READY */;
924
+ this.finalizeState = 0;
926
925
  return true;
927
926
  }
928
927
  deleteFile(value, options = {}, callback) {
@@ -947,11 +946,11 @@ class FileManager extends core_1.Host {
947
946
  }
948
947
  resumeThread(options) {
949
948
  if (this.aborted || options.aborted) {
950
- this.finalizeState = 0 /* FINALIZE_STATE.READY */;
949
+ this.finalizeState = 0;
951
950
  this.performFinalize(true);
952
951
  return;
953
952
  }
954
- this.finalizeState = 5 /* FINALIZE_STATE.RESTARTED */;
953
+ this.finalizeState = 5;
955
954
  startMessage.call(this);
956
955
  this.processAssets(...options.args);
957
956
  }
@@ -987,7 +986,7 @@ class FileManager extends core_1.Host {
987
986
  if (typeof target === 'string') {
988
987
  const module = args.shift();
989
988
  if ((0, types_1.isObject)(module)) {
990
- if (target === "@e-mc/cloud" /* PACKAGE_NAME.CLOUD */) {
989
+ if (target === "@e-mc/cloud") {
991
990
  instance = new cloud_1.default(module, database);
992
991
  }
993
992
  else {
@@ -997,11 +996,11 @@ class FileManager extends core_1.Host {
997
996
  instance = new Handler(module, database);
998
997
  }
999
998
  else {
1000
- throw (0, types_1.errorMessage)(this.moduleName, "Not a Cloud constructor" /* ERR_CLOUD.CONSTRUCTOR */, target);
999
+ throw (0, types_1.errorMessage)(this.moduleName, "Not a Cloud constructor", target);
1001
1000
  }
1002
1001
  }
1003
1002
  catch (err) {
1004
- this.checkPackage(err, target, ["Unable to load handler" /* ERR_MESSAGE.LOAD_HANDLER */, this.moduleName], 64 /* LOG_TYPE.CLOUD */);
1003
+ this.checkPackage(err, target, ["Unable to load handler", this.moduleName], 64);
1005
1004
  }
1006
1005
  }
1007
1006
  }
@@ -1045,17 +1044,20 @@ class FileManager extends core_1.Host {
1045
1044
  manager.install('cloud', this.Cloud.module);
1046
1045
  }
1047
1046
  if (this.Image) {
1048
- for (const handler of this.Image) {
1049
- if ((0, types_1.isPlainObject)(handler)) {
1050
- const image = handler.instance;
1051
- image.reset();
1052
- image.host = manager;
1053
- observeFile.call(manager, image);
1047
+ const mimeMap = new Map();
1048
+ let params = [];
1049
+ for (const [mimeType, handler] of this.Image) {
1050
+ const { constructor, params: trailing } = handler;
1051
+ if (params.length === 0 || mimeType === 'handler') {
1052
+ params = trailing;
1054
1053
  }
1054
+ mimeMap.set(mimeType, constructor);
1055
1055
  }
1056
- manager.Image = this.Image;
1056
+ manager.install('image', mimeMap, ...params);
1057
+ }
1058
+ if (this.Compress) {
1059
+ manager.install('compress', this.Compress.module);
1057
1060
  }
1058
- manager.Compress = this.Compress;
1059
1061
  manager.sessionId = this.sessionId;
1060
1062
  manager.permission = this.permission;
1061
1063
  manager.cacheToDisk = this.cacheToDisk;
@@ -1065,7 +1067,7 @@ class FileManager extends core_1.Host {
1065
1067
  manager.processAssets();
1066
1068
  }
1067
1069
  catch (err) {
1068
- manager.writeFail("Unknown" /* ERR_MESSAGE.UNKNOWN */, err, { startTime: manager.startTime });
1070
+ manager.writeFail("Unknown", err, { startTime: manager.startTime });
1069
1071
  }
1070
1072
  }
1071
1073
  return manager;
@@ -1123,7 +1125,7 @@ class FileManager extends core_1.Host {
1123
1125
  if (value) {
1124
1126
  const isSame = (a, b) => a === b || decodeURIComponent(a) === decodeURIComponent(b);
1125
1127
  const result = (assets || this.assets).filter(item => {
1126
- let { uri, flags } = item;
1128
+ const { uri, flags } = item;
1127
1129
  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))) {
1128
1130
  if (origin) {
1129
1131
  if (!item.url) {
@@ -1145,13 +1147,7 @@ class FileManager extends core_1.Host {
1145
1147
  const indexA = uri.indexOf('#');
1146
1148
  const indexB = value.indexOf('#');
1147
1149
  if (indexA !== -1 || indexB !== -1) {
1148
- if (indexA !== -1) {
1149
- uri = uri.substring(0, indexA);
1150
- }
1151
- if (indexB !== -1) {
1152
- value = value.substring(0, indexB);
1153
- }
1154
- return isSame(uri, value);
1150
+ return isSame(indexA !== -1 ? uri.substring(0, indexA) : uri, indexB !== -1 ? value.substring(0, indexB) : value);
1155
1151
  }
1156
1152
  }
1157
1153
  return false;
@@ -1232,7 +1228,7 @@ class FileManager extends core_1.Host {
1232
1228
  }
1233
1229
  }
1234
1230
  catch (err) {
1235
- this.writeFail(["Unable to rename file" /* ERR_MESSAGE.RENAME_FILE */, name], err, 32 /* LOG_TYPE.FILE */);
1231
+ this.writeFail(["Unable to rename file", name], err, 32);
1236
1232
  return false;
1237
1233
  }
1238
1234
  }
@@ -1253,7 +1249,7 @@ class FileManager extends core_1.Host {
1253
1249
  file.pathname = pathname;
1254
1250
  file.filename = filename;
1255
1251
  this.setLocalUri(file, true);
1256
- this.writeFail(["Unable to rename file" /* ERR_MESSAGE.RENAME_FILE */, name], err, 32 /* LOG_TYPE.FILE */);
1252
+ this.writeFail(["Unable to rename file", name], err, 32);
1257
1253
  return false;
1258
1254
  }
1259
1255
  }
@@ -1290,7 +1286,7 @@ class FileManager extends core_1.Host {
1290
1286
  }
1291
1287
  }
1292
1288
  catch (err) {
1293
- this.writeFail(["Unable to rename file" /* ERR_MESSAGE.RENAME_FILE */, path.basename(value)], err, 32 /* LOG_TYPE.FILE */);
1289
+ this.writeFail(["Unable to rename file", path.basename(value)], err, 32);
1294
1290
  return false;
1295
1291
  }
1296
1292
  if (!copy) {
@@ -1318,25 +1314,25 @@ class FileManager extends core_1.Host {
1318
1314
  this.performFinalize();
1319
1315
  }
1320
1316
  if (err) {
1321
- this.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, uri], err, 32 /* LOG_TYPE.FILE */);
1317
+ this.writeFail(["Unknown", uri], err, 32);
1322
1318
  }
1323
1319
  }
1324
1320
  performFinalize(override) {
1325
1321
  const state = this.finalizeState;
1326
- if (state === 0 /* FINALIZE_STATE.READY */ && (this.cleared && this[kDelayed] <= 0 || override) || (this.aborted || state === 3 /* FINALIZE_STATE.RESTART */) && override) {
1322
+ if (state === 0 && (this.cleared && this[kDelayed] <= 0 || override) || (this.aborted || state === 3) && override) {
1327
1323
  this.clearProcessTimeout();
1328
1324
  this[kDelayed] = Infinity;
1329
1325
  const resetState = () => {
1330
- this.finalizeState = 2 /* FINALIZE_STATE.END */;
1326
+ this.finalizeState = 2;
1331
1327
  this._pendingResult = null;
1332
1328
  };
1333
1329
  const aborted = (err) => {
1334
1330
  if (!this.restarting) {
1335
- this.writeFail(["Transaction was not completed" /* ERR_MESSAGE.INCOMPLETE */, this.baseDirectory], err);
1331
+ this.writeFail(["Transaction was not completed", this.baseDirectory], err);
1336
1332
  resetState();
1337
1333
  }
1338
1334
  else {
1339
- this.finalizeState = 4 /* FINALIZE_STATE.QUEUED */;
1335
+ this.finalizeState = 4;
1340
1336
  }
1341
1337
  this.emit('end', [], collectErrors.call(this), this.collectLog());
1342
1338
  if (!this.restarting) {
@@ -1347,16 +1343,16 @@ class FileManager extends core_1.Host {
1347
1343
  aborted((0, types_1.createAbortError)());
1348
1344
  return;
1349
1345
  }
1350
- this.finalizeState = 1 /* FINALIZE_STATE.COMMIT */;
1346
+ this.finalizeState = 1;
1351
1347
  this.finalize()
1352
1348
  .then(() => {
1353
1349
  const errors = collectErrors.call(this);
1354
1350
  const files = Array.from(this.files).sort((a, b) => {
1355
1351
  const sep = path.sep;
1356
- if (a.indexOf(sep) !== -1 && b.indexOf(sep) === -1) {
1352
+ if (a.includes(sep) && !b.includes(sep)) {
1357
1353
  return -1;
1358
1354
  }
1359
- if (a.indexOf(sep) === -1 && b.indexOf(sep) !== -1) {
1355
+ if (!a.includes(sep) && b.includes(sep)) {
1360
1356
  return 1;
1361
1357
  }
1362
1358
  return a < b ? -1 : 1;
@@ -1397,7 +1393,7 @@ class FileManager extends core_1.Host {
1397
1393
  file.uri = file.url.toString();
1398
1394
  }
1399
1395
  catch (err) {
1400
- this.writeFail(['Unable to parse URL', uri], err, 1024 /* LOG_TYPE.HTTP */);
1396
+ this.writeFail(['Unable to parse URL', uri], err, 1024);
1401
1397
  return { pathname: '', localUri: '' };
1402
1398
  }
1403
1399
  }
@@ -1421,7 +1417,7 @@ class FileManager extends core_1.Host {
1421
1417
  }
1422
1418
  }
1423
1419
  catch (err) {
1424
- this.writeFail(['Unable to resolve file location', uri], err, 32 /* LOG_TYPE.FILE */);
1420
+ this.writeFail(['Unable to resolve file location', uri], err, 32);
1425
1421
  return { pathname: '', localUri: '' };
1426
1422
  }
1427
1423
  }
@@ -1430,18 +1426,18 @@ class FileManager extends core_1.Host {
1430
1426
  let type;
1431
1427
  if (url) {
1432
1428
  if (url.protocol.startsWith('http')) {
1433
- type = 1 /* FETCH_TYPE.HTTP */;
1429
+ type = 1;
1434
1430
  }
1435
1431
  else if (file.socketPath && url.protocol === 'file:') {
1436
- type = 2 /* FETCH_TYPE.UNIX_SOCKET */;
1432
+ type = 2;
1437
1433
  }
1438
1434
  }
1439
1435
  if (!type && uri) {
1440
1436
  if (core_1.Host.isFile(uri, 'torrent')) {
1441
- type = 4 /* FETCH_TYPE.TORRENT */;
1437
+ type = 4;
1442
1438
  }
1443
1439
  else if (core_1.Host.isFile(uri, 's/ftp')) {
1444
- type = 3 /* FETCH_TYPE.FTP */;
1440
+ type = 3;
1445
1441
  }
1446
1442
  }
1447
1443
  file.fetchType = type;
@@ -1492,7 +1488,7 @@ class FileManager extends core_1.Host {
1492
1488
  sourceUTF8 = fs.readFileSync(uri, file.encoding);
1493
1489
  }
1494
1490
  catch (err) {
1495
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(uri)], err, 32 /* LOG_TYPE.FILE */);
1491
+ this.writeFail(["Unable to read file", path.basename(uri)], err, 32);
1496
1492
  }
1497
1493
  }
1498
1494
  if (sourceUTF8?.[0] === '\uFEFF' && file.encoding !== 'utf16le') {
@@ -1512,7 +1508,7 @@ class FileManager extends core_1.Host {
1512
1508
  return fs.readFileSync(uri);
1513
1509
  }
1514
1510
  catch (err) {
1515
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(uri)], err, 32 /* LOG_TYPE.FILE */);
1511
+ this.writeFail(["Unable to read file", path.basename(uri)], err, 32);
1516
1512
  }
1517
1513
  }
1518
1514
  return file.base64 ? Buffer.from(file.base64, 'base64') : null;
@@ -1614,7 +1610,7 @@ class FileManager extends core_1.Host {
1614
1610
  return file.buffer = buffer;
1615
1611
  }
1616
1612
  catch (err) {
1617
- this.writeFail(["Unable to write file" /* ERR_MESSAGE.WRITE_FILE */, path.basename(localUri)], err, 8192 /* LOG_TYPE.PERMISSION */);
1613
+ this.writeFail(["Unable to write file", path.basename(localUri)], err, 8192);
1618
1614
  }
1619
1615
  }
1620
1616
  return null;
@@ -1655,7 +1651,7 @@ class FileManager extends core_1.Host {
1655
1651
  fs.copyFileSync(localUri, output);
1656
1652
  }
1657
1653
  catch (err) {
1658
- this.writeFail(["Unable to copy file" /* ERR_MESSAGE.COPY_FILE */, path.basename(localUri)], err, 32 /* LOG_TYPE.FILE */);
1654
+ this.writeFail(["Unable to copy file", path.basename(localUri)], err, 32);
1659
1655
  return;
1660
1656
  }
1661
1657
  }
@@ -1685,7 +1681,7 @@ class FileManager extends core_1.Host {
1685
1681
  }
1686
1682
  }
1687
1683
  catch (err) {
1688
- this.writeFail(["Unable to read buffer" /* ERR_MESSAGE.READ_BUFFER */, path.basename(localUri)], err, 32 /* LOG_TYPE.FILE */);
1684
+ this.writeFail(["Unable to read buffer", path.basename(localUri)], err, 32);
1689
1685
  }
1690
1686
  if (rename) {
1691
1687
  if (!ext) {
@@ -1702,7 +1698,7 @@ class FileManager extends core_1.Host {
1702
1698
  }
1703
1699
  }
1704
1700
  catch (err) {
1705
- this.writeFail(["Unable to rename file" /* ERR_MESSAGE.RENAME_FILE */, path.basename(output)], err, 32 /* LOG_TYPE.FILE */);
1701
+ this.writeFail(["Unable to rename file", path.basename(output)], err, 32);
1706
1702
  }
1707
1703
  }
1708
1704
  }
@@ -1712,7 +1708,7 @@ class FileManager extends core_1.Host {
1712
1708
  }
1713
1709
  return mimeType;
1714
1710
  }
1715
- compressFile(file, overwrite = true) {
1711
+ async compressFile(file, overwrite = true) {
1716
1712
  const { localUri, compress } = file;
1717
1713
  const instance = this.Compress;
1718
1714
  if (instance && compress && localUri && (this.has(localUri) || (0, types_1.existsFlag)(file.flags))) {
@@ -1744,7 +1740,7 @@ class FileManager extends core_1.Host {
1744
1740
  config.timeout = this[kProcessTimeout].compress ?? PROCESS_TIMEOUT.compress;
1745
1741
  tasks.push(instance.tryFile(file.buffer || localUri, output, config, (err, result) => {
1746
1742
  if (err) {
1747
- this.writeFail(["Unable to compress file" /* ERR_MESSAGE.COMPRESS_FILE */, path.basename(localUri)], err, { type: 8 /* LOG_TYPE.COMPRESS */, startTime: config.startTime });
1743
+ this.writeFail(["Unable to compress file", path.basename(localUri)], err, { type: 8, startTime: config.startTime });
1748
1744
  }
1749
1745
  else if ((0, types_1.isString)(result)) {
1750
1746
  if (condition?.includes('%') && (0, lib_v4_1.getSize)(result) >= (0, lib_v4_1.getSize)(localUri)) {
@@ -1758,7 +1754,7 @@ class FileManager extends core_1.Host {
1758
1754
  }
1759
1755
  }
1760
1756
  catch (err) {
1761
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(output)], err, 32 /* LOG_TYPE.FILE */);
1757
+ this.writeFail(["Unable to read file", path.basename(output)], err, 32);
1762
1758
  }
1763
1759
  }
1764
1760
  }
@@ -1778,7 +1774,7 @@ class FileManager extends core_1.Host {
1778
1774
  file.mimeType = mimeType;
1779
1775
  data.mimeType = mimeType;
1780
1776
  }
1781
- const errorAsset = (instance, err, type = 4 /* LOG_TYPE.PROCESS */) => rejectModule.call(instance, err, type, path.basename(localUri));
1777
+ const errorAsset = (instance, err, type = 4) => rejectModule.call(instance, err, type, path.basename(localUri));
1782
1778
  if (file.tasks) {
1783
1779
  const taskName = [];
1784
1780
  for (const { task, handler: moduleName, preceding } of file.tasks) {
@@ -1827,7 +1823,7 @@ class FileManager extends core_1.Host {
1827
1823
  .then(() => this.closeThread(instance, data))
1828
1824
  .catch(err => {
1829
1825
  this.closeThread(instance, data);
1830
- errorAsset(instance, err, 2048 /* LOG_TYPE.IMAGE */);
1826
+ errorAsset(instance, err, 2048);
1831
1827
  });
1832
1828
  }
1833
1829
  }
@@ -1837,7 +1833,7 @@ class FileManager extends core_1.Host {
1837
1833
  }
1838
1834
  }
1839
1835
  catch (err) {
1840
- errorAsset(instance, err, 2048 /* LOG_TYPE.IMAGE */);
1836
+ errorAsset(instance, err, 2048);
1841
1837
  }
1842
1838
  }
1843
1839
  }
@@ -1917,7 +1913,7 @@ class FileManager extends core_1.Host {
1917
1913
  task();
1918
1914
  }
1919
1915
  catch (err) {
1920
- this.writeFail(["Unable to perform task" /* ERR_MESSAGE.PERFORM_TASK */, path.basename(this.getLocalUri(data))], err);
1916
+ this.writeFail(["Unable to perform task", path.basename(this.getLocalUri(data))], err);
1921
1917
  }
1922
1918
  this.removeAsyncTask();
1923
1919
  });
@@ -1987,14 +1983,14 @@ class FileManager extends core_1.Host {
1987
1983
  getDownload(type = 0) {
1988
1984
  return this[kDownloadStats][type];
1989
1985
  }
1990
- fetchObject(uri, options) {
1986
+ async fetchObject(uri, options) {
1991
1987
  if (!(0, types_1.isObject)(options)) {
1992
1988
  options = { format: options };
1993
1989
  }
1994
1990
  options.format || (options.format = 'json');
1995
- return this.fetchBuffer(uri, options).then(data => typeof data === 'object' ? data : null).catch(() => null);
1991
+ return this.Request.get(uri, options).then(data => typeof data === 'object' ? data : null);
1996
1992
  }
1997
- fetchBuffer(uri, options) {
1993
+ async fetchBuffer(uri, options) {
1998
1994
  if (options) {
1999
1995
  options.format = undefined;
2000
1996
  }
@@ -2012,14 +2008,14 @@ class FileManager extends core_1.Host {
2012
2008
  return buffer;
2013
2009
  });
2014
2010
  }
2015
- fetchFiles(uri, options) {
2011
+ async fetchFiles(uri, options) {
2016
2012
  if (!(0, types_1.isObject)(options)) {
2017
2013
  options = { pathname: options };
2018
2014
  }
2019
2015
  options.pathname || (options.pathname = this.baseDirectory);
2020
2016
  return this.Request.aria2c(uri, options);
2021
2017
  }
2022
- start(emptyDir) {
2018
+ async start(emptyDir) {
2023
2019
  const listener = (resolve) => {
2024
2020
  const callback = (files, errors, status) => {
2025
2021
  if (!this.restarting) {
@@ -2048,19 +2044,19 @@ class FileManager extends core_1.Host {
2048
2044
  });
2049
2045
  }
2050
2046
  switch (this.finalizeState) {
2051
- case 0 /* FINALIZE_STATE.READY */:
2047
+ case 0:
2052
2048
  if (this.delayed === 0 && !this.cleared) {
2053
2049
  break;
2054
2050
  }
2055
- case 1 /* FINALIZE_STATE.COMMIT */:
2056
- case 3 /* FINALIZE_STATE.RESTART */:
2057
- case 5 /* FINALIZE_STATE.RESTARTED */:
2058
- case 4 /* FINALIZE_STATE.QUEUED */:
2051
+ case 1:
2052
+ case 3:
2053
+ case 5:
2054
+ case 4:
2059
2055
  if (this._pendingResult) {
2060
2056
  return this._pendingResult;
2061
2057
  }
2062
- this.finalizeState = 0 /* FINALIZE_STATE.READY */;
2063
- case 2 /* FINALIZE_STATE.END */:
2058
+ this.finalizeState = 0;
2059
+ case 2:
2064
2060
  resetAssets.call(this);
2065
2061
  break;
2066
2062
  }
@@ -2080,14 +2076,14 @@ class FileManager extends core_1.Host {
2080
2076
  abortedHost.call(this);
2081
2077
  return;
2082
2078
  }
2083
- if (this.finalizeState === 5 /* FINALIZE_STATE.RESTARTED */) {
2079
+ if (this.finalizeState === 5) {
2084
2080
  this.restarting = false;
2085
2081
  }
2086
2082
  else if (this._pendingResult) {
2087
2083
  return;
2088
2084
  }
2089
2085
  if (!this.canWrite(this.baseDirectory, { ownPermissionOnly: true })) {
2090
- this.writeFail("Unsupported access" /* ERR_MESSAGE.UNSUPPORTED_ACCESS */, new Error(this.baseDirectory), 8192 /* LOG_TYPE.PERMISSION */);
2086
+ this.writeFail("Unsupported access", new Error(this.baseDirectory), 8192);
2091
2087
  this.cleared = true;
2092
2088
  if (this.queued) {
2093
2089
  this.joinQueue({ reject: true });
@@ -2095,15 +2091,15 @@ class FileManager extends core_1.Host {
2095
2091
  return;
2096
2092
  }
2097
2093
  switch (this.finalizeState) {
2098
- case 0 /* FINALIZE_STATE.READY */:
2094
+ case 0:
2099
2095
  if (this.delayed === 0 && !this.cleared) {
2100
2096
  break;
2101
2097
  }
2102
- case 1 /* FINALIZE_STATE.COMMIT */:
2103
- case 3 /* FINALIZE_STATE.RESTART */:
2104
- case 4 /* FINALIZE_STATE.QUEUED */:
2098
+ case 1:
2099
+ case 3:
2100
+ case 4:
2105
2101
  return;
2106
- case 2 /* FINALIZE_STATE.END */:
2102
+ case 2:
2107
2103
  resetAssets.call(this);
2108
2104
  break;
2109
2105
  }
@@ -2114,7 +2110,7 @@ class FileManager extends core_1.Host {
2114
2110
  args[i] = arguments[i];
2115
2111
  }
2116
2112
  if (this.joinQueue({ args })) {
2117
- this.finalizeState = 4 /* FINALIZE_STATE.QUEUED */;
2113
+ this.finalizeState = 4;
2118
2114
  return;
2119
2115
  }
2120
2116
  }
@@ -2124,7 +2120,7 @@ class FileManager extends core_1.Host {
2124
2120
  this.clearProcessTimeout();
2125
2121
  this[KTimerMain] = setInterval(() => {
2126
2122
  const { processing, processTimeout, finalizeState } = this;
2127
- if (finalizeState === 4 /* FINALIZE_STATE.QUEUED */) {
2123
+ if (finalizeState === 4) {
2128
2124
  return;
2129
2125
  }
2130
2126
  const currentTime = Date.now();
@@ -2157,7 +2153,7 @@ class FileManager extends core_1.Host {
2157
2153
  this.deleteFile(localUri, { id: file.id, emptyDir: true, all: true });
2158
2154
  }
2159
2155
  }
2160
- (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 });
2156
+ (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 });
2161
2157
  processing.splice(i--, 1);
2162
2158
  aborted = true;
2163
2159
  }
@@ -2243,11 +2239,11 @@ class FileManager extends core_1.Host {
2243
2239
  if (bundleIndex > 0) {
2244
2240
  items[bundleIndex - 1] = file;
2245
2241
  let url, parent;
2246
- 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))) {
2242
+ if (file.fetchType === 1 && (cacheToDisk.has(url = file.url) || cacheToMemory.has(url)) && (parent = assets.find(item => item.bundleIndex === 0 && item.bundleId === bundleId))) {
2247
2243
  (parent.bundleQueue || (parent.bundleQueue = [])).push(new Promise(resolve => {
2248
2244
  this.Request.open(url, { method: 'HEAD', httpVersion: 1 })
2249
2245
  .on('response', res => {
2250
- if (res.statusCode < 300 /* HTTP_STATUS.MULTIPLE_CHOICES */) {
2246
+ if (res.statusCode < 300) {
2251
2247
  applyHeaders(file, res.headers);
2252
2248
  }
2253
2249
  resolve(file);
@@ -2311,7 +2307,7 @@ class FileManager extends core_1.Host {
2311
2307
  }
2312
2308
  catch (err) {
2313
2309
  items.forEach(queue => queue.invalid = true);
2314
- 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 */);
2310
+ this.writeFail([buffer ? "Unable to write buffer" : "Unable to copy file", path.basename(file.localUri)], err, 32);
2315
2311
  }
2316
2312
  }
2317
2313
  };
@@ -2361,7 +2357,7 @@ class FileManager extends core_1.Host {
2361
2357
  checkEtag = false;
2362
2358
  }
2363
2359
  else if (uri) {
2364
- if (type === 1 /* FETCH_TYPE.HTTP */ || type === 2 /* FETCH_TYPE.UNIX_SOCKET */) {
2360
+ if (type === 1 || type === 2) {
2365
2361
  const url = queue.url;
2366
2362
  const options = {
2367
2363
  url,
@@ -2369,7 +2365,7 @@ class FileManager extends core_1.Host {
2369
2365
  statusMessage: uri + ` (${queue.bundleIndex})`
2370
2366
  };
2371
2367
  let etag, pipeTo;
2372
- if (type === 2 /* FETCH_TYPE.UNIX_SOCKET */) {
2368
+ if (type === 2) {
2373
2369
  options.socketPath = queue.socketPath;
2374
2370
  options.httpVersion = 1;
2375
2371
  }
@@ -2455,7 +2451,7 @@ class FileManager extends core_1.Host {
2455
2451
  const pathname = this.getTempDir({ uuidDir: true });
2456
2452
  if (!pathname || !mimeType) {
2457
2453
  queue.invalid = true;
2458
- 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)));
2454
+ tasks.push(Promise.reject(!pathname ? new Error("Unable to create temp directory") : (0, types_1.errorValue)("MIME not found", uri)));
2459
2455
  break;
2460
2456
  }
2461
2457
  tasks.push(this.fetchFiles(queue.url || uri, { pathname, binOpts: queue.binOpts || file.binOpts })
@@ -2493,7 +2489,7 @@ class FileManager extends core_1.Host {
2493
2489
  success = await Promise.all(tasks)
2494
2490
  .then(() => true)
2495
2491
  .catch(err => {
2496
- this.writeFail(["Unable to download file" /* ERR_MESSAGE.DOWNLOAD_FILE */, 'bundle: ' + path.basename(localUri)], err, 1024 /* LOG_TYPE.HTTP */);
2492
+ this.writeFail(["Unable to download file", 'bundle: ' + path.basename(localUri)], err, 1024);
2497
2493
  return false;
2498
2494
  });
2499
2495
  }
@@ -2559,10 +2555,10 @@ class FileManager extends core_1.Host {
2559
2555
  if (!preceding) {
2560
2556
  this.completeAsyncTask();
2561
2557
  }
2562
- 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 */);
2558
+ this.writeFail(["Unable to download file", uri], err, err instanceof Error && err.message.startsWith("Timeout was exceeded") ? 16384 : 1024);
2563
2559
  };
2564
2560
  const errorPermission = (file) => {
2565
- 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 */);
2561
+ this.writeFail(["Unable to read file", file.uri], (0, types_1.errorValue)('Operation not permitted', file.uri || "Unknown"), 8192);
2566
2562
  file.invalid = true;
2567
2563
  };
2568
2564
  const createFolder = (file, pathname) => {
@@ -2575,7 +2571,7 @@ class FileManager extends core_1.Host {
2575
2571
  }
2576
2572
  else {
2577
2573
  file.invalid = true;
2578
- this.writeFail("Unable to create directory" /* ERR_MESSAGE.CREATE_DIRECTORY */, (0, types_1.errorValue)('Path not found', pathname));
2574
+ this.writeFail("Unable to create directory", (0, types_1.errorValue)('Path not found', pathname));
2579
2575
  return false;
2580
2576
  }
2581
2577
  }
@@ -2655,7 +2651,7 @@ class FileManager extends core_1.Host {
2655
2651
  }
2656
2652
  return false;
2657
2653
  };
2658
- if ((!etag || item.fetchType === 1 /* FETCH_TYPE.HTTP */ && ((0, types_1.isEmpty)(bundleId) || bundleIndex <= 0)) && (!watch || !item.watch || setBuffer(item))) {
2654
+ if ((!etag || item.fetchType === 1 && ((0, types_1.isEmpty)(bundleId) || bundleIndex <= 0)) && (!watch || !item.watch || setBuffer(item))) {
2659
2655
  let childBundle, childDownload;
2660
2656
  if (!(0, types_1.isEmpty)(bundleId) && bundleIndex > 0) {
2661
2657
  const target = assets.find(parent => parent.bundleId === bundleId && parent.bundleIndex === 0);
@@ -2691,8 +2687,8 @@ class FileManager extends core_1.Host {
2691
2687
  setBuffer(item);
2692
2688
  }
2693
2689
  if (core_1.Host.isPath(localUri)) {
2694
- item.flags |= 128 /* ASSET_FLAG.EXISTS */;
2695
- if (!etag || item.fetchType !== 1 /* FETCH_TYPE.HTTP */) {
2690
+ item.flags |= 128;
2691
+ if (!etag || item.fetchType !== 1) {
2696
2692
  if (!(0, types_1.isEmpty)(bundleId) && bundleIndex === 0) {
2697
2693
  assets.filter(child => child.bundleId === bundleId && child.bundleIndex > 0).forEach(child => {
2698
2694
  setBuffer(child);
@@ -2784,10 +2780,10 @@ class FileManager extends core_1.Host {
2784
2780
  continue;
2785
2781
  }
2786
2782
  const checkDest = (src) => staging || !(0, lib_v4_1.hasSameStat)(src, localUri);
2787
- const type = item.fetchType || 0 /* FETCH_TYPE.UNKNOWN */;
2783
+ const type = item.fetchType || 0;
2788
2784
  const bundleMain = !(0, types_1.isEmpty)(item.bundleId) && item.bundleIndex === 0;
2789
- const isHttp = type === 1 /* FETCH_TYPE.HTTP */;
2790
- if (isHttp || type === 2 /* FETCH_TYPE.UNIX_SOCKET */) {
2785
+ const isHttp = type === 1;
2786
+ if (isHttp || type === 2) {
2791
2787
  let checkEtag;
2792
2788
  if ((0, types_1.isEmpty)(item.bundleId) && bundling[uri]) {
2793
2789
  bundling[uri].push(item);
@@ -2816,7 +2812,7 @@ class FileManager extends core_1.Host {
2816
2812
  const closeResponse = () => client?.destroy();
2817
2813
  const downloadUri = (request, etagDir) => {
2818
2814
  if (checkEtag) {
2819
- item.flags &= ~128 /* ASSET_FLAG.EXISTS */;
2815
+ item.flags &= ~128;
2820
2816
  }
2821
2817
  closeResponse();
2822
2818
  const location = request.url.toString();
@@ -2833,6 +2829,7 @@ class FileManager extends core_1.Host {
2833
2829
  }
2834
2830
  else {
2835
2831
  request.socketPath = item.socketPath;
2832
+ request.method = undefined;
2836
2833
  request.httpVersion = 1;
2837
2834
  }
2838
2835
  this.fetchBuffer(request.url, request)
@@ -2867,7 +2864,7 @@ class FileManager extends core_1.Host {
2867
2864
  (client = request.open(href, target))
2868
2865
  .on('response', res => {
2869
2866
  const statusCode = res.statusCode;
2870
- if (statusCode < 300 /* HTTP_STATUS.MULTIPLE_CHOICES */) {
2867
+ if (statusCode < 300) {
2871
2868
  const etag = applyHeaders(item, res.headers, false, mainEtag);
2872
2869
  let tempDir, etagDir;
2873
2870
  if (etag) {
@@ -2939,7 +2936,7 @@ class FileManager extends core_1.Host {
2939
2936
  fs.writeFileSync(localUri, buffer);
2940
2937
  this.addDownload(Buffer.byteLength(buffer, encoding), types_1.DOWNLOAD_TYPE.CACHE);
2941
2938
  if (checkEtag) {
2942
- item.flags &= ~128 /* ASSET_FLAG.EXISTS */;
2939
+ item.flags &= ~128;
2943
2940
  }
2944
2941
  fileReceived(item, localUri, null, true);
2945
2942
  closeResponse();
@@ -2955,7 +2952,7 @@ class FileManager extends core_1.Host {
2955
2952
  }
2956
2953
  downloadUri(target, etagDir);
2957
2954
  }
2958
- else if (statusCode < 400 /* HTTP_STATUS.BAD_REQUEST */) {
2955
+ else if (statusCode < 400) {
2959
2956
  closeResponse();
2960
2957
  const location = res.headers.location;
2961
2958
  if (location && ++redirects <= HTTP_CLIENT.redirectLimit) {
@@ -3001,7 +2998,7 @@ class FileManager extends core_1.Host {
3001
2998
  }
3002
2999
  else if (type) {
3003
3000
  if (bundleMain && !item.mimeType) {
3004
- errorRequest(item, (0, types_1.errorValue)("MIME not found" /* ERR_MESSAGE.NOTFOUND_MIME */, uri), true);
3001
+ errorRequest(item, (0, types_1.errorValue)("MIME not found", uri), true);
3005
3002
  }
3006
3003
  else if (!checkQueue(item, localUri, pathname, false)) {
3007
3004
  if (downloading[uri]) {
@@ -3039,7 +3036,7 @@ class FileManager extends core_1.Host {
3039
3036
  found = true;
3040
3037
  }
3041
3038
  catch (err) {
3042
- this.writeFail(["Unable to rename file" /* ERR_MESSAGE.RENAME_FILE */, item.filename], err, 32 /* LOG_TYPE.FILE */);
3039
+ this.writeFail(["Unable to rename file", item.filename], err, 32);
3043
3040
  }
3044
3041
  }
3045
3042
  else {
@@ -3121,7 +3118,7 @@ class FileManager extends core_1.Host {
3121
3118
  item.buffer = result;
3122
3119
  }
3123
3120
  })
3124
- .catch(err => this.writeFail(["Unable to compress file" /* ERR_MESSAGE.COMPRESS_FILE */, path.basename(file)], err, { type: 8 /* LOG_TYPE.COMPRESS */, startTime: options.startTime })));
3121
+ .catch(err => this.writeFail(["Unable to compress file", path.basename(file)], err, { type: 8, startTime: options.startTime })));
3125
3122
  }
3126
3123
  }
3127
3124
  }
@@ -3132,7 +3129,7 @@ class FileManager extends core_1.Host {
3132
3129
  async finalizeDocument() {
3133
3130
  for (const { instance, constructor } of this.Document) {
3134
3131
  if (constructor.finalize && instance.assets.length) {
3135
- await constructor.finalize.call(this, instance).catch(err => rejectModule.call(instance, err, 4 /* LOG_TYPE.PROCESS */));
3132
+ await constructor.finalize.call(this, instance).catch(err => rejectModule.call(instance, err, 4));
3136
3133
  if (this.aborted) {
3137
3134
  return;
3138
3135
  }
@@ -3144,7 +3141,7 @@ class FileManager extends core_1.Host {
3144
3141
  for (const { instance, constructor } of this.Task) {
3145
3142
  const items = assets.filter(item => item.tasks.find(data => data.handler === instance.moduleName));
3146
3143
  if (items.length) {
3147
- await (constructor.using || constructor.finalize).call(this, instance, items).catch(err => rejectModule.call(instance, err, 4 /* LOG_TYPE.PROCESS */));
3144
+ await (constructor.using || constructor.finalize).call(this, instance, items).catch(err => rejectModule.call(instance, err, 4));
3148
3145
  if (this.aborted) {
3149
3146
  return;
3150
3147
  }
@@ -3152,9 +3149,9 @@ class FileManager extends core_1.Host {
3152
3149
  }
3153
3150
  }
3154
3151
  }
3155
- finalizeCloud() {
3152
+ async finalizeCloud() {
3156
3153
  const cloud = this.Cloud;
3157
- return cloud ? cloud_1.default.finalize.call(this, cloud).catch(err => rejectModule.call(cloud, err, 64 /* LOG_TYPE.CLOUD */)) : Promise.resolve();
3154
+ return cloud ? cloud_1.default.finalize.call(this, cloud).catch(err => rejectModule.call(cloud, err, 64)) : Promise.resolve();
3158
3155
  }
3159
3156
  async finalizeCleanup() {
3160
3157
  if (this.Compress) {
@@ -3175,7 +3172,7 @@ class FileManager extends core_1.Host {
3175
3172
  }
3176
3173
  for (const { instance, constructor } of this.Document) {
3177
3174
  if (constructor.cleanup && instance.assets.length) {
3178
- await constructor.cleanup.call(this, instance).catch(err => rejectModule.call(instance, err, 4 /* LOG_TYPE.PROCESS */));
3175
+ await constructor.cleanup.call(this, instance).catch(err => rejectModule.call(instance, err, 4));
3179
3176
  }
3180
3177
  }
3181
3178
  }
@@ -3213,11 +3210,11 @@ class FileManager extends core_1.Host {
3213
3210
  }
3214
3211
  }
3215
3212
  removeFiles();
3216
- await this.finalizeCompress(this.assets.filter(item => item.compress && !ignoreAsset(item))).catch(err => rejectModule.call(this, err, 8 /* LOG_TYPE.COMPRESS */));
3213
+ await this.finalizeCompress(this.assets.filter(item => item.compress && !ignoreAsset(item))).catch(err => rejectModule.call(this, err, 8));
3217
3214
  if (this.aborted) {
3218
3215
  return Promise.reject((0, types_1.createAbortError)());
3219
3216
  }
3220
- await this.finalizeDocument().catch(err => rejectModule.call(this, err, 4 /* LOG_TYPE.PROCESS */));
3217
+ await this.finalizeDocument().catch(err => rejectModule.call(this, err, 4));
3221
3218
  if (this.aborted) {
3222
3219
  return Promise.reject((0, types_1.createAbortError)());
3223
3220
  }
@@ -3227,29 +3224,29 @@ class FileManager extends core_1.Host {
3227
3224
  fs.writeFileSync(item.localUri, item.sourceUTF8, item.encoding || (item.encoding = 'utf-8'));
3228
3225
  }
3229
3226
  catch (err) {
3230
- this.writeFail(["Unable to write file" /* ERR_MESSAGE.WRITE_FILE */, path.basename(item.localUri)], err, { type: 32 /* LOG_TYPE.FILE */, startTime });
3227
+ this.writeFail(["Unable to write file", path.basename(item.localUri)], err, { type: 32, startTime });
3231
3228
  }
3232
3229
  }
3233
3230
  }
3234
3231
  removeFiles();
3235
- 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 */));
3232
+ 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));
3236
3233
  if (this.aborted) {
3237
3234
  return Promise.reject((0, types_1.createAbortError)());
3238
3235
  }
3239
3236
  removeFiles();
3240
- await this.finalizeCloud().catch(err => rejectModule.call(this, err, 64 /* LOG_TYPE.CLOUD */));
3237
+ await this.finalizeCloud().catch(err => rejectModule.call(this, err, 64));
3241
3238
  if (this.aborted) {
3242
3239
  return Promise.reject((0, types_1.createAbortError)());
3243
3240
  }
3244
3241
  removeFiles();
3245
- await this.finalizeCleanup().catch(err => rejectModule.call(this, err, 1 /* LOG_TYPE.SYSTEM */));
3242
+ await this.finalizeCleanup().catch(err => rejectModule.call(this, err, 1));
3246
3243
  removeFiles();
3247
3244
  if (LOG_TIMEELAPSED) {
3248
3245
  const [h, d, c] = this[kDownloadStats];
3249
3246
  const errorCount = this.errorCount;
3250
3247
  const message = [];
3251
3248
  if (errorCount) {
3252
- message.push('ERROR ' + errorCount); // eslint-disable-line @typescript-eslint/no-base-to-string
3249
+ message.push('ERROR ' + errorCount);
3253
3250
  }
3254
3251
  let [size, count] = h;
3255
3252
  if (count) {
@@ -3275,7 +3272,7 @@ class FileManager extends core_1.Host {
3275
3272
  this.Request.close();
3276
3273
  }
3277
3274
  set restarting(value) {
3278
- this.finalizeState = (this[kRestarting] = value) ? 3 /* FINALIZE_STATE.RESTART */ : 0 /* FINALIZE_STATE.READY */;
3275
+ this.finalizeState = (this[kRestarting] = value) ? 3 : 0;
3279
3276
  }
3280
3277
  get restarting() {
3281
3278
  return this[kRestarting];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/file-manager",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "FileManager constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,17 +17,17 @@
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.6.0",
24
- "@e-mc/compress": "0.6.0",
25
- "@e-mc/core": "0.6.0",
26
- "@e-mc/document": "0.6.0",
27
- "@e-mc/image": "0.6.0",
28
- "@e-mc/request": "0.6.0",
29
- "@e-mc/task": "0.6.0",
30
- "@e-mc/types": "0.6.0",
31
- "@e-mc/watch": "0.6.0"
23
+ "@e-mc/cloud": "0.6.2",
24
+ "@e-mc/compress": "0.6.2",
25
+ "@e-mc/core": "0.6.2",
26
+ "@e-mc/document": "0.6.2",
27
+ "@e-mc/image": "0.6.2",
28
+ "@e-mc/request": "0.6.2",
29
+ "@e-mc/task": "0.6.2",
30
+ "@e-mc/types": "0.6.2",
31
+ "@e-mc/watch": "0.6.2"
32
32
  }
33
33
  }