@e-mc/file-manager 0.10.6 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +22 -21
- package/index.js +202 -187
- package/package.json +12 -13
package/LICENSE
CHANGED
|
@@ -8,4 +8,4 @@ Redistribution and use in source and binary forms, with or without modification,
|
|
|
8
8
|
|
|
9
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
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.
|
|
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,7 +1,7 @@
|
|
|
1
1
|
# @e-mc/file-manager
|
|
2
2
|
|
|
3
|
-
* NodeJS 16
|
|
4
|
-
*
|
|
3
|
+
* NodeJS 16 LTS
|
|
4
|
+
* ES2021
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
7
7
|
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.11.1/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { DataSource, IncrementalMatch, TaskAction } from "./squared";
|
|
16
16
|
|
|
17
|
-
import type { DocumentConstructor, HostConstructor, ICloud, ICompress, IDocument, IHost, IImage, IModule, IRequest, ITask, ImageConstructor, TaskConstructor,
|
|
17
|
+
import type { DocumentConstructor, HostConstructor, ICloud, ICompress, IDocument, IHost, IImage, IModule, IRequest, ITask, IWatch, ImageConstructor, TaskConstructor, WatchConstructor } from "./index";
|
|
18
18
|
import type { ExternalAsset, FileCommand, FileData, IFileThread, OutputFinalize } from "./asset";
|
|
19
19
|
import type { IPermission, PermissionReadWrite } from "./core";
|
|
20
20
|
import type { AssetContentOptions, ChecksumOptions, DeleteFileAddendum, FileOutput, FinalizeResult, FindAssetOptions, IHttpDiskCache, IHttpMemoryCache, ImageMimeMap, InstallData, PostFinalizeCallback, ReplaceOptions } from "./filemanager";
|
|
@@ -24,13 +24,11 @@ import type { RequestData, Settings } from "./node";
|
|
|
24
24
|
import type { Aria2Options, BufferFormat, OpenOptions } from "./request";
|
|
25
25
|
import type { CloudModule, CompressModule, DbModule, DocumentModule, HttpConnectSettings, HttpMemorySettings, ImageModule, RequestModule, TaskModule, WatchModule } from "./settings";
|
|
26
26
|
|
|
27
|
-
import type { SpawnOptions } from "child_process";
|
|
28
|
-
import type { NoParamCallback } from "fs";
|
|
27
|
+
import type { SpawnOptions } from "node:child_process";
|
|
28
|
+
import type { NoParamCallback } from "node:fs";
|
|
29
29
|
|
|
30
30
|
interface IFileManager extends IHost, Set<string> {
|
|
31
31
|
processTimeout: number;
|
|
32
|
-
cacheToDisk: IHttpDiskCache<ExternalAsset>;
|
|
33
|
-
cacheToMemory: IHttpMemoryCache<ExternalAsset>;
|
|
34
32
|
Request: IRequest;
|
|
35
33
|
Document: InstallData<IDocument<IFileManager, ExternalAsset>, DocumentConstructor<IFileManager, ExternalAsset>>[];
|
|
36
34
|
Task: InstallData<ITask, TaskConstructor>[];
|
|
@@ -51,6 +49,8 @@ interface IFileManager extends IHost, Set<string> {
|
|
|
51
49
|
readonly fetchedAssets: ExternalAsset[];
|
|
52
50
|
readonly copiedAssets: ExternalAsset[];
|
|
53
51
|
readonly emptyDir: Set<string>;
|
|
52
|
+
readonly cacheToDisk: IHttpDiskCache<ExternalAsset>;
|
|
53
|
+
readonly cacheToMemory: IHttpMemoryCache<ExternalAsset>;
|
|
54
54
|
install(name: "document", handler: string, module?: DocumentModule, ...args: unknown[]): IDocument | undefined;
|
|
55
55
|
install(name: "document", target: DocumentConstructor, module?: DocumentModule, ...args: unknown[]): IDocument | undefined;
|
|
56
56
|
install(name: "task", handler: string, module?: TaskModule, ...args: unknown[]): ITask | undefined;
|
|
@@ -60,8 +60,9 @@ interface IFileManager extends IHost, Set<string> {
|
|
|
60
60
|
install(name: "image", handler: string, module?: ImageModule, ...args: unknown[]): IImage | undefined;
|
|
61
61
|
install(name: "image", target: ImageConstructor, module?: ImageModule, ...args: unknown[]): IImage | undefined;
|
|
62
62
|
install(name: "image", targets: Map<string, ImageConstructor>, module?: ImageModule): void;
|
|
63
|
-
install(name: "watch", module:
|
|
64
|
-
install(name: "watch",
|
|
63
|
+
install(name: "watch", handler: string, module?: WatchModule, ...args: unknown[]): IWatch | undefined;
|
|
64
|
+
install(name: "watch", target: WatchConstructor, module?: WatchModule, ...args: unknown[]): IWatch | undefined;
|
|
65
|
+
install(name: "watch", module: WatchModule): IWatch | undefined;
|
|
65
66
|
install(name: "compress", module?: CompressModule): ICompress | undefined;
|
|
66
67
|
install(name: string, ...args: unknown[]): IModule | undefined;
|
|
67
68
|
using(...items: ExternalAsset[] | [boolean, ...ExternalAsset[]]): this;
|
|
@@ -69,7 +70,7 @@ interface IFileManager extends IHost, Set<string> {
|
|
|
69
70
|
removeCwd(value: unknown): string;
|
|
70
71
|
findAsset(value: string | URL, instance?: IModule | FindAssetOptions<ExternalAsset>): ExternalAsset | undefined;
|
|
71
72
|
removeAsset(file: ExternalAsset): boolean;
|
|
72
|
-
replace(file: ExternalAsset, replaceWith: string, mimeType:
|
|
73
|
+
replace(file: ExternalAsset, replaceWith: string, mimeType: string | undefined): boolean;
|
|
73
74
|
replace(file: ExternalAsset, replaceWith: string, options?: ReplaceOptions): boolean;
|
|
74
75
|
rename(file: ExternalAsset, value: string): boolean;
|
|
75
76
|
performAsyncTask(): void;
|
|
@@ -305,18 +306,18 @@ NOTE: **FileManager** is a sub-class of [Host](https://www.npmjs.com/package/@e-
|
|
|
305
306
|
|
|
306
307
|
## References
|
|
307
308
|
|
|
308
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
309
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
310
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
311
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
312
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
313
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
314
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
315
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
316
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
309
|
+
- https://www.unpkg.com/@e-mc/types@0.11.1/lib/squared.d.ts
|
|
310
|
+
- https://www.unpkg.com/@e-mc/types@0.11.1/lib/asset.d.ts
|
|
311
|
+
- https://www.unpkg.com/@e-mc/types@0.11.1/lib/core.d.ts
|
|
312
|
+
- https://www.unpkg.com/@e-mc/types@0.11.1/lib/filemanager.d.ts
|
|
313
|
+
- https://www.unpkg.com/@e-mc/types@0.11.1/lib/logger.d.ts
|
|
314
|
+
- https://www.unpkg.com/@e-mc/types@0.11.1/lib/module.d.ts
|
|
315
|
+
- https://www.unpkg.com/@e-mc/types@0.11.1/lib/node.d.ts
|
|
316
|
+
- https://www.unpkg.com/@e-mc/types@0.11.1/lib/request.d.ts
|
|
317
|
+
- https://www.unpkg.com/@e-mc/types@0.11.1/lib/settings.d.ts
|
|
317
318
|
|
|
318
319
|
* https://www.npmjs.com/package/@types/node
|
|
319
320
|
|
|
320
321
|
## LICENSE
|
|
321
322
|
|
|
322
|
-
BSD 3-Clause
|
|
323
|
+
BSD 3-Clause
|
package/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const stream = require("stream");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const stream = require("node:stream");
|
|
6
6
|
const pm = require("picomatch");
|
|
7
7
|
const diff = require("diff");
|
|
8
8
|
const chalk = require("chalk");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const node_url_1 = require("node:url");
|
|
10
|
+
const node_util_1 = require("node:util");
|
|
11
11
|
const types_1 = require("@e-mc/types");
|
|
12
12
|
const core_1 = require("@e-mc/core");
|
|
13
13
|
const asset_1 = require("@e-mc/document/asset");
|
|
@@ -40,7 +40,7 @@ const PROCESS_STDOUT = process.stdout;
|
|
|
40
40
|
const PROCESS_STDIN = process.stdin;
|
|
41
41
|
const STDOUT_CURSOR = typeof PROCESS_STDOUT.moveCursor === 'function';
|
|
42
42
|
const PROCESS_TIMEOUT = { filemanager: 0, compress: 0 };
|
|
43
|
-
const CACHE_ETAG =
|
|
43
|
+
const CACHE_ETAG = new Map();
|
|
44
44
|
const DISK = {
|
|
45
45
|
ENABLED: false,
|
|
46
46
|
EXPIRES: 0,
|
|
@@ -50,9 +50,8 @@ const DISK = {
|
|
|
50
50
|
};
|
|
51
51
|
const MEMORY = {
|
|
52
52
|
ENABLED: false,
|
|
53
|
-
CACHE:
|
|
53
|
+
CACHE: new Map(),
|
|
54
54
|
SIZE: 0,
|
|
55
|
-
TOTAL: 0,
|
|
56
55
|
EXPIRES: 0,
|
|
57
56
|
LIMIT: (0, types_1.formatSize)("100mb"),
|
|
58
57
|
LIMIT_ALL: (0, types_1.formatSize)("512mb"),
|
|
@@ -87,7 +86,7 @@ let SESSION_ID = 0;
|
|
|
87
86
|
let SESSION_LIMIT = 1000;
|
|
88
87
|
let ASSET_ID = 0;
|
|
89
88
|
let RECURSION_LIMIT = 10;
|
|
90
|
-
let PROCESS_SUB_LIMIT = Math.max(require('os').cpus().length, 1) * 2;
|
|
89
|
+
let PROCESS_SUB_LIMIT = Math.max(require('node:os').cpus().length, 1) * 2;
|
|
91
90
|
let LOG_TIMEELAPSED = true;
|
|
92
91
|
let LOG_TIMEPROCESS = true;
|
|
93
92
|
const HTTP_CLIENT = {
|
|
@@ -136,7 +135,7 @@ function unsetContent(item) {
|
|
|
136
135
|
item.buffer = null;
|
|
137
136
|
}
|
|
138
137
|
if ('sourceUTF8' in item) {
|
|
139
|
-
item.sourceUTF8 =
|
|
138
|
+
item.sourceUTF8 = undefined;
|
|
140
139
|
}
|
|
141
140
|
}
|
|
142
141
|
function bundleTorrent(host, files, mimeType, encoding) {
|
|
@@ -217,24 +216,33 @@ function checkHash(host, localUri, output, options, data) {
|
|
|
217
216
|
}
|
|
218
217
|
return true;
|
|
219
218
|
}
|
|
220
|
-
function validatePaths(values, patterns, include, dot) {
|
|
221
|
-
const items = patterns.map(value =>
|
|
219
|
+
function validatePaths(rootDir, values, patterns, include, dot) {
|
|
220
|
+
const items = patterns.map(value => {
|
|
221
|
+
let invert = false;
|
|
222
|
+
if (!include && value.startsWith('!')) {
|
|
223
|
+
value = value.substring(1);
|
|
224
|
+
invert = true;
|
|
225
|
+
}
|
|
226
|
+
const matchBase = !isMatchRoot(value = core_1.Permission.toPosix(value));
|
|
227
|
+
return [pm(value, { posixSlashes: true, windows: true, nocase: core_1.Host.PLATFORM_WIN32, dot, matchBase }), path.isAbsolute(value), invert];
|
|
228
|
+
});
|
|
222
229
|
return values.filter(value => {
|
|
223
|
-
for (const [pattern,
|
|
224
|
-
if (
|
|
225
|
-
return include;
|
|
230
|
+
for (const [pattern, absolute, invert] of items) {
|
|
231
|
+
if (pattern(absolute ? value : value.substring(rootDir.length))) {
|
|
232
|
+
return invert ? !include : include;
|
|
226
233
|
}
|
|
227
234
|
}
|
|
228
235
|
return !include;
|
|
229
236
|
});
|
|
230
237
|
}
|
|
231
|
-
function filterPaths(values, include, exclude, dot) {
|
|
238
|
+
function filterPaths(rootDir, values, include, exclude, dot) {
|
|
239
|
+
rootDir = core_1.Host.normalizePath(rootDir, 2);
|
|
232
240
|
if (include) {
|
|
233
241
|
if ((0, types_1.isString)(include)) {
|
|
234
242
|
include = [include];
|
|
235
243
|
}
|
|
236
244
|
if ((0, types_1.isArray)(include)) {
|
|
237
|
-
|
|
245
|
+
values = validatePaths(rootDir, values, include, true, dot);
|
|
238
246
|
}
|
|
239
247
|
}
|
|
240
248
|
if (exclude) {
|
|
@@ -242,7 +250,7 @@ function filterPaths(values, include, exclude, dot) {
|
|
|
242
250
|
exclude = [exclude];
|
|
243
251
|
}
|
|
244
252
|
if ((0, types_1.isArray)(exclude)) {
|
|
245
|
-
return validatePaths(values, exclude, false, dot);
|
|
253
|
+
return validatePaths(rootDir, values, exclude, false, dot);
|
|
246
254
|
}
|
|
247
255
|
}
|
|
248
256
|
return values;
|
|
@@ -395,7 +403,7 @@ function clearQueue(data, attr) {
|
|
|
395
403
|
}
|
|
396
404
|
}
|
|
397
405
|
function hasEtag(item, cacheable, fallback) {
|
|
398
|
-
if (!cacheable || !(0, types_1.existsFlag)(item
|
|
406
|
+
if (!cacheable || !(0, types_1.existsFlag)(item)) {
|
|
399
407
|
return false;
|
|
400
408
|
}
|
|
401
409
|
switch (item.incremental) {
|
|
@@ -421,7 +429,7 @@ function processHeaders(item, headers, lastModified, mainEtag) {
|
|
|
421
429
|
const etag = headers.etag;
|
|
422
430
|
if (etag) {
|
|
423
431
|
if (mainEtag) {
|
|
424
|
-
CACHE_ETAG
|
|
432
|
+
CACHE_ETAG.set(item.uri, etag);
|
|
425
433
|
}
|
|
426
434
|
return item.etag = etag;
|
|
427
435
|
}
|
|
@@ -544,8 +552,8 @@ async function doVerifyChecksum(root, from, options, nested) {
|
|
|
544
552
|
const index = item.indexOf(' ');
|
|
545
553
|
return [item.substring(0, index), path.join(root, item.substring(index + 1))];
|
|
546
554
|
});
|
|
547
|
-
const checked = include || exclude ? filterPaths(items.map(item => item[1]), include, exclude, options.dot) : null;
|
|
548
|
-
let valid;
|
|
555
|
+
const checked = include || exclude ? filterPaths(root, items.map(item => item[1]), include, exclude, options.dot) : null;
|
|
556
|
+
let valid = false;
|
|
549
557
|
for (const [previous, pathname] of items) {
|
|
550
558
|
if (checked !== null && !checked.includes(pathname) || recursive === 1 && path.basename(pathname) === filename) {
|
|
551
559
|
continue;
|
|
@@ -671,10 +679,9 @@ function setLogMinWidth() {
|
|
|
671
679
|
}
|
|
672
680
|
const closeResponse = (client) => client?.destroy();
|
|
673
681
|
const isCacheable = (item) => item.initialValue?.cacheable !== false;
|
|
674
|
-
const isMatchRoot = (value) => !value.startsWith('*') && /
|
|
682
|
+
const isMatchRoot = (value) => !value.startsWith('*') && value.includes('/');
|
|
675
683
|
const hasIncremental = (value) => value === "etag" || value === "exists";
|
|
676
684
|
const matchPathname = (value) => core_1.Host.PLATFORM_WIN32 ? value.toLowerCase() : value;
|
|
677
|
-
const sanitizePath = (value) => value.replace(/(?:^\\|\\+)/g, '/');
|
|
678
685
|
const equalAddress = (value, other) => value === other || decodeURIComponent(value) === decodeURIComponent(other);
|
|
679
686
|
const formatPercent = (value) => Math.round(value).toString().padStart(3) + '%';
|
|
680
687
|
const checkEOF = (value) => /\n$/.test(value) ? value : value + '\n';
|
|
@@ -936,34 +943,36 @@ class HttpMemoryCache extends HttpDiskCache {
|
|
|
936
943
|
if (MEMORY.SIZE >= MEMORY.LIMIT_ALL) {
|
|
937
944
|
this.purge(MEMORY.PURGE);
|
|
938
945
|
}
|
|
939
|
-
|
|
946
|
+
const item = [Date.now(), buffer, encoding, contentLength, uri, etag];
|
|
947
|
+
this._items.push(item);
|
|
948
|
+
MEMORY.CACHE.set(uri, item);
|
|
940
949
|
if (this.expires < Infinity) {
|
|
941
950
|
setTimeout(() => {
|
|
942
951
|
this.clear(uri);
|
|
943
952
|
}, Math.min(this.expires, core_1.Host.MAX_TIMEOUT));
|
|
944
953
|
}
|
|
945
|
-
++MEMORY.TOTAL;
|
|
946
|
-
return;
|
|
947
954
|
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
fs.
|
|
955
|
+
else {
|
|
956
|
+
let tempDir;
|
|
957
|
+
if (toDisk && this.withinDisk(contentLength) && (tempDir = this.host.getCacheDir(uri))) {
|
|
958
|
+
try {
|
|
959
|
+
const baseDir = path.join(tempDir, etag);
|
|
960
|
+
if (!fs.existsSync(baseDir)) {
|
|
961
|
+
fs.mkdirSync(baseDir);
|
|
962
|
+
}
|
|
963
|
+
fs.writeFileSync(path.join(baseDir, toDisk), buffer);
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
catch {
|
|
954
967
|
}
|
|
955
|
-
fs.writeFileSync(path.join(baseDir, toDisk), buffer);
|
|
956
|
-
return;
|
|
957
|
-
}
|
|
958
|
-
catch {
|
|
959
968
|
}
|
|
969
|
+
this.clear(uri);
|
|
960
970
|
}
|
|
961
|
-
this.clear(uri);
|
|
962
971
|
}
|
|
963
972
|
clear(uri) {
|
|
964
973
|
let items;
|
|
965
974
|
if (uri) {
|
|
966
|
-
const item = MEMORY.CACHE
|
|
975
|
+
const item = MEMORY.CACHE.get(uri instanceof URL ? uri.href : uri);
|
|
967
976
|
if (!item) {
|
|
968
977
|
return;
|
|
969
978
|
}
|
|
@@ -973,14 +982,13 @@ class HttpMemoryCache extends HttpDiskCache {
|
|
|
973
982
|
items = this._items;
|
|
974
983
|
}
|
|
975
984
|
for (const item of items) {
|
|
976
|
-
const expired = MEMORY.CACHE
|
|
985
|
+
const expired = MEMORY.CACHE.get(uri = item[4]);
|
|
977
986
|
if (expired) {
|
|
978
987
|
const size = expired[3];
|
|
979
988
|
if (size > 0) {
|
|
980
989
|
MEMORY.SIZE -= size;
|
|
981
990
|
}
|
|
982
|
-
|
|
983
|
-
--MEMORY.TOTAL;
|
|
991
|
+
MEMORY.CACHE.delete(uri);
|
|
984
992
|
}
|
|
985
993
|
}
|
|
986
994
|
}
|
|
@@ -1089,26 +1097,26 @@ class ProcessFile {
|
|
|
1089
1097
|
if (err) {
|
|
1090
1098
|
file.invalid = true;
|
|
1091
1099
|
host.completeAsyncTask(err, localUri);
|
|
1092
|
-
return;
|
|
1093
1100
|
}
|
|
1094
|
-
if (file.checksum && !checked && !checkHash(host, localUri, false, file.checksum, file.buffer)) {
|
|
1101
|
+
else if (file.checksum && !checked && !checkHash(host, localUri, false, file.checksum, file.buffer)) {
|
|
1095
1102
|
file.invalid = true;
|
|
1096
1103
|
host.filesToRemove.add(localUri);
|
|
1097
1104
|
host.completeAsyncTask();
|
|
1098
1105
|
host.writeFail(["Checksum did not match", path.basename(localUri)], (0, types_1.errorValue)(file.uri || localUri, "Invalid checksum"), { type: 32, queue: true });
|
|
1099
|
-
return;
|
|
1100
|
-
}
|
|
1101
|
-
if (fetched) {
|
|
1102
|
-
host.fetchedAssets.push(file);
|
|
1103
|
-
}
|
|
1104
|
-
else {
|
|
1105
|
-
host.copiedAssets.push(file);
|
|
1106
|
-
}
|
|
1107
|
-
if (binary) {
|
|
1108
|
-
void host.transformAsset(new FileThread(host, file, 1));
|
|
1109
1106
|
}
|
|
1110
1107
|
else {
|
|
1111
|
-
|
|
1108
|
+
if (fetched) {
|
|
1109
|
+
host.fetchedAssets.push(file);
|
|
1110
|
+
}
|
|
1111
|
+
else {
|
|
1112
|
+
host.copiedAssets.push(file);
|
|
1113
|
+
}
|
|
1114
|
+
if (binary) {
|
|
1115
|
+
void host.transformAsset(new FileThread(host, file, 1));
|
|
1116
|
+
}
|
|
1117
|
+
else {
|
|
1118
|
+
void this.finalize(incremental);
|
|
1119
|
+
}
|
|
1112
1120
|
}
|
|
1113
1121
|
}
|
|
1114
1122
|
async finalize(incremental) {
|
|
@@ -1145,7 +1153,7 @@ class ProcessFile {
|
|
|
1145
1153
|
queue.invalid = true;
|
|
1146
1154
|
return;
|
|
1147
1155
|
}
|
|
1148
|
-
if (value
|
|
1156
|
+
if (Buffer.isBuffer(value)) {
|
|
1149
1157
|
value = value.toString(encoding);
|
|
1150
1158
|
}
|
|
1151
1159
|
const url = queue.url;
|
|
@@ -1179,7 +1187,7 @@ class ProcessFile {
|
|
|
1179
1187
|
else if (url) {
|
|
1180
1188
|
if (etag = queue.etag) {
|
|
1181
1189
|
const valid = incremental !== false || file.incremental === true;
|
|
1182
|
-
const cached = valid && MEMORY.CACHE
|
|
1190
|
+
const cached = valid && MEMORY.CACHE.get(uri);
|
|
1183
1191
|
const etagDir = encodeURIComponent(etag);
|
|
1184
1192
|
if (cached) {
|
|
1185
1193
|
if (etagDir === cached[5]) {
|
|
@@ -1420,40 +1428,29 @@ class FileManager extends core_1.Host {
|
|
|
1420
1428
|
limit = 0;
|
|
1421
1429
|
}
|
|
1422
1430
|
let result = 0;
|
|
1423
|
-
if (limit === 0 || (parent === undefined && limit >= MEMORY.SIZE) || (parent !== undefined && limit > MEMORY.
|
|
1424
|
-
const cache = MEMORY.CACHE;
|
|
1431
|
+
if (limit === 0 || (parent === undefined && limit >= MEMORY.SIZE) || (parent !== undefined && limit > MEMORY.CACHE.size)) {
|
|
1425
1432
|
if (percent >= 1) {
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
++result;
|
|
1429
|
-
}
|
|
1433
|
+
result = MEMORY.CACHE.size;
|
|
1434
|
+
MEMORY.CACHE.clear();
|
|
1430
1435
|
MEMORY.SIZE = 0;
|
|
1431
|
-
MEMORY.TOTAL = 0;
|
|
1432
1436
|
}
|
|
1433
1437
|
else if (percent > 0) {
|
|
1438
|
+
const items = Array.from(MEMORY.CACHE.entries());
|
|
1434
1439
|
const bufferSize = Math.ceil(MEMORY.SIZE * percent);
|
|
1435
|
-
const items = [];
|
|
1436
1440
|
let purgeSize = 0;
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
if (item) {
|
|
1440
|
-
items.push([item, uri]);
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
items.sort((a, b) => a[0][0] - b[0][0]);
|
|
1444
|
-
for (const [item, uri] of items) {
|
|
1441
|
+
items.sort((a, b) => a[1][0] - b[1][0]);
|
|
1442
|
+
for (const [uri, item] of items) {
|
|
1445
1443
|
const size = item[3];
|
|
1446
1444
|
if (size > 0) {
|
|
1447
1445
|
purgeSize += size;
|
|
1448
1446
|
MEMORY.SIZE -= size;
|
|
1449
1447
|
}
|
|
1450
|
-
|
|
1448
|
+
MEMORY.CACHE.delete(uri);
|
|
1451
1449
|
++result;
|
|
1452
1450
|
if (purgeSize >= bufferSize) {
|
|
1453
1451
|
break;
|
|
1454
1452
|
}
|
|
1455
1453
|
}
|
|
1456
|
-
MEMORY.TOTAL = items.length - result;
|
|
1457
1454
|
}
|
|
1458
1455
|
}
|
|
1459
1456
|
return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
|
|
@@ -1499,6 +1496,9 @@ class FileManager extends core_1.Host {
|
|
|
1499
1496
|
else if (id && (id = +id) > 0) {
|
|
1500
1497
|
SESSION_LIMIT = Math.pow(10, id);
|
|
1501
1498
|
}
|
|
1499
|
+
if (logger.color === false) {
|
|
1500
|
+
LOGGER.PROGRESS_USECOLOR = false;
|
|
1501
|
+
}
|
|
1502
1502
|
if (logger.progress) {
|
|
1503
1503
|
let { scroll_buffer, max_width, use_color, text_wrap, color, bg_color, raw_mode, box_char } = logger.progress;
|
|
1504
1504
|
if ((scroll_buffer = (0, util_2.asInt)(scroll_buffer)) >= 0 && scroll_buffer <= 16) {
|
|
@@ -1554,7 +1554,7 @@ class FileManager extends core_1.Host {
|
|
|
1554
1554
|
}
|
|
1555
1555
|
static sanitizeAssets(assets, exclusions = []) {
|
|
1556
1556
|
for (const item of assets) {
|
|
1557
|
-
if ((0, types_1.ignoreFlag)(item
|
|
1557
|
+
if ((0, types_1.ignoreFlag)(item)) {
|
|
1558
1558
|
continue;
|
|
1559
1559
|
}
|
|
1560
1560
|
const initialValue = item.initialValue;
|
|
@@ -1610,11 +1610,11 @@ class FileManager extends core_1.Host {
|
|
|
1610
1610
|
to = joinRoot ? path.join(root, to) : path.resolve(to);
|
|
1611
1611
|
recurseDir(result, [root], { ignore: [...ignore, to], sortBy, recursive });
|
|
1612
1612
|
const output = [];
|
|
1613
|
-
for (const pathname of result = filterPaths(result, include, exclude, options.dot)) {
|
|
1613
|
+
for (const pathname of result = filterPaths(root, result, include, exclude, options.dot)) {
|
|
1614
1614
|
if (recursive === 1 && path.basename(pathname) === filename) {
|
|
1615
1615
|
continue;
|
|
1616
1616
|
}
|
|
1617
|
-
const current = await this.readHash(pathname, { algorithm, digest }) + ' ' +
|
|
1617
|
+
const current = await this.readHash(pathname, { algorithm, digest }) + ' ' + core_1.Permission.toPosix(pathname).substring(root.length).replace(/^\//, '');
|
|
1618
1618
|
if (verbose) {
|
|
1619
1619
|
process.stdout.write(current + '\n');
|
|
1620
1620
|
}
|
|
@@ -1727,7 +1727,7 @@ class FileManager extends core_1.Host {
|
|
|
1727
1727
|
this[_j] = new Scheduler();
|
|
1728
1728
|
this[_k] = [[0, 0], [0, 0], [0, 0]];
|
|
1729
1729
|
this[_l] = null;
|
|
1730
|
-
this[_m] =
|
|
1730
|
+
this[_m] = null;
|
|
1731
1731
|
this[_o] = null;
|
|
1732
1732
|
if (isFunction(permission)) {
|
|
1733
1733
|
postFinalize = permission;
|
|
@@ -1740,7 +1740,7 @@ class FileManager extends core_1.Host {
|
|
|
1740
1740
|
this[kBaseDirectory] = path.normalize(baseDirectory[index] === path.sep ? baseDirectory.substring(0, index) : baseDirectory);
|
|
1741
1741
|
this.permission = permission && core_1.Host.isPermission(permission) ? permission : core_1.Host.getPermissionFromSettings();
|
|
1742
1742
|
this.sessionId = (++SESSION_ID === SESSION_LIMIT ? SESSION_ID = 1 : SESSION_ID).toString();
|
|
1743
|
-
const
|
|
1743
|
+
const assets = config.assets || [];
|
|
1744
1744
|
let targeted;
|
|
1745
1745
|
for (let i = 0, length = assets.length; i < length; ++i) {
|
|
1746
1746
|
const item = assets[i];
|
|
@@ -1754,24 +1754,24 @@ class FileManager extends core_1.Host {
|
|
|
1754
1754
|
if (encoding && encoding !== 'utf8' && encoding !== 'utf-8') {
|
|
1755
1755
|
item.encoding = encoding.endsWith('be') ? undefined : (0, types_1.getEncoding)(encoding);
|
|
1756
1756
|
}
|
|
1757
|
-
if ((0, types_1.usingFlag)(item
|
|
1757
|
+
if ((0, types_1.usingFlag)(item)) {
|
|
1758
1758
|
(targeted ||= []).push(item);
|
|
1759
1759
|
}
|
|
1760
1760
|
item.id ||= ++ASSET_ID;
|
|
1761
1761
|
}
|
|
1762
1762
|
this._assets = assets.slice(0);
|
|
1763
|
-
this[kIncremental] = incremental === "staging" ? "staging" : "none";
|
|
1763
|
+
this[kIncremental] = config.incremental === "staging" ? "staging" : "none";
|
|
1764
1764
|
if (targeted) {
|
|
1765
1765
|
this.using(...targeted);
|
|
1766
1766
|
}
|
|
1767
|
-
if (Array.isArray(dataSource)) {
|
|
1768
|
-
this.dataSourceItems.push(...dataSource);
|
|
1767
|
+
if (Array.isArray(config.dataSource)) {
|
|
1768
|
+
this.dataSourceItems.push(...config.dataSource);
|
|
1769
1769
|
}
|
|
1770
1770
|
if (this.willAbort(this)) {
|
|
1771
1771
|
this.abortable = true;
|
|
1772
1772
|
}
|
|
1773
|
-
if (
|
|
1774
|
-
applyTimeout(this[kProcessTimeout], timeout);
|
|
1773
|
+
if (config.timeout) {
|
|
1774
|
+
applyTimeout(this[kProcessTimeout] = Object.create(null), config.timeout);
|
|
1775
1775
|
}
|
|
1776
1776
|
if (isFunction(postFinalize)) {
|
|
1777
1777
|
this.on('end', postFinalize);
|
|
@@ -1784,19 +1784,11 @@ class FileManager extends core_1.Host {
|
|
|
1784
1784
|
if (MEMORY.EXCLUDE.length > 0) {
|
|
1785
1785
|
this.cacheToMemory.exclude = MEMORY.EXCLUDE;
|
|
1786
1786
|
}
|
|
1787
|
-
if (threads) {
|
|
1788
|
-
this.setTaskLimit(threads);
|
|
1787
|
+
if (typeof config.threads === 'number') {
|
|
1788
|
+
this.setTaskLimit(config.threads);
|
|
1789
1789
|
}
|
|
1790
1790
|
if ((0, types_1.isPlainObject)(config.log) && (0, types_1.isArray)(config.log.showDiff) && this.incremental !== "staging") {
|
|
1791
|
-
this[kDiffSource] = [
|
|
1792
|
-
config.log.showDiff.map(item => {
|
|
1793
|
-
if (!(0, types_1.hasGlob)(item)) {
|
|
1794
|
-
return item;
|
|
1795
|
-
}
|
|
1796
|
-
return isMatchRoot(item) ? pm(core_1.Permission.toPosix(item), { nocase: core_1.Host.PLATFORM_WIN32 }) : pm(sanitizePath(item), { matchBase: true, nocase: core_1.Host.PLATFORM_WIN32 });
|
|
1797
|
-
}),
|
|
1798
|
-
{}
|
|
1799
|
-
];
|
|
1791
|
+
this[kDiffSource] = [config.log.showDiff.map(value => (0, types_1.hasGlob)(value) ? (value = core_1.Permission.toPosix(value), pm(value, { matchBase: !isMatchRoot(value), nocase: core_1.Host.PLATFORM_WIN32 })) : value), {}];
|
|
1800
1792
|
}
|
|
1801
1793
|
const request = new request_1();
|
|
1802
1794
|
request.host = this;
|
|
@@ -2058,79 +2050,96 @@ class FileManager extends core_1.Host {
|
|
|
2058
2050
|
else if ((0, types_1.isObject)(Target)) {
|
|
2059
2051
|
instance = new cloud_1(Target, database);
|
|
2060
2052
|
}
|
|
2061
|
-
if (instance) {
|
|
2062
|
-
|
|
2063
|
-
instance.init(this.config);
|
|
2064
|
-
observeFile(this, instance);
|
|
2065
|
-
return this.Cloud = instance;
|
|
2053
|
+
if (!instance) {
|
|
2054
|
+
return;
|
|
2066
2055
|
}
|
|
2067
|
-
|
|
2056
|
+
instance.host = this;
|
|
2057
|
+
instance.init(this.config);
|
|
2058
|
+
observeFile(this, instance);
|
|
2059
|
+
return this.Cloud = instance;
|
|
2068
2060
|
}
|
|
2069
2061
|
case 'watch': {
|
|
2070
|
-
|
|
2062
|
+
let instance;
|
|
2063
|
+
if ((0, types_1.isString)(Target)) {
|
|
2064
|
+
const module = args.shift();
|
|
2065
|
+
if ((0, types_1.isObject)(module)) {
|
|
2066
|
+
if (Target === "@e-mc/watch") {
|
|
2067
|
+
instance = new watch_1(module);
|
|
2068
|
+
}
|
|
2069
|
+
else if (isFunction(Target = tryPackage(this, Target, 16)) && Target.prototype instanceof watch_1) {
|
|
2070
|
+
instance = new Target(module);
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
else if ((0, types_1.isObject)(Target)) {
|
|
2075
|
+
instance = new watch_1(Target);
|
|
2076
|
+
}
|
|
2077
|
+
if (!instance) {
|
|
2078
|
+
return;
|
|
2079
|
+
}
|
|
2071
2080
|
instance.host = this;
|
|
2072
2081
|
instance.init(this.config);
|
|
2073
|
-
instance.whenModified
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
constructor.sanitizeAssets
|
|
2082
|
+
if (!instance.whenModified) {
|
|
2083
|
+
instance.whenModified = (assets, sanitize, postFinalize) => {
|
|
2084
|
+
if (typeof sanitize === 'function') {
|
|
2085
|
+
postFinalize = sanitize;
|
|
2086
|
+
sanitize = true;
|
|
2087
|
+
}
|
|
2088
|
+
if (sanitize) {
|
|
2089
|
+
FileManager.sanitizeAssets(assets);
|
|
2090
|
+
for (const { instance: document, constructor } of this.Document) {
|
|
2091
|
+
if (constructor.sanitizeAssets) {
|
|
2092
|
+
constructor.sanitizeAssets(assets.filter(item => this.hasDocument(document, item.document)));
|
|
2093
|
+
}
|
|
2083
2094
|
}
|
|
2084
2095
|
}
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2096
|
+
const manager = new FileManager(this.baseDirectory, { ...this.config, incremental: "none", assets }, postFinalize);
|
|
2097
|
+
for (const { constructor, params } of this.Document) {
|
|
2098
|
+
manager.install('document', constructor, ...params);
|
|
2099
|
+
}
|
|
2100
|
+
for (const { constructor, params } of this.Task) {
|
|
2101
|
+
manager.install('task', constructor, ...params);
|
|
2102
|
+
}
|
|
2103
|
+
if (this.Cloud) {
|
|
2104
|
+
manager.install('cloud', this.Cloud.module);
|
|
2105
|
+
}
|
|
2106
|
+
if (this.Image) {
|
|
2107
|
+
const mimeMap = new Map();
|
|
2108
|
+
let params = [];
|
|
2109
|
+
for (const [mimeType, handler] of this.Image) {
|
|
2110
|
+
const { constructor, params: trailing } = handler;
|
|
2111
|
+
if (mimeType === 'handler') {
|
|
2112
|
+
if (this.Image.size === 1) {
|
|
2113
|
+
manager.install('image', constructor, ...trailing);
|
|
2114
|
+
break;
|
|
2115
|
+
}
|
|
2116
|
+
params = trailing;
|
|
2117
|
+
}
|
|
2118
|
+
else if (params.length === 0) {
|
|
2119
|
+
params = trailing;
|
|
2105
2120
|
}
|
|
2106
|
-
|
|
2121
|
+
mimeMap.set(mimeType, constructor);
|
|
2107
2122
|
}
|
|
2108
|
-
|
|
2109
|
-
|
|
2123
|
+
if (mimeMap.size > 0) {
|
|
2124
|
+
manager.install('image', mimeMap, ...params);
|
|
2110
2125
|
}
|
|
2111
|
-
mimeMap.set(mimeType, constructor);
|
|
2112
|
-
}
|
|
2113
|
-
if (mimeMap.size > 0) {
|
|
2114
|
-
manager.install('image', mimeMap, ...params);
|
|
2115
2126
|
}
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
manager.install('compress', this.Compress.module);
|
|
2119
|
-
}
|
|
2120
|
-
manager.sessionId = this.sessionId;
|
|
2121
|
-
manager.permission = this.permission;
|
|
2122
|
-
manager.cacheToDisk = this.cacheToDisk;
|
|
2123
|
-
manager.cacheToMemory = this.cacheToMemory;
|
|
2124
|
-
if (postFinalize) {
|
|
2125
|
-
try {
|
|
2126
|
-
manager.processAssets();
|
|
2127
|
+
if (this.Compress) {
|
|
2128
|
+
manager.install('compress', this.Compress.module);
|
|
2127
2129
|
}
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
+
manager.sessionId = this.sessionId;
|
|
2131
|
+
manager.permission = this.permission;
|
|
2132
|
+
if (postFinalize) {
|
|
2133
|
+
try {
|
|
2134
|
+
manager.processAssets();
|
|
2135
|
+
}
|
|
2136
|
+
catch (err) {
|
|
2137
|
+
manager.writeFail("Unknown", err, { startTime: manager.startTime });
|
|
2138
|
+
}
|
|
2130
2139
|
}
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
}
|
|
2140
|
+
return manager;
|
|
2141
|
+
};
|
|
2142
|
+
}
|
|
2134
2143
|
return this.Watch = instance;
|
|
2135
2144
|
}
|
|
2136
2145
|
case 'image': {
|
|
@@ -2431,12 +2440,12 @@ class FileManager extends core_1.Host {
|
|
|
2431
2440
|
pathname = file.pathname || '';
|
|
2432
2441
|
}
|
|
2433
2442
|
const assets = this.assets;
|
|
2434
|
-
let target = matchPathname(path.join(pathname, filename)), modified;
|
|
2443
|
+
let target = matchPathname(path.join(pathname, filename)), modified = false;
|
|
2435
2444
|
for (let i = 0, j = 1, length = assets.length; i < length; ++i) {
|
|
2436
2445
|
const item = assets[i];
|
|
2437
2446
|
if (item !== file && item.filename && target === matchPathname(path.join(item.pathname || '', item.filename))) {
|
|
2438
|
-
const ext = path.
|
|
2439
|
-
filename =
|
|
2447
|
+
const { name, ext } = path.parse(filename);
|
|
2448
|
+
filename = name + '_' + j + ext;
|
|
2440
2449
|
target = matchPathname(path.join(pathname, filename));
|
|
2441
2450
|
modified = true;
|
|
2442
2451
|
i = -1;
|
|
@@ -2594,7 +2603,7 @@ class FileManager extends core_1.Host {
|
|
|
2594
2603
|
return fs.readFileSync(localUri);
|
|
2595
2604
|
}
|
|
2596
2605
|
catch (err) {
|
|
2597
|
-
if (!(base64 && core_1.Host.isErrorCode(err, 'ENOENT'))) {
|
|
2606
|
+
if (!(base64 && core_1.Host.isErrorCode(err, 'ENOENT', 'EACCES'))) {
|
|
2598
2607
|
this.writeFail(["Unable to read file", path.basename(localUri)], err, 32);
|
|
2599
2608
|
base64 = undefined;
|
|
2600
2609
|
}
|
|
@@ -2795,7 +2804,7 @@ class FileManager extends core_1.Host {
|
|
|
2795
2804
|
async compressFile(file, overwrite = true) {
|
|
2796
2805
|
const { localUri, compress } = file;
|
|
2797
2806
|
const instance = this.Compress;
|
|
2798
|
-
if (instance && compress && localUri && (this.has(localUri) || (0, types_1.existsFlag)(file
|
|
2807
|
+
if (instance && compress && localUri && (this.has(localUri) || (0, types_1.existsFlag)(file))) {
|
|
2799
2808
|
const tasks = [];
|
|
2800
2809
|
for (const options of compress) {
|
|
2801
2810
|
const { format, condition } = options;
|
|
@@ -2820,8 +2829,8 @@ class FileManager extends core_1.Host {
|
|
|
2820
2829
|
}
|
|
2821
2830
|
if (output && (!condition || withinSizeRange(localUri, condition))) {
|
|
2822
2831
|
try {
|
|
2823
|
-
if (overwrite || !fs.existsSync(output) || !(0, types_1.existsFlag)(file
|
|
2824
|
-
options.timeout = this
|
|
2832
|
+
if (overwrite || !fs.existsSync(output) || !(0, types_1.existsFlag)(file) && fs.statSync(output).mtimeMs < this.startTime) {
|
|
2833
|
+
options.timeout = this.getNamedTimeout('compress');
|
|
2825
2834
|
tasks.push(instance.tryFile(file.buffer || localUri, output, options).then(() => {
|
|
2826
2835
|
const outFile = options.outFile;
|
|
2827
2836
|
if (outFile) {
|
|
@@ -3023,8 +3032,7 @@ class FileManager extends core_1.Host {
|
|
|
3023
3032
|
}
|
|
3024
3033
|
}
|
|
3025
3034
|
getProcessTimeout(handler) {
|
|
3026
|
-
|
|
3027
|
-
return this[kProcessTimeout][moduleName] ?? PROCESS_TIMEOUT[moduleName] ?? (handler.constructor.PROCESS_TIMEOUT || 0);
|
|
3035
|
+
return this.getNamedTimeout(handler.instance.moduleName) ?? (handler.constructor.PROCESS_TIMEOUT || 0);
|
|
3028
3036
|
}
|
|
3029
3037
|
clearProcessTimeout() {
|
|
3030
3038
|
const timerMain = this[KTimerMain];
|
|
@@ -3207,7 +3215,7 @@ class FileManager extends core_1.Host {
|
|
|
3207
3215
|
}
|
|
3208
3216
|
const { processing, processTimeout } = this;
|
|
3209
3217
|
const currentTime = Date.now();
|
|
3210
|
-
let aborted;
|
|
3218
|
+
let aborted = false;
|
|
3211
3219
|
for (let i = 0; i < processing.length; ++i) {
|
|
3212
3220
|
const data = processing[i];
|
|
3213
3221
|
const file = data.file;
|
|
@@ -3270,7 +3278,7 @@ class FileManager extends core_1.Host {
|
|
|
3270
3278
|
const groupData = new ProcessGroup();
|
|
3271
3279
|
const imported = assets.filter(item => item.imported && (0, types_1.isArray)(item.imported));
|
|
3272
3280
|
for (let item of assets) {
|
|
3273
|
-
if (item.invalid || (0, types_1.ignoreFlag)(item
|
|
3281
|
+
if (item.invalid || (0, types_1.ignoreFlag)(item)) {
|
|
3274
3282
|
continue;
|
|
3275
3283
|
}
|
|
3276
3284
|
let download = this.setLocalUri(item), uri = item.uri;
|
|
@@ -3310,11 +3318,11 @@ class FileManager extends core_1.Host {
|
|
|
3310
3318
|
if (etag && imported.some(file => file.imported.includes(uri))) {
|
|
3311
3319
|
item.incremental = "none";
|
|
3312
3320
|
}
|
|
3313
|
-
else if (!(0, types_1.mainFlag)(item
|
|
3321
|
+
else if (!(0, types_1.mainFlag)(item)) {
|
|
3314
3322
|
let cached;
|
|
3315
3323
|
const { bundleId, bundleIndex = -1 } = item;
|
|
3316
3324
|
const setBuffer = (target) => {
|
|
3317
|
-
if (!etag && (uri = target.uri) && (cached = MEMORY.CACHE
|
|
3325
|
+
if (!etag && (uri = target.uri) && (cached = MEMORY.CACHE.get(uri))) {
|
|
3318
3326
|
target.etag = cached[5];
|
|
3319
3327
|
target.contentLength = cached[3];
|
|
3320
3328
|
return true;
|
|
@@ -3326,7 +3334,7 @@ class FileManager extends core_1.Host {
|
|
|
3326
3334
|
if (!(0, types_1.isEmpty)(bundleId) && bundleIndex > 0) {
|
|
3327
3335
|
const target = assets.find(parent => parent.bundleIndex === 0 && parent.bundleId === bundleId);
|
|
3328
3336
|
if (target) {
|
|
3329
|
-
if ((0, types_1.existsFlag)(target
|
|
3337
|
+
if ((0, types_1.existsFlag)(target)) {
|
|
3330
3338
|
setBuffer(item);
|
|
3331
3339
|
item.invalid = true;
|
|
3332
3340
|
}
|
|
@@ -3399,10 +3407,10 @@ class FileManager extends core_1.Host {
|
|
|
3399
3407
|
if (!etag) {
|
|
3400
3408
|
(0, asset_1.setInitialValue)(item, false).buffer = buffer;
|
|
3401
3409
|
}
|
|
3402
|
-
else if (uri && CACHE_ETAG
|
|
3410
|
+
else if (uri && CACHE_ETAG.has(uri)) {
|
|
3403
3411
|
const initialValue = (0, asset_1.setInitialValue)(item, false);
|
|
3404
3412
|
initialValue.buffer = buffer;
|
|
3405
|
-
initialValue.etag = CACHE_ETAG
|
|
3413
|
+
initialValue.etag = CACHE_ETAG.get(uri);
|
|
3406
3414
|
}
|
|
3407
3415
|
}
|
|
3408
3416
|
catch {
|
|
@@ -3513,11 +3521,11 @@ class FileManager extends core_1.Host {
|
|
|
3513
3521
|
downloading[uri] = [];
|
|
3514
3522
|
}
|
|
3515
3523
|
const url = item.url;
|
|
3516
|
-
let mainEtag = false, encoding = item.encoding, client = null, cacheDir, cacheBuffer;
|
|
3524
|
+
let mainEtag = false, encoding = item.encoding, client = null, cacheDir = false, cacheBuffer = false;
|
|
3517
3525
|
if (type === 1) {
|
|
3518
3526
|
cacheDir = cacheToDisk.has(url) && isCacheable(item);
|
|
3519
3527
|
cacheBuffer = cacheToMemory.has(url);
|
|
3520
|
-
mainEtag = (0, types_1.mainFlag)(item
|
|
3528
|
+
mainEtag = (0, types_1.mainFlag)(item) && (cacheEtag || item.incremental === "etag");
|
|
3521
3529
|
}
|
|
3522
3530
|
const downloadUri = (request, etagDir) => {
|
|
3523
3531
|
if (checkEtag) {
|
|
@@ -3585,7 +3593,7 @@ class FileManager extends core_1.Host {
|
|
|
3585
3593
|
etagDir = encodeURIComponent(etag);
|
|
3586
3594
|
if (incremental !== false || item.incremental === true) {
|
|
3587
3595
|
const location = href.toString();
|
|
3588
|
-
const cached = MEMORY.CACHE
|
|
3596
|
+
const cached = MEMORY.CACHE.get(location);
|
|
3589
3597
|
let buffer;
|
|
3590
3598
|
if (cached) {
|
|
3591
3599
|
if (etagDir === cached[5] && (!encoding || encoding === cached[2])) {
|
|
@@ -3747,7 +3755,7 @@ class FileManager extends core_1.Host {
|
|
|
3747
3755
|
}
|
|
3748
3756
|
else {
|
|
3749
3757
|
const ext = item.filename && path.extname(item.filename);
|
|
3750
|
-
let found;
|
|
3758
|
+
let found = false;
|
|
3751
3759
|
for (const file of result) {
|
|
3752
3760
|
if (!found && ext === path.extname(file).toLowerCase()) {
|
|
3753
3761
|
try {
|
|
@@ -3814,9 +3822,13 @@ class FileManager extends core_1.Host {
|
|
|
3814
3822
|
const received = args[1];
|
|
3815
3823
|
const total = args[2];
|
|
3816
3824
|
if (received === 0 && total === 0) {
|
|
3817
|
-
if (
|
|
3825
|
+
if (typeof args[3] === 'bigint') {
|
|
3818
3826
|
found.dataTime = args[3];
|
|
3819
3827
|
}
|
|
3828
|
+
else if (Array.isArray(args[3])) {
|
|
3829
|
+
const [s, n] = args[3];
|
|
3830
|
+
found.dataTime = BigInt(s * 1000000000) + BigInt(n);
|
|
3831
|
+
}
|
|
3820
3832
|
return;
|
|
3821
3833
|
}
|
|
3822
3834
|
found.receivedBytes = received;
|
|
@@ -3914,7 +3926,7 @@ class FileManager extends core_1.Host {
|
|
|
3914
3926
|
}
|
|
3915
3927
|
const diffTime = currentTime - item.startTime;
|
|
3916
3928
|
const unit = receivedBytes < 1048576 ? 'KB' : receivedBytes < 1073741824 ? 'MB' : 'GB';
|
|
3917
|
-
const [time, size, speed] = formatSegment(endTime > 0 ? bars === 0 ? -1 : endTime : 0, formatMinutes(diffTime).padStart(LOGGER.TITLE_WIDTH), (0, types_1.formatSize)(receivedBytes, { unit, unitSeparator: ' ', fixedDecimals: true, decimalPlaces: unit === 'KB' ? 0 : unit === 'MB' ? 1 : 2 }).padStart(8), (0, util_2.getTransferRate)(receivedBytes, item.dataTime ? (0, types_1.convertTime)(process.hrtime(item.dataTime
|
|
3929
|
+
const [time, size, speed] = formatSegment(endTime > 0 ? bars === 0 ? -1 : endTime : 0, formatMinutes(diffTime).padStart(LOGGER.TITLE_WIDTH), (0, types_1.formatSize)(receivedBytes, { unit, unitSeparator: ' ', fixedDecimals: true, decimalPlaces: unit === 'KB' ? 0 : unit === 'MB' ? 1 : 2 }).padStart(8), (0, util_2.getTransferRate)(receivedBytes, item.dataTime ? (0, types_1.convertTime)(process.hrtime.bigint() - item.dataTime, false) * 1000 : diffTime, ' ').padStart(10));
|
|
3918
3930
|
let output = time + ` ${chalk.blackBright(LOGGER.TITLE_SEP)} ` + (endTime > 0 && bars === 0 ? chalk.grey(item.url) : item.url) + spacer;
|
|
3919
3931
|
if (barLength === 1) {
|
|
3920
3932
|
output += ` ${endTime > 0 ? bars === 0 ? chalk.red('ERR!') : LOGGER.PROGRESS_COMPLETE : formatPercent(percent)} ` + spacer;
|
|
@@ -3933,7 +3945,7 @@ class FileManager extends core_1.Host {
|
|
|
3933
3945
|
}
|
|
3934
3946
|
output += '\n';
|
|
3935
3947
|
if (!LOGGER.PROGRESS_USECOLOR) {
|
|
3936
|
-
output =
|
|
3948
|
+
output = (0, node_util_1.stripVTControlCharacters)(output);
|
|
3937
3949
|
}
|
|
3938
3950
|
PROCESS_STDOUT.clearLine(0);
|
|
3939
3951
|
PROCESS_STDOUT.write(output);
|
|
@@ -3949,7 +3961,7 @@ class FileManager extends core_1.Host {
|
|
|
3949
3961
|
processTask.section(redraw);
|
|
3950
3962
|
const { PROGRESS_COLOR: color, PROGRESS_BGCOLOR: bgColor, PROGRESS_USECOLOR: useColor, PROGRESS_TEXTWRAP: messageTextWrap } = LOGGER;
|
|
3951
3963
|
const scroll = processTask.scroll;
|
|
3952
|
-
let start = 0, end = 0, output, last;
|
|
3964
|
+
let start = 0, end = 0, output = false, last;
|
|
3953
3965
|
if (cleared) {
|
|
3954
3966
|
logDelayed = this._logDelayed;
|
|
3955
3967
|
end = Math.min(logDelayed.length, scrollHeight);
|
|
@@ -4056,7 +4068,7 @@ class FileManager extends core_1.Host {
|
|
|
4056
4068
|
}
|
|
4057
4069
|
else {
|
|
4058
4070
|
if (data instanceof URL && data.protocol === 'file:') {
|
|
4059
|
-
data = (0,
|
|
4071
|
+
data = (0, node_url_1.fileURLToPath)(data);
|
|
4060
4072
|
}
|
|
4061
4073
|
if ((0, types_1.isString)(data) && core_1.Host.isPath(data, true) && this.canRead(data)) {
|
|
4062
4074
|
data = fs.createReadStream(data);
|
|
@@ -4116,7 +4128,7 @@ class FileManager extends core_1.Host {
|
|
|
4116
4128
|
for (let i = 0, length = output.length, buffer = null; i < length; ++i) {
|
|
4117
4129
|
const options = output[i];
|
|
4118
4130
|
options.mimeType = mimeType;
|
|
4119
|
-
options.timeout ??= this
|
|
4131
|
+
options.timeout ??= this.getNamedTimeout('compress');
|
|
4120
4132
|
await compress.tryImage(buffer || files.length === 1 && item.buffer || file, file, options)
|
|
4121
4133
|
.then(result => {
|
|
4122
4134
|
if (result) {
|
|
@@ -4192,7 +4204,7 @@ class FileManager extends core_1.Host {
|
|
|
4192
4204
|
const baseDirectory = this.baseDirectory;
|
|
4193
4205
|
checksum.joinRoot = true;
|
|
4194
4206
|
checksum.throwsEmpty = true;
|
|
4195
|
-
const sumTime = LOG_TIMEELAPSED ? process.hrtime() : 0;
|
|
4207
|
+
const sumTime = LOG_TIMEELAPSED ? process.hrtime.bigint() : 0;
|
|
4196
4208
|
const files = (await FileManager.writeChecksum(baseDirectory, checksum.filename, checksum));
|
|
4197
4209
|
if (sumTime) {
|
|
4198
4210
|
this.writeTimeElapsed(checksum.algorithm || "sha256", [baseDirectory, files.length + (files.length === 1 ? ' file' : ' files')], sumTime, { ...core_1.Host.LOG_STYLE_WARN });
|
|
@@ -4224,7 +4236,7 @@ class FileManager extends core_1.Host {
|
|
|
4224
4236
|
if (LOG_TIMEELAPSED) {
|
|
4225
4237
|
this.writeTimeElapsed('READY', 'Finalizing assets...', this.startTime, { ...core_1.Host.LOG_STYLE_WARN, showCpu: true });
|
|
4226
4238
|
}
|
|
4227
|
-
const startTime = process.hrtime();
|
|
4239
|
+
const startTime = process.hrtime.bigint();
|
|
4228
4240
|
const filesToRemove = this.filesToRemove;
|
|
4229
4241
|
for (const [file, output] of this.filesToCompare) {
|
|
4230
4242
|
const localUri = file.localUri;
|
|
@@ -4343,8 +4355,7 @@ class FileManager extends core_1.Host {
|
|
|
4343
4355
|
message.push('CACHE ' + (count > 1 ? count + ' / ' : '') + (0, types_1.formatSize)(size));
|
|
4344
4356
|
}
|
|
4345
4357
|
if (MEMORY.SIZE > 0) {
|
|
4346
|
-
|
|
4347
|
-
message.push('BUFFER ' + (bufferCount > 1 ? bufferCount + ' / ' : '') + (0, types_1.formatSize)(MEMORY.SIZE));
|
|
4358
|
+
message.push('BUFFER ' + (MEMORY.CACHE.size > 1 ? MEMORY.CACHE.size + ' / ' : '') + (0, types_1.formatSize)(MEMORY.SIZE));
|
|
4348
4359
|
}
|
|
4349
4360
|
this.writeTimeElapsed('CLOSE', ['No further modifications', message.length > 0 ? message.join(chalk.blackBright(LOGGER.MESSAGE_SEP)) : ''], startTime, { ...core_1.Host.LOG_STYLE_WARN });
|
|
4350
4361
|
}
|
|
@@ -4435,6 +4446,10 @@ class FileManager extends core_1.Host {
|
|
|
4435
4446
|
this.done = true;
|
|
4436
4447
|
}
|
|
4437
4448
|
}
|
|
4449
|
+
getNamedTimeout(name) {
|
|
4450
|
+
const timeout = this[kProcessTimeout];
|
|
4451
|
+
return timeout && name in timeout ? timeout[name] : PROCESS_TIMEOUT[name];
|
|
4452
|
+
}
|
|
4438
4453
|
set restarting(value) {
|
|
4439
4454
|
this.finalizeState = (this[kRestarting] = value) ? 3 : 0;
|
|
4440
4455
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/file-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "FileManager constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,18 +20,17 @@
|
|
|
20
20
|
"license": "BSD-3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "0.
|
|
24
|
-
"@e-mc/compress": "0.
|
|
25
|
-
"@e-mc/core": "0.
|
|
26
|
-
"@e-mc/document": "0.
|
|
27
|
-
"@e-mc/image": "0.
|
|
28
|
-
"@e-mc/request": "0.
|
|
29
|
-
"@e-mc/task": "0.
|
|
30
|
-
"@e-mc/types": "0.
|
|
31
|
-
"@e-mc/watch": "0.
|
|
23
|
+
"@e-mc/cloud": "0.11.1",
|
|
24
|
+
"@e-mc/compress": "0.11.1",
|
|
25
|
+
"@e-mc/core": "0.11.1",
|
|
26
|
+
"@e-mc/document": "0.11.1",
|
|
27
|
+
"@e-mc/image": "0.11.1",
|
|
28
|
+
"@e-mc/request": "0.11.1",
|
|
29
|
+
"@e-mc/task": "0.11.1",
|
|
30
|
+
"@e-mc/types": "0.11.1",
|
|
31
|
+
"@e-mc/watch": "0.11.1",
|
|
32
32
|
"chalk": "4.1.2",
|
|
33
|
-
"diff": "^
|
|
34
|
-
"picomatch": "^4.0.2"
|
|
35
|
-
"strip-ansi": "6.0.1"
|
|
33
|
+
"diff": "^7.0.0",
|
|
34
|
+
"picomatch": "^4.0.2"
|
|
36
35
|
}
|
|
37
36
|
}
|