@e-mc/file-manager 0.14.0 → 0.14.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/README.md +10 -10
- package/index.js +104 -45
- package/package.json +10 -13
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.14.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.14.1/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { ChecksumValue, DataSource, IncrementalMatch, TaskAction } from "./squared";
|
|
@@ -297,15 +297,15 @@ NOTE: **FileManager** is a sub-class of [Host](https://www.npmjs.com/package/@e-
|
|
|
297
297
|
|
|
298
298
|
## References
|
|
299
299
|
|
|
300
|
-
- https://www.unpkg.com/@e-mc/types@0.14.
|
|
301
|
-
- https://www.unpkg.com/@e-mc/types@0.14.
|
|
302
|
-
- https://www.unpkg.com/@e-mc/types@0.14.
|
|
303
|
-
- https://www.unpkg.com/@e-mc/types@0.14.
|
|
304
|
-
- https://www.unpkg.com/@e-mc/types@0.14.
|
|
305
|
-
- https://www.unpkg.com/@e-mc/types@0.14.
|
|
306
|
-
- https://www.unpkg.com/@e-mc/types@0.14.
|
|
307
|
-
- https://www.unpkg.com/@e-mc/types@0.14.
|
|
308
|
-
- https://www.unpkg.com/@e-mc/types@0.14.
|
|
300
|
+
- https://www.unpkg.com/@e-mc/types@0.14.1/lib/squared.d.ts
|
|
301
|
+
- https://www.unpkg.com/@e-mc/types@0.14.1/lib/asset.d.ts
|
|
302
|
+
- https://www.unpkg.com/@e-mc/types@0.14.1/lib/core.d.ts
|
|
303
|
+
- https://www.unpkg.com/@e-mc/types@0.14.1/lib/filemanager.d.ts
|
|
304
|
+
- https://www.unpkg.com/@e-mc/types@0.14.1/lib/logger.d.ts
|
|
305
|
+
- https://www.unpkg.com/@e-mc/types@0.14.1/lib/module.d.ts
|
|
306
|
+
- https://www.unpkg.com/@e-mc/types@0.14.1/lib/node.d.ts
|
|
307
|
+
- https://www.unpkg.com/@e-mc/types@0.14.1/lib/request.d.ts
|
|
308
|
+
- https://www.unpkg.com/@e-mc/types@0.14.1/lib/settings.d.ts
|
|
309
309
|
|
|
310
310
|
* https://www.npmjs.com/package/@types/node
|
|
311
311
|
|
package/index.js
CHANGED
|
@@ -12,7 +12,7 @@ const { DOWNLOAD_TYPE, FILE_TYPE, THRESHOLD, asExt, cloneFlag, convertTime, crea
|
|
|
12
12
|
const { AbortComponent, Host, Permission } = require('@e-mc/core');
|
|
13
13
|
const { isEqual, setInitialValue } = require('@e-mc/document/asset');
|
|
14
14
|
const { concatString, getNewline } = require('@e-mc/document/util');
|
|
15
|
-
const { asFloat, asInt, byteLength, checkRetryable, fromSeconds, fromURL, getSize, getTransferRate, hasSameStat, hasSize } = require('@e-mc/request/util');
|
|
15
|
+
const { asFloat, asInt, byteLength, checkRetryable, fromSeconds, fromURL, getSize, getTransferRate, hasSameStat, hasSize, parseHeader } = require('@e-mc/request/util');
|
|
16
16
|
const Request = require('@e-mc/request');
|
|
17
17
|
const Image = require('@e-mc/image');
|
|
18
18
|
const Watch = require('@e-mc/watch');
|
|
@@ -134,7 +134,7 @@ function recurseDir(output, subDirs, options) {
|
|
|
134
134
|
const baseDir = path.join(...subDirs);
|
|
135
135
|
const items = fs.readdirSync(baseDir, { withFileTypes: true })
|
|
136
136
|
.filter(item => {
|
|
137
|
-
if (ignoreGlob
|
|
137
|
+
if (ignoreGlob?.(fromDir ? path.posix.join(fromDir, item.name) : item.name)) {
|
|
138
138
|
return false;
|
|
139
139
|
}
|
|
140
140
|
return item.name;
|
|
@@ -153,12 +153,12 @@ function recurseDir(output, subDirs, options) {
|
|
|
153
153
|
for (const item of items) {
|
|
154
154
|
if (!item.isDirectory()) {
|
|
155
155
|
const pathname = path.join(baseDir, item.name);
|
|
156
|
-
if (item.isSymbolicLink() && Host.isDir(pathname) || ignore.length > 0 && (
|
|
156
|
+
if (item.isSymbolicLink() && Host.isDir(pathname) || ignore.length > 0 && !hasPath(ignore, pathname)) {
|
|
157
157
|
continue;
|
|
158
158
|
}
|
|
159
159
|
output.push(pathname);
|
|
160
160
|
}
|
|
161
|
-
else if (recursive && (subDirs.length > 1 || (
|
|
161
|
+
else if (recursive && (subDirs.length > 1 || !hasPath(ignoreRoot, item.name))) {
|
|
162
162
|
recurseDir(output, subDirs.concat(item.name), options);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
@@ -263,7 +263,7 @@ function equalAddress(value, other) {
|
|
|
263
263
|
const b = decodeURIComponent(other);
|
|
264
264
|
return a === b || a === other || value === b;
|
|
265
265
|
}
|
|
266
|
-
function processHeaders(
|
|
266
|
+
function processHeaders(headers, item, lastModified, mainEtag) {
|
|
267
267
|
const contentLength = parseInt(headers['content-length']);
|
|
268
268
|
if (contentLength > 0) {
|
|
269
269
|
item.contentLength = contentLength;
|
|
@@ -282,6 +282,36 @@ function processHeaders(item, headers, lastModified, mainEtag) {
|
|
|
282
282
|
return item.lastModified = headers['last-modified'];
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
|
+
function processCacheHeaders(headers, noCache, noStore) {
|
|
286
|
+
if (noStore) {
|
|
287
|
+
return NaN;
|
|
288
|
+
}
|
|
289
|
+
const cacheControl = parseHeader(headers, 'cache-control');
|
|
290
|
+
if (cacheControl) {
|
|
291
|
+
if (cacheControl.includes('no-store')) {
|
|
292
|
+
return -1;
|
|
293
|
+
}
|
|
294
|
+
const maxAge = cacheControl.find(value => value.startsWith('max-age='));
|
|
295
|
+
if (maxAge && (!noCache || cacheControl.includes('public') || cacheControl.includes('must-revalidate'))) {
|
|
296
|
+
const age = parseHeader(headers, 'age');
|
|
297
|
+
let result = parseInt(maxAge.split('=').pop()) * 1000;
|
|
298
|
+
if (age) {
|
|
299
|
+
result -= age;
|
|
300
|
+
if (result < 0 && noCache) {
|
|
301
|
+
return -1;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return result > 0 ? result : 0;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (!noCache) {
|
|
308
|
+
const expires = parseHeader(headers, 'expires');
|
|
309
|
+
if (expires && !isNaN(expires)) {
|
|
310
|
+
const date = parseHeader(headers, 'date') || Date.now();
|
|
311
|
+
return expires - date;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
285
315
|
function setContent(item, buffer) {
|
|
286
316
|
if (typeof buffer === 'string') {
|
|
287
317
|
item.sourceUTF8 = buffer;
|
|
@@ -312,7 +342,7 @@ async function doVerifyChecksum(root, from, options, nested) {
|
|
|
312
342
|
const filename = path.basename(from);
|
|
313
343
|
const files = [];
|
|
314
344
|
from = joinRoot ? path.join(root, filename) : path.resolve(from);
|
|
315
|
-
recurseDir(files, [root], { ignore:
|
|
345
|
+
recurseDir(files, [root], { ignore: toPosix([...ignore, from]), ignoreRoot: toPosix(ignoreRoot), sortBy, recursive });
|
|
316
346
|
const items = fs.readFileSync(from, 'utf8').split('\n').map(item => {
|
|
317
347
|
const index = item.indexOf(' ');
|
|
318
348
|
return [item.slice(0, index), path.join(root, item.slice(index + 1))];
|
|
@@ -468,13 +498,15 @@ const downloadStats = () => [[0, 0], [0, 0], [0, 0]];
|
|
|
468
498
|
const isCacheable = (item) => item.initialValue?.cacheable !== false;
|
|
469
499
|
const getPmOptions = (value, { matchBase = value.startsWith('*') && !value.includes('/'), dot = false } = {}) => ({ nocase: Host.PLATFORM_WIN32, matchBase, dot });
|
|
470
500
|
const isDownloadAll = (type) => type === 4 || type === 0;
|
|
501
|
+
const isStored = (noCache, maxAge) => !noCache || typeof maxAge === 'number';
|
|
471
502
|
const hasFiles = (type, uri) => type === 3 || type === 4 || type === 0 && Request.isRclone(uri);
|
|
472
503
|
const hasIncremental = (value) => value === "etag" || value === "exists";
|
|
473
|
-
const
|
|
474
|
-
const
|
|
504
|
+
const hasPath = (values, name) => Host.PLATFORM_WIN32 ? !values.includes(name.toLowerCase()) : !values.includes(name);
|
|
505
|
+
const toPathCase = (value) => Host.PLATFORM_WIN32 ? value.toLowerCase() : value;
|
|
506
|
+
const toPosix = (values) => Host.PLATFORM_WIN32 ? values.map(value => Permission.toPosix(value).toLowerCase()) : values;
|
|
475
507
|
const formatPercent = (value) => Math.round(value).toString().padStart(3) + '%';
|
|
476
508
|
const formatLength = (value, length) => `${length} ${value + (length === 1 ? '' : 's')}`;
|
|
477
|
-
const checkEOF = (value) => value.
|
|
509
|
+
const checkEOF = (value) => value.at(-1) === '\n' ? value : value + '\n';
|
|
478
510
|
const checksumFile = (algorithm) => "checksum" + '.' + (isString(algorithm) ? algorithm.toLowerCase() : "sha256");
|
|
479
511
|
const ignoreAsset = (item, exists) => item.invalid || hasBit(item.flags, 1 | (!exists ? 128 : 0));
|
|
480
512
|
const validateChecksum = (host, item, buffer, localUri = item.localUri) => !item.checksum || host.checkHash(item.checksum, buffer, localUri);
|
|
@@ -609,13 +641,13 @@ class HttpDiskCache {
|
|
|
609
641
|
if (!this.enabled) {
|
|
610
642
|
return false;
|
|
611
643
|
}
|
|
612
|
-
|
|
613
|
-
|
|
644
|
+
if (typeof uri === 'string') {
|
|
645
|
+
try {
|
|
614
646
|
uri = new URL(uri);
|
|
615
647
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
648
|
+
catch {
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
619
651
|
}
|
|
620
652
|
const flags = this._flags;
|
|
621
653
|
if (flags === 0) {
|
|
@@ -639,7 +671,14 @@ class HttpDiskCache {
|
|
|
639
671
|
}
|
|
640
672
|
return true;
|
|
641
673
|
}
|
|
642
|
-
add(uri, etag, target, { buffer, contentLength = getSize(target) } = {}) {
|
|
674
|
+
add(uri, etag, target, { buffer, contentLength = getSize(target), maxAge = 0 } = {}) {
|
|
675
|
+
if (maxAge < 0) {
|
|
676
|
+
this.clear(target);
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
if (isNaN(maxAge)) {
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
643
682
|
let tempDir;
|
|
644
683
|
if (contentLength <= this.limit && (tempDir = this.host.getCacheDir(uri))) {
|
|
645
684
|
const baseDir = path.join(tempDir, etag);
|
|
@@ -654,7 +693,7 @@ class HttpDiskCache {
|
|
|
654
693
|
else {
|
|
655
694
|
fs.copyFileSync(target, tempUri);
|
|
656
695
|
}
|
|
657
|
-
const expires = this.expires;
|
|
696
|
+
const expires = maxAge || this.expires;
|
|
658
697
|
if (expires > 0 && expires < Infinity) {
|
|
659
698
|
setTimeout(() => {
|
|
660
699
|
this.clear(target);
|
|
@@ -741,7 +780,14 @@ class HttpMemoryCache extends HttpDiskCache {
|
|
|
741
780
|
has(uri) {
|
|
742
781
|
return this.expires > 0 && super.has(uri);
|
|
743
782
|
}
|
|
744
|
-
add(uri, etag, buffer, { encoding, toDisk, contentLength = Buffer.byteLength(buffer, encoding) } = {}) {
|
|
783
|
+
add(uri, etag, buffer, { encoding, toDisk, contentLength = Buffer.byteLength(buffer, encoding), maxAge = 0 } = {}) {
|
|
784
|
+
if (maxAge < 0) {
|
|
785
|
+
this.clear(uri);
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
if (isNaN(maxAge)) {
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
745
791
|
if (contentLength <= this.limit) {
|
|
746
792
|
if (uri instanceof URL) {
|
|
747
793
|
uri = uri.href;
|
|
@@ -753,10 +799,11 @@ class HttpMemoryCache extends HttpDiskCache {
|
|
|
753
799
|
const item = [Date.now(), buffer, encoding, contentLength, uri, etag];
|
|
754
800
|
this._items.push(item);
|
|
755
801
|
MEMORY.CACHE.set(uri, item);
|
|
756
|
-
|
|
802
|
+
const expires = maxAge || this.expires;
|
|
803
|
+
if (expires < Infinity) {
|
|
757
804
|
setTimeout(() => {
|
|
758
805
|
this.clear(uri);
|
|
759
|
-
}, Math.min(
|
|
806
|
+
}, Math.min(expires, Host.MAX_TIMEOUT));
|
|
760
807
|
}
|
|
761
808
|
}
|
|
762
809
|
else {
|
|
@@ -862,10 +909,14 @@ class ProcessFile {
|
|
|
862
909
|
const parent = host.assets.find(item => item.bundleIndex === 0 && item.bundleId === bundleId);
|
|
863
910
|
if (parent) {
|
|
864
911
|
(parent.bundleQueue ||= []).push(new Promise(resolve => {
|
|
865
|
-
host.Request.open(url, { method: 'HEAD', httpVersion: 1 })
|
|
912
|
+
host.Request.open(url, { method: 'HEAD', httpVersion: 1, headers: file.headers })
|
|
866
913
|
.on('response', res => {
|
|
867
|
-
|
|
868
|
-
|
|
914
|
+
const statusCode = res.statusCode;
|
|
915
|
+
if (statusCode === 204 || statusCode === 304) {
|
|
916
|
+
file.contentLength = 0;
|
|
917
|
+
}
|
|
918
|
+
else if (statusCode < 300) {
|
|
919
|
+
processHeaders(res.headers, file, false, false);
|
|
869
920
|
}
|
|
870
921
|
resolve(file);
|
|
871
922
|
})
|
|
@@ -992,11 +1043,11 @@ class ProcessFile {
|
|
|
992
1043
|
for (const queue of items) {
|
|
993
1044
|
const encoding = queue.encoding ||= 'utf8';
|
|
994
1045
|
const { uri, fetchType: type } = queue;
|
|
995
|
-
let tempFile;
|
|
1046
|
+
let tempFile, maxAge;
|
|
996
1047
|
if (checkEtag && queue.trailingContent) {
|
|
997
1048
|
checkEtag = false;
|
|
998
1049
|
}
|
|
999
|
-
const verifyBundle = (value, etag, checked) => {
|
|
1050
|
+
const verifyBundle = (value, etag, checked, noCache) => {
|
|
1000
1051
|
if (!queue.invalid) {
|
|
1001
1052
|
if (!checked && !validateChecksum(host, queue, value, localUri)) {
|
|
1002
1053
|
queue.invalid = true;
|
|
@@ -1006,10 +1057,11 @@ class ProcessFile {
|
|
|
1006
1057
|
value = value.toString(encoding);
|
|
1007
1058
|
}
|
|
1008
1059
|
const url = queue.url;
|
|
1009
|
-
if (etag && host.cacheToMemory.has(url)) {
|
|
1060
|
+
if (etag && host.cacheToMemory.has(url) && isStored(noCache, maxAge)) {
|
|
1010
1061
|
host.cacheToMemory.add(url, encodeURIComponent(etag), value, {
|
|
1011
|
-
encoding,
|
|
1012
1062
|
contentLength: queue.contentLength,
|
|
1063
|
+
maxAge,
|
|
1064
|
+
encoding,
|
|
1013
1065
|
toDisk: !tempFile && isCacheable(queue) ? queue.filename || queue.localUri && path.basename(queue.localUri) : ''
|
|
1014
1066
|
});
|
|
1015
1067
|
}
|
|
@@ -1026,6 +1078,8 @@ class ProcessFile {
|
|
|
1026
1078
|
const options = {
|
|
1027
1079
|
url,
|
|
1028
1080
|
encoding,
|
|
1081
|
+
headers: queue.headers,
|
|
1082
|
+
noCache: true,
|
|
1029
1083
|
statusMessage: uri + ` (${queue.bundleIndex})`
|
|
1030
1084
|
};
|
|
1031
1085
|
let etag, pipeTo;
|
|
@@ -1078,14 +1132,15 @@ class ProcessFile {
|
|
|
1078
1132
|
options.httpVersion = 1;
|
|
1079
1133
|
}
|
|
1080
1134
|
options.connected = (headers) => {
|
|
1081
|
-
etag = processHeaders(
|
|
1135
|
+
etag = processHeaders(headers, queue, !!host.Watch, false);
|
|
1136
|
+
maxAge = processCacheHeaders(headers, options.noCache, options.noStore);
|
|
1082
1137
|
return true;
|
|
1083
1138
|
};
|
|
1084
1139
|
}
|
|
1085
1140
|
tasks.push(new Promise((resolve, reject) => {
|
|
1086
1141
|
void host.scheduleTask(url || uri, options, (data) => {
|
|
1087
1142
|
if (data) {
|
|
1088
|
-
verifyBundle(data, etag);
|
|
1143
|
+
verifyBundle(data, etag, false, options.noCache);
|
|
1089
1144
|
}
|
|
1090
1145
|
else {
|
|
1091
1146
|
queue.invalid = true;
|
|
@@ -1129,7 +1184,7 @@ class ProcessFile {
|
|
|
1129
1184
|
}
|
|
1130
1185
|
const pathname = getTempDir(true);
|
|
1131
1186
|
tasks.push(new Promise((resolve, reject) => {
|
|
1132
|
-
void host.scheduleTask(queue.url || uri, { pathname, binOpts: queue.binOpts || file.binOpts }, (result) => {
|
|
1187
|
+
void host.scheduleTask(queue.url || uri, { pathname, binOpts: queue.binOpts || file.binOpts, headers: queue.headers }, (result) => {
|
|
1133
1188
|
if (result.length > 0) {
|
|
1134
1189
|
verifyBundle(bundleTorrent(host, result, mimeType, encoding));
|
|
1135
1190
|
}
|
|
@@ -1286,6 +1341,7 @@ class FileManager extends Host {
|
|
|
1286
1341
|
result = MEMORY.CACHE.size;
|
|
1287
1342
|
MEMORY.CACHE.clear();
|
|
1288
1343
|
MEMORY.SIZE = 0;
|
|
1344
|
+
CACHE_ETAG.clear();
|
|
1289
1345
|
}
|
|
1290
1346
|
else if (percent > 0) {
|
|
1291
1347
|
const items = Array.from(MEMORY.CACHE.entries());
|
|
@@ -1463,7 +1519,7 @@ class FileManager extends Host {
|
|
|
1463
1519
|
try {
|
|
1464
1520
|
const filename = path.basename(to);
|
|
1465
1521
|
to = joinRoot ? path.join(root, to) : path.resolve(to);
|
|
1466
|
-
recurseDir(result, [root], { ignore:
|
|
1522
|
+
recurseDir(result, [root], { ignore: toPosix([...ignore, to]), ignoreRoot: toPosix(ignoreRoot), sortBy, recursive });
|
|
1467
1523
|
const output = [];
|
|
1468
1524
|
for (const pathname of result = filterPaths(root, result, options)) {
|
|
1469
1525
|
if (recursive === 1 && path.basename(pathname) === filename) {
|
|
@@ -1604,7 +1660,7 @@ class FileManager extends Host {
|
|
|
1604
1660
|
if (LOG_TIMEPROCESS) {
|
|
1605
1661
|
Host.initCpuUsage(this);
|
|
1606
1662
|
}
|
|
1607
|
-
this.#baseDirectory = path.normalize(
|
|
1663
|
+
this.#baseDirectory = path.normalize(Host.PLATFORM_WIN32 ? baseDirectory.replace(/[\\/]+$/, '') : baseDirectory.replace(/\/+$/, ''));
|
|
1608
1664
|
this.permission = permission && Host.isPermission(permission) ? permission : Host.getPermissionFromSettings();
|
|
1609
1665
|
this.sessionId = FileManager.generateSessionId();
|
|
1610
1666
|
this.supports('permission', false, true);
|
|
@@ -2331,13 +2387,13 @@ class FileManager extends Host {
|
|
|
2331
2387
|
pathname = file.pathname || '';
|
|
2332
2388
|
}
|
|
2333
2389
|
const assets = this.assets;
|
|
2334
|
-
let target =
|
|
2390
|
+
let target = toPathCase(path.join(pathname, filename)), modified = false;
|
|
2335
2391
|
for (let i = 0, j = 1, length = assets.length; i < length; ++i) {
|
|
2336
2392
|
const item = assets[i];
|
|
2337
|
-
if (item !== file && item.filename && target ===
|
|
2393
|
+
if (item !== file && item.filename && target === toPathCase(path.join(item.pathname || '', item.filename))) {
|
|
2338
2394
|
const { name, ext } = path.parse(filename);
|
|
2339
2395
|
filename = name + '_' + j + ext;
|
|
2340
|
-
target =
|
|
2396
|
+
target = toPathCase(path.join(pathname, filename));
|
|
2341
2397
|
modified = true;
|
|
2342
2398
|
i = -1;
|
|
2343
2399
|
++j;
|
|
@@ -3464,14 +3520,17 @@ class FileManager extends Host {
|
|
|
3464
3520
|
}
|
|
3465
3521
|
client?.destroy();
|
|
3466
3522
|
const location = request.url.toString();
|
|
3523
|
+
let maxAge;
|
|
3467
3524
|
request.encoding = encoding;
|
|
3525
|
+
request.headers = item.headers;
|
|
3468
3526
|
request.pipeTo = localUri;
|
|
3469
3527
|
request.statusMessage = location + (bundleMain ? ' (0)' : '');
|
|
3470
3528
|
if (type === 1) {
|
|
3471
3529
|
request.method = 'GET';
|
|
3472
3530
|
request.httpVersion = (originCount[request.url.origin] || 0) <= 1 ? 1 : undefined;
|
|
3473
3531
|
request.connected = headers => {
|
|
3474
|
-
processHeaders(
|
|
3532
|
+
processHeaders(headers, item, watching, mainEtag);
|
|
3533
|
+
maxAge = processCacheHeaders(headers, request.noCache, request.noStore);
|
|
3475
3534
|
return item.willChange || !!etagDir && (cacheDir || !item.contentLength || cacheToMemory.within(item.contentLength)) || this.hasLog('progress');
|
|
3476
3535
|
};
|
|
3477
3536
|
}
|
|
@@ -3488,13 +3547,13 @@ class FileManager extends Host {
|
|
|
3488
3547
|
item.buffer = data;
|
|
3489
3548
|
}
|
|
3490
3549
|
target.received(null, incremental, type === 1);
|
|
3491
|
-
if (etagDir) {
|
|
3550
|
+
if (etagDir && isStored(request.noCache, maxAge)) {
|
|
3492
3551
|
queueMicrotask(() => {
|
|
3493
3552
|
if (cacheBuffer && data) {
|
|
3494
|
-
cacheToMemory.add(location, etagDir, data, {
|
|
3553
|
+
cacheToMemory.add(location, etagDir, data, { contentLength: item.contentLength, maxAge, encoding, toDisk: !cacheDir && isCacheable(item) ? path.basename(localUri) : '' });
|
|
3495
3554
|
}
|
|
3496
3555
|
if (cacheDir) {
|
|
3497
|
-
cacheToDisk.add(location, etagDir, localUri, {
|
|
3556
|
+
cacheToDisk.add(location, etagDir, localUri, { contentLength: item.contentLength, maxAge, buffer: data });
|
|
3498
3557
|
}
|
|
3499
3558
|
});
|
|
3500
3559
|
}
|
|
@@ -3508,15 +3567,15 @@ class FileManager extends Host {
|
|
|
3508
3567
|
const request = this.Request;
|
|
3509
3568
|
try {
|
|
3510
3569
|
++processTask.pending;
|
|
3511
|
-
const opts = request.opts(href, { method: 'HEAD', httpVersion: 1 });
|
|
3570
|
+
const opts = request.opts(href, { method: 'HEAD', httpVersion: 1, headers: item.headers });
|
|
3512
3571
|
(client = request.open(href, opts))
|
|
3513
3572
|
.on('response', res => {
|
|
3514
3573
|
--processTask.pending;
|
|
3515
3574
|
const statusCode = res.statusCode;
|
|
3516
3575
|
if (statusCode < 300) {
|
|
3517
|
-
const etag = processHeaders(
|
|
3576
|
+
const etag = processHeaders(res.headers, item, false, mainEtag);
|
|
3518
3577
|
let etagDir = null, tempDir;
|
|
3519
|
-
if (etag) {
|
|
3578
|
+
if (etag && !opts.noCache) {
|
|
3520
3579
|
if (cacheDir || mainEtag) {
|
|
3521
3580
|
tempDir = this.getCacheDir(href);
|
|
3522
3581
|
}
|
|
@@ -3557,7 +3616,7 @@ class FileManager extends Host {
|
|
|
3557
3616
|
return;
|
|
3558
3617
|
}
|
|
3559
3618
|
if (cacheToMemory.within(item.contentLength = Buffer.byteLength(buffer, encoding))) {
|
|
3560
|
-
cacheToMemory.add(location, etagDir, buffer, {
|
|
3619
|
+
cacheToMemory.add(location, etagDir, buffer, { contentLength: item.contentLength, encoding, tempFile: pipeAs });
|
|
3561
3620
|
}
|
|
3562
3621
|
}
|
|
3563
3622
|
if (checkDest(pipeAs, localUri)) {
|
|
@@ -3670,7 +3729,7 @@ class FileManager extends Host {
|
|
|
3670
3729
|
}
|
|
3671
3730
|
downloading[uri] = [];
|
|
3672
3731
|
this.performAsyncTask();
|
|
3673
|
-
const options = { pathname, binOpts: item.binOpts, shellExpansion: item.shellExpansion };
|
|
3732
|
+
const options = { pathname, binOpts: item.binOpts, shellExpansion: item.shellExpansion, headers: item.headers };
|
|
3674
3733
|
let src;
|
|
3675
3734
|
if (type === 0) {
|
|
3676
3735
|
if (item.filename) {
|
|
@@ -4289,12 +4348,12 @@ class FileManager extends Host {
|
|
|
4289
4348
|
});
|
|
4290
4349
|
instance.on('dir:remove', value => {
|
|
4291
4350
|
if (this.removeCwd(value)) {
|
|
4292
|
-
value =
|
|
4351
|
+
value = toPathCase(value);
|
|
4293
4352
|
if (!value.endsWith(path.sep)) {
|
|
4294
4353
|
value += path.sep;
|
|
4295
4354
|
}
|
|
4296
4355
|
for (const name of this.files) {
|
|
4297
|
-
if (
|
|
4356
|
+
if (toPathCase(name).startsWith(value)) {
|
|
4298
4357
|
this.files.delete(name);
|
|
4299
4358
|
}
|
|
4300
4359
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/file-manager",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "FileManager constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
7
|
"repository": {
|
|
11
8
|
"type": "git",
|
|
12
9
|
"url": "git+https://github.com/anpham6/e-mc.git",
|
|
@@ -19,15 +16,15 @@
|
|
|
19
16
|
"license": "BSD-3-Clause",
|
|
20
17
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
21
18
|
"dependencies": {
|
|
22
|
-
"@e-mc/cloud": "0.14.
|
|
23
|
-
"@e-mc/compress": "0.14.
|
|
24
|
-
"@e-mc/core": "0.14.
|
|
25
|
-
"@e-mc/document": "0.14.
|
|
26
|
-
"@e-mc/image": "0.14.
|
|
27
|
-
"@e-mc/request": "0.14.
|
|
28
|
-
"@e-mc/task": "0.14.
|
|
29
|
-
"@e-mc/types": "0.14.
|
|
30
|
-
"@e-mc/watch": "0.14.
|
|
19
|
+
"@e-mc/cloud": "0.14.1",
|
|
20
|
+
"@e-mc/compress": "0.14.1",
|
|
21
|
+
"@e-mc/core": "0.14.1",
|
|
22
|
+
"@e-mc/document": "0.14.1",
|
|
23
|
+
"@e-mc/image": "0.14.1",
|
|
24
|
+
"@e-mc/request": "0.14.1",
|
|
25
|
+
"@e-mc/task": "0.14.1",
|
|
26
|
+
"@e-mc/types": "0.14.1",
|
|
27
|
+
"@e-mc/watch": "0.14.1",
|
|
31
28
|
"chalk": "4.1.2",
|
|
32
29
|
"diff": "^9.0.0",
|
|
33
30
|
"picomatch": "^4.0.4"
|