@e-mc/file-manager 0.14.0 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/index.js +107 -50
- 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.2/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.2/lib/squared.d.ts
|
|
301
|
+
- https://www.unpkg.com/@e-mc/types@0.14.2/lib/asset.d.ts
|
|
302
|
+
- https://www.unpkg.com/@e-mc/types@0.14.2/lib/core.d.ts
|
|
303
|
+
- https://www.unpkg.com/@e-mc/types@0.14.2/lib/filemanager.d.ts
|
|
304
|
+
- https://www.unpkg.com/@e-mc/types@0.14.2/lib/logger.d.ts
|
|
305
|
+
- https://www.unpkg.com/@e-mc/types@0.14.2/lib/module.d.ts
|
|
306
|
+
- https://www.unpkg.com/@e-mc/types@0.14.2/lib/node.d.ts
|
|
307
|
+
- https://www.unpkg.com/@e-mc/types@0.14.2/lib/request.d.ts
|
|
308
|
+
- https://www.unpkg.com/@e-mc/types@0.14.2/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;
|
|
@@ -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 isNoContent = (statusCode) => statusCode === 204 || statusCode === 304;
|
|
502
|
+
const isStored = (noCache, maxAge) => !noCache || typeof maxAge === 'number';
|
|
471
503
|
const hasFiles = (type, uri) => type === 3 || type === 4 || type === 0 && Request.isRclone(uri);
|
|
472
504
|
const hasIncremental = (value) => value === "etag" || value === "exists";
|
|
473
|
-
const
|
|
474
|
-
const
|
|
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 (isNoContent(statusCode)) {
|
|
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;
|
|
@@ -1093,12 +1148,7 @@ class ProcessFile {
|
|
|
1093
1148
|
const downloaded = groupData.bundling[uri];
|
|
1094
1149
|
if (isArray(downloaded)) {
|
|
1095
1150
|
if (data && !queue.invalid) {
|
|
1096
|
-
|
|
1097
|
-
queue.sourceUTF8 = data;
|
|
1098
|
-
}
|
|
1099
|
-
else {
|
|
1100
|
-
queue.buffer = data;
|
|
1101
|
-
}
|
|
1151
|
+
setContent(queue, data);
|
|
1102
1152
|
this.copyDownload(queue, downloaded);
|
|
1103
1153
|
}
|
|
1104
1154
|
else {
|
|
@@ -1129,7 +1179,7 @@ class ProcessFile {
|
|
|
1129
1179
|
}
|
|
1130
1180
|
const pathname = getTempDir(true);
|
|
1131
1181
|
tasks.push(new Promise((resolve, reject) => {
|
|
1132
|
-
void host.scheduleTask(queue.url || uri, { pathname, binOpts: queue.binOpts || file.binOpts }, (result) => {
|
|
1182
|
+
void host.scheduleTask(queue.url || uri, { pathname, binOpts: queue.binOpts || file.binOpts, headers: queue.headers }, (result) => {
|
|
1133
1183
|
if (result.length > 0) {
|
|
1134
1184
|
verifyBundle(bundleTorrent(host, result, mimeType, encoding));
|
|
1135
1185
|
}
|
|
@@ -1286,6 +1336,7 @@ class FileManager extends Host {
|
|
|
1286
1336
|
result = MEMORY.CACHE.size;
|
|
1287
1337
|
MEMORY.CACHE.clear();
|
|
1288
1338
|
MEMORY.SIZE = 0;
|
|
1339
|
+
CACHE_ETAG.clear();
|
|
1289
1340
|
}
|
|
1290
1341
|
else if (percent > 0) {
|
|
1291
1342
|
const items = Array.from(MEMORY.CACHE.entries());
|
|
@@ -1463,7 +1514,7 @@ class FileManager extends Host {
|
|
|
1463
1514
|
try {
|
|
1464
1515
|
const filename = path.basename(to);
|
|
1465
1516
|
to = joinRoot ? path.join(root, to) : path.resolve(to);
|
|
1466
|
-
recurseDir(result, [root], { ignore:
|
|
1517
|
+
recurseDir(result, [root], { ignore: toPosix([...ignore, to]), ignoreRoot: toPosix(ignoreRoot), sortBy, recursive });
|
|
1467
1518
|
const output = [];
|
|
1468
1519
|
for (const pathname of result = filterPaths(root, result, options)) {
|
|
1469
1520
|
if (recursive === 1 && path.basename(pathname) === filename) {
|
|
@@ -1604,7 +1655,7 @@ class FileManager extends Host {
|
|
|
1604
1655
|
if (LOG_TIMEPROCESS) {
|
|
1605
1656
|
Host.initCpuUsage(this);
|
|
1606
1657
|
}
|
|
1607
|
-
this.#baseDirectory = path.normalize(
|
|
1658
|
+
this.#baseDirectory = path.normalize(Host.PLATFORM_WIN32 ? baseDirectory.replace(/[\\/]+$/, '') : baseDirectory.replace(/\/+$/, ''));
|
|
1608
1659
|
this.permission = permission && Host.isPermission(permission) ? permission : Host.getPermissionFromSettings();
|
|
1609
1660
|
this.sessionId = FileManager.generateSessionId();
|
|
1610
1661
|
this.supports('permission', false, true);
|
|
@@ -2331,13 +2382,13 @@ class FileManager extends Host {
|
|
|
2331
2382
|
pathname = file.pathname || '';
|
|
2332
2383
|
}
|
|
2333
2384
|
const assets = this.assets;
|
|
2334
|
-
let target =
|
|
2385
|
+
let target = toPathCase(path.join(pathname, filename)), modified = false;
|
|
2335
2386
|
for (let i = 0, j = 1, length = assets.length; i < length; ++i) {
|
|
2336
2387
|
const item = assets[i];
|
|
2337
|
-
if (item !== file && item.filename && target ===
|
|
2388
|
+
if (item !== file && item.filename && target === toPathCase(path.join(item.pathname || '', item.filename))) {
|
|
2338
2389
|
const { name, ext } = path.parse(filename);
|
|
2339
2390
|
filename = name + '_' + j + ext;
|
|
2340
|
-
target =
|
|
2391
|
+
target = toPathCase(path.join(pathname, filename));
|
|
2341
2392
|
modified = true;
|
|
2342
2393
|
i = -1;
|
|
2343
2394
|
++j;
|
|
@@ -3464,14 +3515,17 @@ class FileManager extends Host {
|
|
|
3464
3515
|
}
|
|
3465
3516
|
client?.destroy();
|
|
3466
3517
|
const location = request.url.toString();
|
|
3518
|
+
let maxAge;
|
|
3467
3519
|
request.encoding = encoding;
|
|
3520
|
+
request.headers = item.headers;
|
|
3468
3521
|
request.pipeTo = localUri;
|
|
3469
3522
|
request.statusMessage = location + (bundleMain ? ' (0)' : '');
|
|
3470
3523
|
if (type === 1) {
|
|
3471
3524
|
request.method = 'GET';
|
|
3472
3525
|
request.httpVersion = (originCount[request.url.origin] || 0) <= 1 ? 1 : undefined;
|
|
3473
3526
|
request.connected = headers => {
|
|
3474
|
-
processHeaders(
|
|
3527
|
+
processHeaders(headers, item, watching, mainEtag);
|
|
3528
|
+
maxAge = processCacheHeaders(headers, request.noCache, request.noStore);
|
|
3475
3529
|
return item.willChange || !!etagDir && (cacheDir || !item.contentLength || cacheToMemory.within(item.contentLength)) || this.hasLog('progress');
|
|
3476
3530
|
};
|
|
3477
3531
|
}
|
|
@@ -3488,13 +3542,13 @@ class FileManager extends Host {
|
|
|
3488
3542
|
item.buffer = data;
|
|
3489
3543
|
}
|
|
3490
3544
|
target.received(null, incremental, type === 1);
|
|
3491
|
-
if (etagDir) {
|
|
3545
|
+
if (etagDir && isStored(request.noCache, maxAge)) {
|
|
3492
3546
|
queueMicrotask(() => {
|
|
3493
3547
|
if (cacheBuffer && data) {
|
|
3494
|
-
cacheToMemory.add(location, etagDir, data, {
|
|
3548
|
+
cacheToMemory.add(location, etagDir, data, { contentLength: item.contentLength, maxAge, encoding, toDisk: !cacheDir && isCacheable(item) ? path.basename(localUri) : '' });
|
|
3495
3549
|
}
|
|
3496
3550
|
if (cacheDir) {
|
|
3497
|
-
cacheToDisk.add(location, etagDir, localUri, {
|
|
3551
|
+
cacheToDisk.add(location, etagDir, localUri, { contentLength: item.contentLength, maxAge, buffer: data });
|
|
3498
3552
|
}
|
|
3499
3553
|
});
|
|
3500
3554
|
}
|
|
@@ -3508,15 +3562,18 @@ class FileManager extends Host {
|
|
|
3508
3562
|
const request = this.Request;
|
|
3509
3563
|
try {
|
|
3510
3564
|
++processTask.pending;
|
|
3511
|
-
const opts = request.opts(href, { method: 'HEAD', httpVersion: 1 });
|
|
3565
|
+
const opts = request.opts(href, { method: 'HEAD', httpVersion: 1, headers: item.headers });
|
|
3512
3566
|
(client = request.open(href, opts))
|
|
3513
3567
|
.on('response', res => {
|
|
3514
3568
|
--processTask.pending;
|
|
3515
3569
|
const statusCode = res.statusCode;
|
|
3516
|
-
if (statusCode
|
|
3517
|
-
|
|
3570
|
+
if (isNoContent(statusCode)) {
|
|
3571
|
+
downloadUri(opts, null);
|
|
3572
|
+
}
|
|
3573
|
+
else if (statusCode < 300) {
|
|
3574
|
+
const etag = processHeaders(res.headers, item, false, mainEtag && !opts.noStore);
|
|
3518
3575
|
let etagDir = null, tempDir;
|
|
3519
|
-
if (etag) {
|
|
3576
|
+
if (etag && !opts.noCache && !opts.noStore) {
|
|
3520
3577
|
if (cacheDir || mainEtag) {
|
|
3521
3578
|
tempDir = this.getCacheDir(href);
|
|
3522
3579
|
}
|
|
@@ -3557,7 +3614,7 @@ class FileManager extends Host {
|
|
|
3557
3614
|
return;
|
|
3558
3615
|
}
|
|
3559
3616
|
if (cacheToMemory.within(item.contentLength = Buffer.byteLength(buffer, encoding))) {
|
|
3560
|
-
cacheToMemory.add(location, etagDir, buffer, {
|
|
3617
|
+
cacheToMemory.add(location, etagDir, buffer, { contentLength: item.contentLength, encoding, tempFile: pipeAs });
|
|
3561
3618
|
}
|
|
3562
3619
|
}
|
|
3563
3620
|
if (checkDest(pipeAs, localUri)) {
|
|
@@ -3670,7 +3727,7 @@ class FileManager extends Host {
|
|
|
3670
3727
|
}
|
|
3671
3728
|
downloading[uri] = [];
|
|
3672
3729
|
this.performAsyncTask();
|
|
3673
|
-
const options = { pathname, binOpts: item.binOpts, shellExpansion: item.shellExpansion };
|
|
3730
|
+
const options = { pathname, binOpts: item.binOpts, shellExpansion: item.shellExpansion, headers: item.headers };
|
|
3674
3731
|
let src;
|
|
3675
3732
|
if (type === 0) {
|
|
3676
3733
|
if (item.filename) {
|
|
@@ -4289,12 +4346,12 @@ class FileManager extends Host {
|
|
|
4289
4346
|
});
|
|
4290
4347
|
instance.on('dir:remove', value => {
|
|
4291
4348
|
if (this.removeCwd(value)) {
|
|
4292
|
-
value =
|
|
4349
|
+
value = toPathCase(value);
|
|
4293
4350
|
if (!value.endsWith(path.sep)) {
|
|
4294
4351
|
value += path.sep;
|
|
4295
4352
|
}
|
|
4296
4353
|
for (const name of this.files) {
|
|
4297
|
-
if (
|
|
4354
|
+
if (toPathCase(name).startsWith(value)) {
|
|
4298
4355
|
this.files.delete(name);
|
|
4299
4356
|
}
|
|
4300
4357
|
}
|
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.2",
|
|
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.2",
|
|
20
|
+
"@e-mc/compress": "0.14.2",
|
|
21
|
+
"@e-mc/core": "0.14.2",
|
|
22
|
+
"@e-mc/document": "0.14.2",
|
|
23
|
+
"@e-mc/image": "0.14.2",
|
|
24
|
+
"@e-mc/request": "0.14.2",
|
|
25
|
+
"@e-mc/task": "0.14.2",
|
|
26
|
+
"@e-mc/types": "0.14.2",
|
|
27
|
+
"@e-mc/watch": "0.14.2",
|
|
31
28
|
"chalk": "4.1.2",
|
|
32
29
|
"diff": "^9.0.0",
|
|
33
30
|
"picomatch": "^4.0.4"
|