@e-mc/file-manager 0.10.6 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +22 -21
- package/index.js +193 -180
- 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.0/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.0/lib/squared.d.ts
|
|
310
|
+
- https://www.unpkg.com/@e-mc/types@0.11.0/lib/asset.d.ts
|
|
311
|
+
- https://www.unpkg.com/@e-mc/types@0.11.0/lib/core.d.ts
|
|
312
|
+
- https://www.unpkg.com/@e-mc/types@0.11.0/lib/filemanager.d.ts
|
|
313
|
+
- https://www.unpkg.com/@e-mc/types@0.11.0/lib/logger.d.ts
|
|
314
|
+
- https://www.unpkg.com/@e-mc/types@0.11.0/lib/module.d.ts
|
|
315
|
+
- https://www.unpkg.com/@e-mc/types@0.11.0/lib/node.d.ts
|
|
316
|
+
- https://www.unpkg.com/@e-mc/types@0.11.0/lib/request.d.ts
|
|
317
|
+
- https://www.unpkg.com/@e-mc/types@0.11.0/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 = {
|
|
@@ -218,11 +217,18 @@ function checkHash(host, localUri, output, options, data) {
|
|
|
218
217
|
return true;
|
|
219
218
|
}
|
|
220
219
|
function validatePaths(values, patterns, include, dot) {
|
|
221
|
-
const items = patterns.map(value =>
|
|
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
|
+
return isMatchRoot(value = core_1.Permission.toPosix(value)) ? [path.resolve(value), { nocase: core_1.Host.PLATFORM_WIN32, dot }, invert] : [value, { matchBase: true, nocase: core_1.Host.PLATFORM_WIN32, dot }, invert];
|
|
227
|
+
});
|
|
222
228
|
return values.filter(value => {
|
|
223
|
-
for (const [pattern, options] of items) {
|
|
229
|
+
for (const [pattern, options, invert] of items) {
|
|
224
230
|
if (pm.isMatch(core_1.Permission.toPosix(value), pattern, options)) {
|
|
225
|
-
return include;
|
|
231
|
+
return invert ? !include : include;
|
|
226
232
|
}
|
|
227
233
|
}
|
|
228
234
|
return !include;
|
|
@@ -234,7 +240,7 @@ function filterPaths(values, include, exclude, dot) {
|
|
|
234
240
|
include = [include];
|
|
235
241
|
}
|
|
236
242
|
if ((0, types_1.isArray)(include)) {
|
|
237
|
-
|
|
243
|
+
values = validatePaths(values, include, true, dot);
|
|
238
244
|
}
|
|
239
245
|
}
|
|
240
246
|
if (exclude) {
|
|
@@ -395,7 +401,7 @@ function clearQueue(data, attr) {
|
|
|
395
401
|
}
|
|
396
402
|
}
|
|
397
403
|
function hasEtag(item, cacheable, fallback) {
|
|
398
|
-
if (!cacheable || !(0, types_1.existsFlag)(item
|
|
404
|
+
if (!cacheable || !(0, types_1.existsFlag)(item)) {
|
|
399
405
|
return false;
|
|
400
406
|
}
|
|
401
407
|
switch (item.incremental) {
|
|
@@ -421,7 +427,7 @@ function processHeaders(item, headers, lastModified, mainEtag) {
|
|
|
421
427
|
const etag = headers.etag;
|
|
422
428
|
if (etag) {
|
|
423
429
|
if (mainEtag) {
|
|
424
|
-
CACHE_ETAG
|
|
430
|
+
CACHE_ETAG.set(item.uri, etag);
|
|
425
431
|
}
|
|
426
432
|
return item.etag = etag;
|
|
427
433
|
}
|
|
@@ -545,7 +551,7 @@ async function doVerifyChecksum(root, from, options, nested) {
|
|
|
545
551
|
return [item.substring(0, index), path.join(root, item.substring(index + 1))];
|
|
546
552
|
});
|
|
547
553
|
const checked = include || exclude ? filterPaths(items.map(item => item[1]), include, exclude, options.dot) : null;
|
|
548
|
-
let valid;
|
|
554
|
+
let valid = false;
|
|
549
555
|
for (const [previous, pathname] of items) {
|
|
550
556
|
if (checked !== null && !checked.includes(pathname) || recursive === 1 && path.basename(pathname) === filename) {
|
|
551
557
|
continue;
|
|
@@ -671,10 +677,9 @@ function setLogMinWidth() {
|
|
|
671
677
|
}
|
|
672
678
|
const closeResponse = (client) => client?.destroy();
|
|
673
679
|
const isCacheable = (item) => item.initialValue?.cacheable !== false;
|
|
674
|
-
const isMatchRoot = (value) => !value.startsWith('*') && /
|
|
680
|
+
const isMatchRoot = (value) => !value.startsWith('*') && value.includes('/');
|
|
675
681
|
const hasIncremental = (value) => value === "etag" || value === "exists";
|
|
676
682
|
const matchPathname = (value) => core_1.Host.PLATFORM_WIN32 ? value.toLowerCase() : value;
|
|
677
|
-
const sanitizePath = (value) => value.replace(/(?:^\\|\\+)/g, '/');
|
|
678
683
|
const equalAddress = (value, other) => value === other || decodeURIComponent(value) === decodeURIComponent(other);
|
|
679
684
|
const formatPercent = (value) => Math.round(value).toString().padStart(3) + '%';
|
|
680
685
|
const checkEOF = (value) => /\n$/.test(value) ? value : value + '\n';
|
|
@@ -936,34 +941,36 @@ class HttpMemoryCache extends HttpDiskCache {
|
|
|
936
941
|
if (MEMORY.SIZE >= MEMORY.LIMIT_ALL) {
|
|
937
942
|
this.purge(MEMORY.PURGE);
|
|
938
943
|
}
|
|
939
|
-
|
|
944
|
+
const item = [Date.now(), buffer, encoding, contentLength, uri, etag];
|
|
945
|
+
this._items.push(item);
|
|
946
|
+
MEMORY.CACHE.set(uri, item);
|
|
940
947
|
if (this.expires < Infinity) {
|
|
941
948
|
setTimeout(() => {
|
|
942
949
|
this.clear(uri);
|
|
943
950
|
}, Math.min(this.expires, core_1.Host.MAX_TIMEOUT));
|
|
944
951
|
}
|
|
945
|
-
++MEMORY.TOTAL;
|
|
946
|
-
return;
|
|
947
952
|
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
fs.
|
|
953
|
+
else {
|
|
954
|
+
let tempDir;
|
|
955
|
+
if (toDisk && this.withinDisk(contentLength) && (tempDir = this.host.getCacheDir(uri))) {
|
|
956
|
+
try {
|
|
957
|
+
const baseDir = path.join(tempDir, etag);
|
|
958
|
+
if (!fs.existsSync(baseDir)) {
|
|
959
|
+
fs.mkdirSync(baseDir);
|
|
960
|
+
}
|
|
961
|
+
fs.writeFileSync(path.join(baseDir, toDisk), buffer);
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
catch {
|
|
954
965
|
}
|
|
955
|
-
fs.writeFileSync(path.join(baseDir, toDisk), buffer);
|
|
956
|
-
return;
|
|
957
|
-
}
|
|
958
|
-
catch {
|
|
959
966
|
}
|
|
967
|
+
this.clear(uri);
|
|
960
968
|
}
|
|
961
|
-
this.clear(uri);
|
|
962
969
|
}
|
|
963
970
|
clear(uri) {
|
|
964
971
|
let items;
|
|
965
972
|
if (uri) {
|
|
966
|
-
const item = MEMORY.CACHE
|
|
973
|
+
const item = MEMORY.CACHE.get(uri instanceof URL ? uri.href : uri);
|
|
967
974
|
if (!item) {
|
|
968
975
|
return;
|
|
969
976
|
}
|
|
@@ -973,14 +980,13 @@ class HttpMemoryCache extends HttpDiskCache {
|
|
|
973
980
|
items = this._items;
|
|
974
981
|
}
|
|
975
982
|
for (const item of items) {
|
|
976
|
-
const expired = MEMORY.CACHE
|
|
983
|
+
const expired = MEMORY.CACHE.get(uri = item[4]);
|
|
977
984
|
if (expired) {
|
|
978
985
|
const size = expired[3];
|
|
979
986
|
if (size > 0) {
|
|
980
987
|
MEMORY.SIZE -= size;
|
|
981
988
|
}
|
|
982
|
-
|
|
983
|
-
--MEMORY.TOTAL;
|
|
989
|
+
MEMORY.CACHE.delete(uri);
|
|
984
990
|
}
|
|
985
991
|
}
|
|
986
992
|
}
|
|
@@ -1089,26 +1095,26 @@ class ProcessFile {
|
|
|
1089
1095
|
if (err) {
|
|
1090
1096
|
file.invalid = true;
|
|
1091
1097
|
host.completeAsyncTask(err, localUri);
|
|
1092
|
-
return;
|
|
1093
1098
|
}
|
|
1094
|
-
if (file.checksum && !checked && !checkHash(host, localUri, false, file.checksum, file.buffer)) {
|
|
1099
|
+
else if (file.checksum && !checked && !checkHash(host, localUri, false, file.checksum, file.buffer)) {
|
|
1095
1100
|
file.invalid = true;
|
|
1096
1101
|
host.filesToRemove.add(localUri);
|
|
1097
1102
|
host.completeAsyncTask();
|
|
1098
1103
|
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
1104
|
}
|
|
1110
1105
|
else {
|
|
1111
|
-
|
|
1106
|
+
if (fetched) {
|
|
1107
|
+
host.fetchedAssets.push(file);
|
|
1108
|
+
}
|
|
1109
|
+
else {
|
|
1110
|
+
host.copiedAssets.push(file);
|
|
1111
|
+
}
|
|
1112
|
+
if (binary) {
|
|
1113
|
+
void host.transformAsset(new FileThread(host, file, 1));
|
|
1114
|
+
}
|
|
1115
|
+
else {
|
|
1116
|
+
void this.finalize(incremental);
|
|
1117
|
+
}
|
|
1112
1118
|
}
|
|
1113
1119
|
}
|
|
1114
1120
|
async finalize(incremental) {
|
|
@@ -1145,7 +1151,7 @@ class ProcessFile {
|
|
|
1145
1151
|
queue.invalid = true;
|
|
1146
1152
|
return;
|
|
1147
1153
|
}
|
|
1148
|
-
if (value
|
|
1154
|
+
if (Buffer.isBuffer(value)) {
|
|
1149
1155
|
value = value.toString(encoding);
|
|
1150
1156
|
}
|
|
1151
1157
|
const url = queue.url;
|
|
@@ -1179,7 +1185,7 @@ class ProcessFile {
|
|
|
1179
1185
|
else if (url) {
|
|
1180
1186
|
if (etag = queue.etag) {
|
|
1181
1187
|
const valid = incremental !== false || file.incremental === true;
|
|
1182
|
-
const cached = valid && MEMORY.CACHE
|
|
1188
|
+
const cached = valid && MEMORY.CACHE.get(uri);
|
|
1183
1189
|
const etagDir = encodeURIComponent(etag);
|
|
1184
1190
|
if (cached) {
|
|
1185
1191
|
if (etagDir === cached[5]) {
|
|
@@ -1420,40 +1426,29 @@ class FileManager extends core_1.Host {
|
|
|
1420
1426
|
limit = 0;
|
|
1421
1427
|
}
|
|
1422
1428
|
let result = 0;
|
|
1423
|
-
if (limit === 0 || (parent === undefined && limit >= MEMORY.SIZE) || (parent !== undefined && limit > MEMORY.
|
|
1424
|
-
const cache = MEMORY.CACHE;
|
|
1429
|
+
if (limit === 0 || (parent === undefined && limit >= MEMORY.SIZE) || (parent !== undefined && limit > MEMORY.CACHE.size)) {
|
|
1425
1430
|
if (percent >= 1) {
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
++result;
|
|
1429
|
-
}
|
|
1431
|
+
result = MEMORY.CACHE.size;
|
|
1432
|
+
MEMORY.CACHE.clear();
|
|
1430
1433
|
MEMORY.SIZE = 0;
|
|
1431
|
-
MEMORY.TOTAL = 0;
|
|
1432
1434
|
}
|
|
1433
1435
|
else if (percent > 0) {
|
|
1436
|
+
const items = Array.from(MEMORY.CACHE.entries());
|
|
1434
1437
|
const bufferSize = Math.ceil(MEMORY.SIZE * percent);
|
|
1435
|
-
const items = [];
|
|
1436
1438
|
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) {
|
|
1439
|
+
items.sort((a, b) => a[1][0] - b[1][0]);
|
|
1440
|
+
for (const [uri, item] of items) {
|
|
1445
1441
|
const size = item[3];
|
|
1446
1442
|
if (size > 0) {
|
|
1447
1443
|
purgeSize += size;
|
|
1448
1444
|
MEMORY.SIZE -= size;
|
|
1449
1445
|
}
|
|
1450
|
-
|
|
1446
|
+
MEMORY.CACHE.delete(uri);
|
|
1451
1447
|
++result;
|
|
1452
1448
|
if (purgeSize >= bufferSize) {
|
|
1453
1449
|
break;
|
|
1454
1450
|
}
|
|
1455
1451
|
}
|
|
1456
|
-
MEMORY.TOTAL = items.length - result;
|
|
1457
1452
|
}
|
|
1458
1453
|
}
|
|
1459
1454
|
return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
|
|
@@ -1499,6 +1494,9 @@ class FileManager extends core_1.Host {
|
|
|
1499
1494
|
else if (id && (id = +id) > 0) {
|
|
1500
1495
|
SESSION_LIMIT = Math.pow(10, id);
|
|
1501
1496
|
}
|
|
1497
|
+
if (logger.color === false) {
|
|
1498
|
+
LOGGER.PROGRESS_USECOLOR = false;
|
|
1499
|
+
}
|
|
1502
1500
|
if (logger.progress) {
|
|
1503
1501
|
let { scroll_buffer, max_width, use_color, text_wrap, color, bg_color, raw_mode, box_char } = logger.progress;
|
|
1504
1502
|
if ((scroll_buffer = (0, util_2.asInt)(scroll_buffer)) >= 0 && scroll_buffer <= 16) {
|
|
@@ -1554,7 +1552,7 @@ class FileManager extends core_1.Host {
|
|
|
1554
1552
|
}
|
|
1555
1553
|
static sanitizeAssets(assets, exclusions = []) {
|
|
1556
1554
|
for (const item of assets) {
|
|
1557
|
-
if ((0, types_1.ignoreFlag)(item
|
|
1555
|
+
if ((0, types_1.ignoreFlag)(item)) {
|
|
1558
1556
|
continue;
|
|
1559
1557
|
}
|
|
1560
1558
|
const initialValue = item.initialValue;
|
|
@@ -1614,7 +1612,7 @@ class FileManager extends core_1.Host {
|
|
|
1614
1612
|
if (recursive === 1 && path.basename(pathname) === filename) {
|
|
1615
1613
|
continue;
|
|
1616
1614
|
}
|
|
1617
|
-
const current = await this.readHash(pathname, { algorithm, digest }) + ' ' +
|
|
1615
|
+
const current = await this.readHash(pathname, { algorithm, digest }) + ' ' + core_1.Permission.toPosix(pathname).substring(root.length).replace(/^\//, '');
|
|
1618
1616
|
if (verbose) {
|
|
1619
1617
|
process.stdout.write(current + '\n');
|
|
1620
1618
|
}
|
|
@@ -1727,7 +1725,7 @@ class FileManager extends core_1.Host {
|
|
|
1727
1725
|
this[_j] = new Scheduler();
|
|
1728
1726
|
this[_k] = [[0, 0], [0, 0], [0, 0]];
|
|
1729
1727
|
this[_l] = null;
|
|
1730
|
-
this[_m] =
|
|
1728
|
+
this[_m] = null;
|
|
1731
1729
|
this[_o] = null;
|
|
1732
1730
|
if (isFunction(permission)) {
|
|
1733
1731
|
postFinalize = permission;
|
|
@@ -1740,7 +1738,7 @@ class FileManager extends core_1.Host {
|
|
|
1740
1738
|
this[kBaseDirectory] = path.normalize(baseDirectory[index] === path.sep ? baseDirectory.substring(0, index) : baseDirectory);
|
|
1741
1739
|
this.permission = permission && core_1.Host.isPermission(permission) ? permission : core_1.Host.getPermissionFromSettings();
|
|
1742
1740
|
this.sessionId = (++SESSION_ID === SESSION_LIMIT ? SESSION_ID = 1 : SESSION_ID).toString();
|
|
1743
|
-
const
|
|
1741
|
+
const assets = config.assets || [];
|
|
1744
1742
|
let targeted;
|
|
1745
1743
|
for (let i = 0, length = assets.length; i < length; ++i) {
|
|
1746
1744
|
const item = assets[i];
|
|
@@ -1754,24 +1752,24 @@ class FileManager extends core_1.Host {
|
|
|
1754
1752
|
if (encoding && encoding !== 'utf8' && encoding !== 'utf-8') {
|
|
1755
1753
|
item.encoding = encoding.endsWith('be') ? undefined : (0, types_1.getEncoding)(encoding);
|
|
1756
1754
|
}
|
|
1757
|
-
if ((0, types_1.usingFlag)(item
|
|
1755
|
+
if ((0, types_1.usingFlag)(item)) {
|
|
1758
1756
|
(targeted ||= []).push(item);
|
|
1759
1757
|
}
|
|
1760
1758
|
item.id ||= ++ASSET_ID;
|
|
1761
1759
|
}
|
|
1762
1760
|
this._assets = assets.slice(0);
|
|
1763
|
-
this[kIncremental] = incremental === "staging" ? "staging" : "none";
|
|
1761
|
+
this[kIncremental] = config.incremental === "staging" ? "staging" : "none";
|
|
1764
1762
|
if (targeted) {
|
|
1765
1763
|
this.using(...targeted);
|
|
1766
1764
|
}
|
|
1767
|
-
if (Array.isArray(dataSource)) {
|
|
1768
|
-
this.dataSourceItems.push(...dataSource);
|
|
1765
|
+
if (Array.isArray(config.dataSource)) {
|
|
1766
|
+
this.dataSourceItems.push(...config.dataSource);
|
|
1769
1767
|
}
|
|
1770
1768
|
if (this.willAbort(this)) {
|
|
1771
1769
|
this.abortable = true;
|
|
1772
1770
|
}
|
|
1773
|
-
if (
|
|
1774
|
-
applyTimeout(this[kProcessTimeout], timeout);
|
|
1771
|
+
if (config.timeout) {
|
|
1772
|
+
applyTimeout(this[kProcessTimeout] = Object.create(null), config.timeout);
|
|
1775
1773
|
}
|
|
1776
1774
|
if (isFunction(postFinalize)) {
|
|
1777
1775
|
this.on('end', postFinalize);
|
|
@@ -1784,19 +1782,11 @@ class FileManager extends core_1.Host {
|
|
|
1784
1782
|
if (MEMORY.EXCLUDE.length > 0) {
|
|
1785
1783
|
this.cacheToMemory.exclude = MEMORY.EXCLUDE;
|
|
1786
1784
|
}
|
|
1787
|
-
if (threads) {
|
|
1788
|
-
this.setTaskLimit(threads);
|
|
1785
|
+
if (typeof config.threads === 'number') {
|
|
1786
|
+
this.setTaskLimit(config.threads);
|
|
1789
1787
|
}
|
|
1790
1788
|
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
|
-
];
|
|
1789
|
+
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
1790
|
}
|
|
1801
1791
|
const request = new request_1();
|
|
1802
1792
|
request.host = this;
|
|
@@ -2058,79 +2048,96 @@ class FileManager extends core_1.Host {
|
|
|
2058
2048
|
else if ((0, types_1.isObject)(Target)) {
|
|
2059
2049
|
instance = new cloud_1(Target, database);
|
|
2060
2050
|
}
|
|
2061
|
-
if (instance) {
|
|
2062
|
-
|
|
2063
|
-
instance.init(this.config);
|
|
2064
|
-
observeFile(this, instance);
|
|
2065
|
-
return this.Cloud = instance;
|
|
2051
|
+
if (!instance) {
|
|
2052
|
+
return;
|
|
2066
2053
|
}
|
|
2067
|
-
|
|
2054
|
+
instance.host = this;
|
|
2055
|
+
instance.init(this.config);
|
|
2056
|
+
observeFile(this, instance);
|
|
2057
|
+
return this.Cloud = instance;
|
|
2068
2058
|
}
|
|
2069
2059
|
case 'watch': {
|
|
2070
|
-
|
|
2060
|
+
let instance;
|
|
2061
|
+
if ((0, types_1.isString)(Target)) {
|
|
2062
|
+
const module = args.shift();
|
|
2063
|
+
if ((0, types_1.isObject)(module)) {
|
|
2064
|
+
if (Target === "@e-mc/watch") {
|
|
2065
|
+
instance = new watch_1(module);
|
|
2066
|
+
}
|
|
2067
|
+
else if (isFunction(Target = tryPackage(this, Target, 16)) && Target.prototype instanceof watch_1) {
|
|
2068
|
+
instance = new Target(module);
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
else if ((0, types_1.isObject)(Target)) {
|
|
2073
|
+
instance = new watch_1(Target);
|
|
2074
|
+
}
|
|
2075
|
+
if (!instance) {
|
|
2076
|
+
return;
|
|
2077
|
+
}
|
|
2071
2078
|
instance.host = this;
|
|
2072
2079
|
instance.init(this.config);
|
|
2073
|
-
instance.whenModified
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
constructor.sanitizeAssets
|
|
2080
|
+
if (!instance.whenModified) {
|
|
2081
|
+
instance.whenModified = (assets, sanitize, postFinalize) => {
|
|
2082
|
+
if (typeof sanitize === 'function') {
|
|
2083
|
+
postFinalize = sanitize;
|
|
2084
|
+
sanitize = true;
|
|
2085
|
+
}
|
|
2086
|
+
if (sanitize) {
|
|
2087
|
+
FileManager.sanitizeAssets(assets);
|
|
2088
|
+
for (const { instance: document, constructor } of this.Document) {
|
|
2089
|
+
if (constructor.sanitizeAssets) {
|
|
2090
|
+
constructor.sanitizeAssets(assets.filter(item => this.hasDocument(document, item.document)));
|
|
2091
|
+
}
|
|
2083
2092
|
}
|
|
2084
2093
|
}
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2094
|
+
const manager = new FileManager(this.baseDirectory, { ...this.config, incremental: "none", assets }, postFinalize);
|
|
2095
|
+
for (const { constructor, params } of this.Document) {
|
|
2096
|
+
manager.install('document', constructor, ...params);
|
|
2097
|
+
}
|
|
2098
|
+
for (const { constructor, params } of this.Task) {
|
|
2099
|
+
manager.install('task', constructor, ...params);
|
|
2100
|
+
}
|
|
2101
|
+
if (this.Cloud) {
|
|
2102
|
+
manager.install('cloud', this.Cloud.module);
|
|
2103
|
+
}
|
|
2104
|
+
if (this.Image) {
|
|
2105
|
+
const mimeMap = new Map();
|
|
2106
|
+
let params = [];
|
|
2107
|
+
for (const [mimeType, handler] of this.Image) {
|
|
2108
|
+
const { constructor, params: trailing } = handler;
|
|
2109
|
+
if (mimeType === 'handler') {
|
|
2110
|
+
if (this.Image.size === 1) {
|
|
2111
|
+
manager.install('image', constructor, ...trailing);
|
|
2112
|
+
break;
|
|
2113
|
+
}
|
|
2114
|
+
params = trailing;
|
|
2115
|
+
}
|
|
2116
|
+
else if (params.length === 0) {
|
|
2117
|
+
params = trailing;
|
|
2105
2118
|
}
|
|
2106
|
-
|
|
2119
|
+
mimeMap.set(mimeType, constructor);
|
|
2107
2120
|
}
|
|
2108
|
-
|
|
2109
|
-
|
|
2121
|
+
if (mimeMap.size > 0) {
|
|
2122
|
+
manager.install('image', mimeMap, ...params);
|
|
2110
2123
|
}
|
|
2111
|
-
mimeMap.set(mimeType, constructor);
|
|
2112
2124
|
}
|
|
2113
|
-
if (
|
|
2114
|
-
manager.install('
|
|
2125
|
+
if (this.Compress) {
|
|
2126
|
+
manager.install('compress', this.Compress.module);
|
|
2115
2127
|
}
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
try {
|
|
2126
|
-
manager.processAssets();
|
|
2127
|
-
}
|
|
2128
|
-
catch (err) {
|
|
2129
|
-
manager.writeFail("Unknown", err, { startTime: manager.startTime });
|
|
2128
|
+
manager.sessionId = this.sessionId;
|
|
2129
|
+
manager.permission = this.permission;
|
|
2130
|
+
if (postFinalize) {
|
|
2131
|
+
try {
|
|
2132
|
+
manager.processAssets();
|
|
2133
|
+
}
|
|
2134
|
+
catch (err) {
|
|
2135
|
+
manager.writeFail("Unknown", err, { startTime: manager.startTime });
|
|
2136
|
+
}
|
|
2130
2137
|
}
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
}
|
|
2138
|
+
return manager;
|
|
2139
|
+
};
|
|
2140
|
+
}
|
|
2134
2141
|
return this.Watch = instance;
|
|
2135
2142
|
}
|
|
2136
2143
|
case 'image': {
|
|
@@ -2431,12 +2438,12 @@ class FileManager extends core_1.Host {
|
|
|
2431
2438
|
pathname = file.pathname || '';
|
|
2432
2439
|
}
|
|
2433
2440
|
const assets = this.assets;
|
|
2434
|
-
let target = matchPathname(path.join(pathname, filename)), modified;
|
|
2441
|
+
let target = matchPathname(path.join(pathname, filename)), modified = false;
|
|
2435
2442
|
for (let i = 0, j = 1, length = assets.length; i < length; ++i) {
|
|
2436
2443
|
const item = assets[i];
|
|
2437
2444
|
if (item !== file && item.filename && target === matchPathname(path.join(item.pathname || '', item.filename))) {
|
|
2438
|
-
const ext = path.
|
|
2439
|
-
filename =
|
|
2445
|
+
const { name, ext } = path.parse(filename);
|
|
2446
|
+
filename = name + '_' + j + ext;
|
|
2440
2447
|
target = matchPathname(path.join(pathname, filename));
|
|
2441
2448
|
modified = true;
|
|
2442
2449
|
i = -1;
|
|
@@ -2594,7 +2601,7 @@ class FileManager extends core_1.Host {
|
|
|
2594
2601
|
return fs.readFileSync(localUri);
|
|
2595
2602
|
}
|
|
2596
2603
|
catch (err) {
|
|
2597
|
-
if (!(base64 && core_1.Host.isErrorCode(err, 'ENOENT'))) {
|
|
2604
|
+
if (!(base64 && core_1.Host.isErrorCode(err, 'ENOENT', 'EACCES'))) {
|
|
2598
2605
|
this.writeFail(["Unable to read file", path.basename(localUri)], err, 32);
|
|
2599
2606
|
base64 = undefined;
|
|
2600
2607
|
}
|
|
@@ -2795,7 +2802,7 @@ class FileManager extends core_1.Host {
|
|
|
2795
2802
|
async compressFile(file, overwrite = true) {
|
|
2796
2803
|
const { localUri, compress } = file;
|
|
2797
2804
|
const instance = this.Compress;
|
|
2798
|
-
if (instance && compress && localUri && (this.has(localUri) || (0, types_1.existsFlag)(file
|
|
2805
|
+
if (instance && compress && localUri && (this.has(localUri) || (0, types_1.existsFlag)(file))) {
|
|
2799
2806
|
const tasks = [];
|
|
2800
2807
|
for (const options of compress) {
|
|
2801
2808
|
const { format, condition } = options;
|
|
@@ -2820,8 +2827,8 @@ class FileManager extends core_1.Host {
|
|
|
2820
2827
|
}
|
|
2821
2828
|
if (output && (!condition || withinSizeRange(localUri, condition))) {
|
|
2822
2829
|
try {
|
|
2823
|
-
if (overwrite || !fs.existsSync(output) || !(0, types_1.existsFlag)(file
|
|
2824
|
-
options.timeout = this
|
|
2830
|
+
if (overwrite || !fs.existsSync(output) || !(0, types_1.existsFlag)(file) && fs.statSync(output).mtimeMs < this.startTime) {
|
|
2831
|
+
options.timeout = this.getNamedTimeout('compress');
|
|
2825
2832
|
tasks.push(instance.tryFile(file.buffer || localUri, output, options).then(() => {
|
|
2826
2833
|
const outFile = options.outFile;
|
|
2827
2834
|
if (outFile) {
|
|
@@ -3023,8 +3030,7 @@ class FileManager extends core_1.Host {
|
|
|
3023
3030
|
}
|
|
3024
3031
|
}
|
|
3025
3032
|
getProcessTimeout(handler) {
|
|
3026
|
-
|
|
3027
|
-
return this[kProcessTimeout][moduleName] ?? PROCESS_TIMEOUT[moduleName] ?? (handler.constructor.PROCESS_TIMEOUT || 0);
|
|
3033
|
+
return this.getNamedTimeout(handler.instance.moduleName) ?? (handler.constructor.PROCESS_TIMEOUT || 0);
|
|
3028
3034
|
}
|
|
3029
3035
|
clearProcessTimeout() {
|
|
3030
3036
|
const timerMain = this[KTimerMain];
|
|
@@ -3207,7 +3213,7 @@ class FileManager extends core_1.Host {
|
|
|
3207
3213
|
}
|
|
3208
3214
|
const { processing, processTimeout } = this;
|
|
3209
3215
|
const currentTime = Date.now();
|
|
3210
|
-
let aborted;
|
|
3216
|
+
let aborted = false;
|
|
3211
3217
|
for (let i = 0; i < processing.length; ++i) {
|
|
3212
3218
|
const data = processing[i];
|
|
3213
3219
|
const file = data.file;
|
|
@@ -3270,7 +3276,7 @@ class FileManager extends core_1.Host {
|
|
|
3270
3276
|
const groupData = new ProcessGroup();
|
|
3271
3277
|
const imported = assets.filter(item => item.imported && (0, types_1.isArray)(item.imported));
|
|
3272
3278
|
for (let item of assets) {
|
|
3273
|
-
if (item.invalid || (0, types_1.ignoreFlag)(item
|
|
3279
|
+
if (item.invalid || (0, types_1.ignoreFlag)(item)) {
|
|
3274
3280
|
continue;
|
|
3275
3281
|
}
|
|
3276
3282
|
let download = this.setLocalUri(item), uri = item.uri;
|
|
@@ -3310,11 +3316,11 @@ class FileManager extends core_1.Host {
|
|
|
3310
3316
|
if (etag && imported.some(file => file.imported.includes(uri))) {
|
|
3311
3317
|
item.incremental = "none";
|
|
3312
3318
|
}
|
|
3313
|
-
else if (!(0, types_1.mainFlag)(item
|
|
3319
|
+
else if (!(0, types_1.mainFlag)(item)) {
|
|
3314
3320
|
let cached;
|
|
3315
3321
|
const { bundleId, bundleIndex = -1 } = item;
|
|
3316
3322
|
const setBuffer = (target) => {
|
|
3317
|
-
if (!etag && (uri = target.uri) && (cached = MEMORY.CACHE
|
|
3323
|
+
if (!etag && (uri = target.uri) && (cached = MEMORY.CACHE.get(uri))) {
|
|
3318
3324
|
target.etag = cached[5];
|
|
3319
3325
|
target.contentLength = cached[3];
|
|
3320
3326
|
return true;
|
|
@@ -3326,7 +3332,7 @@ class FileManager extends core_1.Host {
|
|
|
3326
3332
|
if (!(0, types_1.isEmpty)(bundleId) && bundleIndex > 0) {
|
|
3327
3333
|
const target = assets.find(parent => parent.bundleIndex === 0 && parent.bundleId === bundleId);
|
|
3328
3334
|
if (target) {
|
|
3329
|
-
if ((0, types_1.existsFlag)(target
|
|
3335
|
+
if ((0, types_1.existsFlag)(target)) {
|
|
3330
3336
|
setBuffer(item);
|
|
3331
3337
|
item.invalid = true;
|
|
3332
3338
|
}
|
|
@@ -3399,10 +3405,10 @@ class FileManager extends core_1.Host {
|
|
|
3399
3405
|
if (!etag) {
|
|
3400
3406
|
(0, asset_1.setInitialValue)(item, false).buffer = buffer;
|
|
3401
3407
|
}
|
|
3402
|
-
else if (uri && CACHE_ETAG
|
|
3408
|
+
else if (uri && CACHE_ETAG.has(uri)) {
|
|
3403
3409
|
const initialValue = (0, asset_1.setInitialValue)(item, false);
|
|
3404
3410
|
initialValue.buffer = buffer;
|
|
3405
|
-
initialValue.etag = CACHE_ETAG
|
|
3411
|
+
initialValue.etag = CACHE_ETAG.get(uri);
|
|
3406
3412
|
}
|
|
3407
3413
|
}
|
|
3408
3414
|
catch {
|
|
@@ -3513,11 +3519,11 @@ class FileManager extends core_1.Host {
|
|
|
3513
3519
|
downloading[uri] = [];
|
|
3514
3520
|
}
|
|
3515
3521
|
const url = item.url;
|
|
3516
|
-
let mainEtag = false, encoding = item.encoding, client = null, cacheDir, cacheBuffer;
|
|
3522
|
+
let mainEtag = false, encoding = item.encoding, client = null, cacheDir = false, cacheBuffer = false;
|
|
3517
3523
|
if (type === 1) {
|
|
3518
3524
|
cacheDir = cacheToDisk.has(url) && isCacheable(item);
|
|
3519
3525
|
cacheBuffer = cacheToMemory.has(url);
|
|
3520
|
-
mainEtag = (0, types_1.mainFlag)(item
|
|
3526
|
+
mainEtag = (0, types_1.mainFlag)(item) && (cacheEtag || item.incremental === "etag");
|
|
3521
3527
|
}
|
|
3522
3528
|
const downloadUri = (request, etagDir) => {
|
|
3523
3529
|
if (checkEtag) {
|
|
@@ -3585,7 +3591,7 @@ class FileManager extends core_1.Host {
|
|
|
3585
3591
|
etagDir = encodeURIComponent(etag);
|
|
3586
3592
|
if (incremental !== false || item.incremental === true) {
|
|
3587
3593
|
const location = href.toString();
|
|
3588
|
-
const cached = MEMORY.CACHE
|
|
3594
|
+
const cached = MEMORY.CACHE.get(location);
|
|
3589
3595
|
let buffer;
|
|
3590
3596
|
if (cached) {
|
|
3591
3597
|
if (etagDir === cached[5] && (!encoding || encoding === cached[2])) {
|
|
@@ -3747,7 +3753,7 @@ class FileManager extends core_1.Host {
|
|
|
3747
3753
|
}
|
|
3748
3754
|
else {
|
|
3749
3755
|
const ext = item.filename && path.extname(item.filename);
|
|
3750
|
-
let found;
|
|
3756
|
+
let found = false;
|
|
3751
3757
|
for (const file of result) {
|
|
3752
3758
|
if (!found && ext === path.extname(file).toLowerCase()) {
|
|
3753
3759
|
try {
|
|
@@ -3814,9 +3820,13 @@ class FileManager extends core_1.Host {
|
|
|
3814
3820
|
const received = args[1];
|
|
3815
3821
|
const total = args[2];
|
|
3816
3822
|
if (received === 0 && total === 0) {
|
|
3817
|
-
if (
|
|
3823
|
+
if (typeof args[3] === 'bigint') {
|
|
3818
3824
|
found.dataTime = args[3];
|
|
3819
3825
|
}
|
|
3826
|
+
else if (Array.isArray(args[3])) {
|
|
3827
|
+
const [s, n] = args[3];
|
|
3828
|
+
found.dataTime = BigInt(s * 1000000000) + BigInt(n);
|
|
3829
|
+
}
|
|
3820
3830
|
return;
|
|
3821
3831
|
}
|
|
3822
3832
|
found.receivedBytes = received;
|
|
@@ -3914,7 +3924,7 @@ class FileManager extends core_1.Host {
|
|
|
3914
3924
|
}
|
|
3915
3925
|
const diffTime = currentTime - item.startTime;
|
|
3916
3926
|
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
|
|
3927
|
+
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
3928
|
let output = time + ` ${chalk.blackBright(LOGGER.TITLE_SEP)} ` + (endTime > 0 && bars === 0 ? chalk.grey(item.url) : item.url) + spacer;
|
|
3919
3929
|
if (barLength === 1) {
|
|
3920
3930
|
output += ` ${endTime > 0 ? bars === 0 ? chalk.red('ERR!') : LOGGER.PROGRESS_COMPLETE : formatPercent(percent)} ` + spacer;
|
|
@@ -3933,7 +3943,7 @@ class FileManager extends core_1.Host {
|
|
|
3933
3943
|
}
|
|
3934
3944
|
output += '\n';
|
|
3935
3945
|
if (!LOGGER.PROGRESS_USECOLOR) {
|
|
3936
|
-
output =
|
|
3946
|
+
output = (0, node_util_1.stripVTControlCharacters)(output);
|
|
3937
3947
|
}
|
|
3938
3948
|
PROCESS_STDOUT.clearLine(0);
|
|
3939
3949
|
PROCESS_STDOUT.write(output);
|
|
@@ -3949,7 +3959,7 @@ class FileManager extends core_1.Host {
|
|
|
3949
3959
|
processTask.section(redraw);
|
|
3950
3960
|
const { PROGRESS_COLOR: color, PROGRESS_BGCOLOR: bgColor, PROGRESS_USECOLOR: useColor, PROGRESS_TEXTWRAP: messageTextWrap } = LOGGER;
|
|
3951
3961
|
const scroll = processTask.scroll;
|
|
3952
|
-
let start = 0, end = 0, output, last;
|
|
3962
|
+
let start = 0, end = 0, output = false, last;
|
|
3953
3963
|
if (cleared) {
|
|
3954
3964
|
logDelayed = this._logDelayed;
|
|
3955
3965
|
end = Math.min(logDelayed.length, scrollHeight);
|
|
@@ -4056,7 +4066,7 @@ class FileManager extends core_1.Host {
|
|
|
4056
4066
|
}
|
|
4057
4067
|
else {
|
|
4058
4068
|
if (data instanceof URL && data.protocol === 'file:') {
|
|
4059
|
-
data = (0,
|
|
4069
|
+
data = (0, node_url_1.fileURLToPath)(data);
|
|
4060
4070
|
}
|
|
4061
4071
|
if ((0, types_1.isString)(data) && core_1.Host.isPath(data, true) && this.canRead(data)) {
|
|
4062
4072
|
data = fs.createReadStream(data);
|
|
@@ -4116,7 +4126,7 @@ class FileManager extends core_1.Host {
|
|
|
4116
4126
|
for (let i = 0, length = output.length, buffer = null; i < length; ++i) {
|
|
4117
4127
|
const options = output[i];
|
|
4118
4128
|
options.mimeType = mimeType;
|
|
4119
|
-
options.timeout ??= this
|
|
4129
|
+
options.timeout ??= this.getNamedTimeout('compress');
|
|
4120
4130
|
await compress.tryImage(buffer || files.length === 1 && item.buffer || file, file, options)
|
|
4121
4131
|
.then(result => {
|
|
4122
4132
|
if (result) {
|
|
@@ -4192,7 +4202,7 @@ class FileManager extends core_1.Host {
|
|
|
4192
4202
|
const baseDirectory = this.baseDirectory;
|
|
4193
4203
|
checksum.joinRoot = true;
|
|
4194
4204
|
checksum.throwsEmpty = true;
|
|
4195
|
-
const sumTime = LOG_TIMEELAPSED ? process.hrtime() : 0;
|
|
4205
|
+
const sumTime = LOG_TIMEELAPSED ? process.hrtime.bigint() : 0;
|
|
4196
4206
|
const files = (await FileManager.writeChecksum(baseDirectory, checksum.filename, checksum));
|
|
4197
4207
|
if (sumTime) {
|
|
4198
4208
|
this.writeTimeElapsed(checksum.algorithm || "sha256", [baseDirectory, files.length + (files.length === 1 ? ' file' : ' files')], sumTime, { ...core_1.Host.LOG_STYLE_WARN });
|
|
@@ -4224,7 +4234,7 @@ class FileManager extends core_1.Host {
|
|
|
4224
4234
|
if (LOG_TIMEELAPSED) {
|
|
4225
4235
|
this.writeTimeElapsed('READY', 'Finalizing assets...', this.startTime, { ...core_1.Host.LOG_STYLE_WARN, showCpu: true });
|
|
4226
4236
|
}
|
|
4227
|
-
const startTime = process.hrtime();
|
|
4237
|
+
const startTime = process.hrtime.bigint();
|
|
4228
4238
|
const filesToRemove = this.filesToRemove;
|
|
4229
4239
|
for (const [file, output] of this.filesToCompare) {
|
|
4230
4240
|
const localUri = file.localUri;
|
|
@@ -4343,8 +4353,7 @@ class FileManager extends core_1.Host {
|
|
|
4343
4353
|
message.push('CACHE ' + (count > 1 ? count + ' / ' : '') + (0, types_1.formatSize)(size));
|
|
4344
4354
|
}
|
|
4345
4355
|
if (MEMORY.SIZE > 0) {
|
|
4346
|
-
|
|
4347
|
-
message.push('BUFFER ' + (bufferCount > 1 ? bufferCount + ' / ' : '') + (0, types_1.formatSize)(MEMORY.SIZE));
|
|
4356
|
+
message.push('BUFFER ' + (MEMORY.CACHE.size > 1 ? MEMORY.CACHE.size + ' / ' : '') + (0, types_1.formatSize)(MEMORY.SIZE));
|
|
4348
4357
|
}
|
|
4349
4358
|
this.writeTimeElapsed('CLOSE', ['No further modifications', message.length > 0 ? message.join(chalk.blackBright(LOGGER.MESSAGE_SEP)) : ''], startTime, { ...core_1.Host.LOG_STYLE_WARN });
|
|
4350
4359
|
}
|
|
@@ -4435,6 +4444,10 @@ class FileManager extends core_1.Host {
|
|
|
4435
4444
|
this.done = true;
|
|
4436
4445
|
}
|
|
4437
4446
|
}
|
|
4447
|
+
getNamedTimeout(name) {
|
|
4448
|
+
const timeout = this[kProcessTimeout];
|
|
4449
|
+
return timeout && name in timeout ? timeout[name] : PROCESS_TIMEOUT[name];
|
|
4450
|
+
}
|
|
4438
4451
|
set restarting(value) {
|
|
4439
4452
|
this.finalizeState = (this[kRestarting] = value) ? 3 : 0;
|
|
4440
4453
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/file-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
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.0",
|
|
24
|
+
"@e-mc/compress": "0.11.0",
|
|
25
|
+
"@e-mc/core": "0.11.0",
|
|
26
|
+
"@e-mc/document": "0.11.0",
|
|
27
|
+
"@e-mc/image": "0.11.0",
|
|
28
|
+
"@e-mc/request": "0.11.0",
|
|
29
|
+
"@e-mc/task": "0.11.0",
|
|
30
|
+
"@e-mc/types": "0.11.0",
|
|
31
|
+
"@e-mc/watch": "0.11.0",
|
|
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
|
}
|