@e-mc/file-manager 0.5.3 → 0.6.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/index.js +79 -78
- package/package.json +10 -10
package/index.js
CHANGED
|
@@ -36,7 +36,7 @@ const CACHE_ETAG = {};
|
|
|
36
36
|
const DISK = {
|
|
37
37
|
ENABLED: false,
|
|
38
38
|
EXPIRES: 0,
|
|
39
|
-
LIMIT: (0, types_1.formatSize)(
|
|
39
|
+
LIMIT: (0, types_1.formatSize)("1gb" /* CACHE_SIZE.FILE_MANAGER_DISK_LIMIT */),
|
|
40
40
|
INCLUDE: [],
|
|
41
41
|
EXCLUDE: []
|
|
42
42
|
};
|
|
@@ -46,8 +46,8 @@ const MEMORY = {
|
|
|
46
46
|
SIZE: 0,
|
|
47
47
|
TOTAL: 0,
|
|
48
48
|
EXPIRES: 0,
|
|
49
|
-
LIMIT: (0, types_1.formatSize)(
|
|
50
|
-
LIMIT_ALL: (0, types_1.formatSize)(
|
|
49
|
+
LIMIT: (0, types_1.formatSize)("100mb" /* CACHE_SIZE.FILE_MANAGER_MEMORY_LIMIT */),
|
|
50
|
+
LIMIT_ALL: (0, types_1.formatSize)("512mb" /* CACHE_SIZE.FILE_MANAGER_MEMORY_LIMIT_ALL */),
|
|
51
51
|
INCLUDE: [],
|
|
52
52
|
EXCLUDE: [],
|
|
53
53
|
PURGE: 0.25,
|
|
@@ -2242,22 +2242,19 @@ class FileManager extends core_1.Host {
|
|
|
2242
2242
|
bundling[_l = file.uri] || (bundling[_l] = []);
|
|
2243
2243
|
if (bundleIndex > 0) {
|
|
2244
2244
|
items[bundleIndex - 1] = file;
|
|
2245
|
-
|
|
2246
|
-
if (file.fetchType === 1 /* FETCH_TYPE.HTTP */ && (cacheToDisk.has(url) || cacheToMemory.has(url))) {
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
.on('timeout', () => resolve(file));
|
|
2259
|
-
}));
|
|
2260
|
-
}
|
|
2245
|
+
let url, parent;
|
|
2246
|
+
if (file.fetchType === 1 /* FETCH_TYPE.HTTP */ && (cacheToDisk.has(url = file.url) || cacheToMemory.has(url)) && (parent = assets.find(item => item.bundleIndex === 0 && item.bundleId === bundleId))) {
|
|
2247
|
+
(parent.bundleQueue || (parent.bundleQueue = [])).push(new Promise(resolve => {
|
|
2248
|
+
this.Request.open(url, { method: 'HEAD', httpVersion: 1 })
|
|
2249
|
+
.on('response', res => {
|
|
2250
|
+
if (res.statusCode < 300 /* HTTP_STATUS.MULTIPLE_CHOICES */) {
|
|
2251
|
+
applyHeaders(file, res.headers);
|
|
2252
|
+
}
|
|
2253
|
+
resolve(file);
|
|
2254
|
+
})
|
|
2255
|
+
.on('error', () => resolve(file))
|
|
2256
|
+
.on('timeout', () => resolve(file));
|
|
2257
|
+
}));
|
|
2261
2258
|
}
|
|
2262
2259
|
return true;
|
|
2263
2260
|
}
|
|
@@ -2322,9 +2319,10 @@ class FileManager extends core_1.Host {
|
|
|
2322
2319
|
completed[localUri] = file;
|
|
2323
2320
|
if (!(0, types_1.isEmpty)(file.bundleId) && file.bundleIndex === 0) {
|
|
2324
2321
|
this.setAssetContent(file, this.getUTF8String(file, localUri));
|
|
2322
|
+
const bundleQueue = file.bundleQueue;
|
|
2325
2323
|
let success = true, error, checkEtag = !file.trailingContent && hasEtag(file);
|
|
2326
|
-
if (
|
|
2327
|
-
error = await Promise.all(
|
|
2324
|
+
if (bundleQueue) {
|
|
2325
|
+
error = await Promise.all(bundleQueue).then(() => null).catch((err) => err);
|
|
2328
2326
|
delete file.bundleQueue;
|
|
2329
2327
|
}
|
|
2330
2328
|
const items = appending[localUri];
|
|
@@ -2607,8 +2605,9 @@ class FileManager extends core_1.Host {
|
|
|
2607
2605
|
if (item.invalid || (0, types_1.ignoreFlag)(item.flags)) {
|
|
2608
2606
|
continue;
|
|
2609
2607
|
}
|
|
2610
|
-
|
|
2611
|
-
|
|
2608
|
+
let { filename, uri } = item;
|
|
2609
|
+
if (!filename) {
|
|
2610
|
+
if (!(uri && core_1.Host.isFile(uri, 'torrent'))) {
|
|
2612
2611
|
item.invalid = true;
|
|
2613
2612
|
continue;
|
|
2614
2613
|
}
|
|
@@ -2640,13 +2639,13 @@ class FileManager extends core_1.Host {
|
|
|
2640
2639
|
item.incremental = undefined;
|
|
2641
2640
|
}
|
|
2642
2641
|
}
|
|
2643
|
-
if (valid &&
|
|
2644
|
-
let uri = item.uri, cached;
|
|
2642
|
+
if (valid && filename) {
|
|
2645
2643
|
const etag = (cacheEtag && type !== 'exists' || type === 'etag') && !!uri;
|
|
2646
2644
|
if (etag && imported.some(file => file.imported.includes(uri))) {
|
|
2647
2645
|
item.incremental = 'none';
|
|
2648
2646
|
}
|
|
2649
2647
|
else if (!(0, types_1.mainFlag)(item.flags)) {
|
|
2648
|
+
let cached;
|
|
2650
2649
|
const { bundleId, bundleIndex = -1 } = item;
|
|
2651
2650
|
const setBuffer = (target) => {
|
|
2652
2651
|
if (!etag && (uri = target.uri) && (cached = MEMORY.CACHE[uri])) {
|
|
@@ -2726,13 +2725,12 @@ class FileManager extends core_1.Host {
|
|
|
2726
2725
|
try {
|
|
2727
2726
|
const buffer = fs.readFileSync(localUri);
|
|
2728
2727
|
if (!etag) {
|
|
2729
|
-
(0, asset_1.setInitialValue)(item, false);
|
|
2730
|
-
item.initialValue.buffer = buffer;
|
|
2728
|
+
(0, asset_1.setInitialValue)(item, false).buffer = buffer;
|
|
2731
2729
|
}
|
|
2732
2730
|
else if (uri && CACHE_ETAG[uri]) {
|
|
2733
|
-
(0, asset_1.setInitialValue)(item, false);
|
|
2734
|
-
|
|
2735
|
-
|
|
2731
|
+
const initialValue = (0, asset_1.setInitialValue)(item, false);
|
|
2732
|
+
initialValue.buffer = buffer;
|
|
2733
|
+
initialValue.etag = CACHE_ETAG[uri];
|
|
2736
2734
|
}
|
|
2737
2735
|
}
|
|
2738
2736
|
catch {
|
|
@@ -2753,12 +2751,12 @@ class FileManager extends core_1.Host {
|
|
|
2753
2751
|
break;
|
|
2754
2752
|
}
|
|
2755
2753
|
const { pathname, localUri } = download;
|
|
2756
|
-
let uri;
|
|
2757
2754
|
if (item.content) {
|
|
2758
2755
|
if (!checkQueue(item, localUri, pathname, true)) {
|
|
2759
|
-
|
|
2756
|
+
const content = item.content;
|
|
2757
|
+
item.sourceUTF8 = content;
|
|
2760
2758
|
this.performAsyncTask();
|
|
2761
|
-
fs.writeFile(localUri,
|
|
2759
|
+
fs.writeFile(localUri, content, item.encoding || (item.encoding = 'utf-8'), err => fileReceived(item, localUri, err));
|
|
2762
2760
|
}
|
|
2763
2761
|
}
|
|
2764
2762
|
else if (item.dataView) {
|
|
@@ -2779,18 +2777,22 @@ class FileManager extends core_1.Host {
|
|
|
2779
2777
|
fs.writeFile(localUri, item.base64, 'base64', err => fileReceived(item, localUri, err, false, true));
|
|
2780
2778
|
}
|
|
2781
2779
|
}
|
|
2782
|
-
else
|
|
2780
|
+
else {
|
|
2781
|
+
const uri = item.uri;
|
|
2782
|
+
if (!uri) {
|
|
2783
|
+
item.invalid = true;
|
|
2784
|
+
continue;
|
|
2785
|
+
}
|
|
2783
2786
|
const checkDest = (src) => staging || !(0, lib_v4_1.hasSameStat)(src, localUri);
|
|
2784
|
-
const type = item.fetchType
|
|
2787
|
+
const type = item.fetchType || 0 /* FETCH_TYPE.UNKNOWN */;
|
|
2785
2788
|
const bundleMain = !(0, types_1.isEmpty)(item.bundleId) && item.bundleIndex === 0;
|
|
2786
|
-
|
|
2787
|
-
if (
|
|
2788
|
-
|
|
2789
|
-
const checkEtag = hasEtag(item);
|
|
2789
|
+
const isHttp = type === 1 /* FETCH_TYPE.HTTP */;
|
|
2790
|
+
if (isHttp || type === 2 /* FETCH_TYPE.UNIX_SOCKET */) {
|
|
2791
|
+
let checkEtag;
|
|
2790
2792
|
if ((0, types_1.isEmpty)(item.bundleId) && bundling[uri]) {
|
|
2791
2793
|
bundling[uri].push(item);
|
|
2792
2794
|
}
|
|
2793
|
-
else if (checkEtag || !checkQueue(item, localUri, pathname)) {
|
|
2795
|
+
else if ((checkEtag = hasEtag(item)) || !checkQueue(item, localUri, pathname)) {
|
|
2794
2796
|
if (!isHttp && !checkDest(uri)) {
|
|
2795
2797
|
fileReceived(item, localUri);
|
|
2796
2798
|
}
|
|
@@ -2804,6 +2806,7 @@ class FileManager extends core_1.Host {
|
|
|
2804
2806
|
if (!checkEtag) {
|
|
2805
2807
|
downloading[uri] = [];
|
|
2806
2808
|
}
|
|
2809
|
+
const url = item.url;
|
|
2807
2810
|
let cacheDir, cacheBuffer, mainEtag, encoding = item.encoding, client = null;
|
|
2808
2811
|
if (isHttp) {
|
|
2809
2812
|
cacheDir = cacheToDisk.has(url) && isCacheable(item);
|
|
@@ -3078,9 +3081,6 @@ class FileManager extends core_1.Host {
|
|
|
3078
3081
|
}
|
|
3079
3082
|
}
|
|
3080
3083
|
}
|
|
3081
|
-
else {
|
|
3082
|
-
item.invalid = true;
|
|
3083
|
-
}
|
|
3084
3084
|
}
|
|
3085
3085
|
this.cleared = true;
|
|
3086
3086
|
}
|
|
@@ -3091,35 +3091,37 @@ class FileManager extends core_1.Host {
|
|
|
3091
3091
|
}
|
|
3092
3092
|
const tasks = [];
|
|
3093
3093
|
for (const item of assets) {
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
item.buffer = result;
|
|
3117
|
-
}
|
|
3118
|
-
})
|
|
3119
|
-
.catch(err => this.writeFail(["Unable to compress file" /* ERR_MESSAGE.COMPRESS_FILE */, path.basename(file)], err, { type: 8 /* LOG_TYPE.COMPRESS */, startTime: options.startTime })));
|
|
3120
|
-
}
|
|
3094
|
+
const localUri = item.localUri;
|
|
3095
|
+
if (!(localUri && image_1.default.isBinary(item.mimeType))) {
|
|
3096
|
+
continue;
|
|
3097
|
+
}
|
|
3098
|
+
const files = [localUri];
|
|
3099
|
+
if (item.transforms) {
|
|
3100
|
+
files.push(...item.transforms);
|
|
3101
|
+
}
|
|
3102
|
+
const format = item.mimeType.split('/').pop();
|
|
3103
|
+
for (const file of files) {
|
|
3104
|
+
const output = item.compress.filter(({ condition }) => !condition || withinSizeRange(file, condition));
|
|
3105
|
+
if (!(output.length && this.has(file))) {
|
|
3106
|
+
continue;
|
|
3107
|
+
}
|
|
3108
|
+
const found = output.filter(value => value.format === format);
|
|
3109
|
+
for (const config of found.length ? found : output) {
|
|
3110
|
+
const options = {
|
|
3111
|
+
...config,
|
|
3112
|
+
timeout: this[kProcessTimeout].compress ?? PROCESS_TIMEOUT.compress,
|
|
3113
|
+
proxyUrl: (uri) => {
|
|
3114
|
+
const proxy = this.Request.proxyOf(uri);
|
|
3115
|
+
return proxy ? proxy.host.href : '';
|
|
3121
3116
|
}
|
|
3122
|
-
}
|
|
3117
|
+
};
|
|
3118
|
+
tasks.push(compress.tryImage(item.buffer && files.length === 1 ? item.buffer : file, file, options)
|
|
3119
|
+
.then(result => {
|
|
3120
|
+
if (result instanceof Buffer && file === localUri) {
|
|
3121
|
+
item.buffer = result;
|
|
3122
|
+
}
|
|
3123
|
+
})
|
|
3124
|
+
.catch(err => this.writeFail(["Unable to compress file" /* ERR_MESSAGE.COMPRESS_FILE */, path.basename(file)], err, { type: 8 /* LOG_TYPE.COMPRESS */, startTime: options.startTime })));
|
|
3123
3125
|
}
|
|
3124
3126
|
}
|
|
3125
3127
|
}
|
|
@@ -3132,7 +3134,7 @@ class FileManager extends core_1.Host {
|
|
|
3132
3134
|
if (constructor.finalize && instance.assets.length) {
|
|
3133
3135
|
await constructor.finalize.call(this, instance).catch(err => rejectModule.call(instance, err, 4 /* LOG_TYPE.PROCESS */));
|
|
3134
3136
|
if (this.aborted) {
|
|
3135
|
-
|
|
3137
|
+
return;
|
|
3136
3138
|
}
|
|
3137
3139
|
}
|
|
3138
3140
|
}
|
|
@@ -3144,16 +3146,15 @@ class FileManager extends core_1.Host {
|
|
|
3144
3146
|
if (items.length) {
|
|
3145
3147
|
await (constructor.using || constructor.finalize).call(this, instance, items).catch(err => rejectModule.call(instance, err, 4 /* LOG_TYPE.PROCESS */));
|
|
3146
3148
|
if (this.aborted) {
|
|
3147
|
-
|
|
3149
|
+
return;
|
|
3148
3150
|
}
|
|
3149
3151
|
}
|
|
3150
3152
|
}
|
|
3151
3153
|
}
|
|
3152
3154
|
}
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
}
|
|
3155
|
+
finalizeCloud() {
|
|
3156
|
+
const cloud = this.Cloud;
|
|
3157
|
+
return cloud ? cloud_1.default.finalize.call(this, cloud).catch(err => rejectModule.call(cloud, err, 64 /* LOG_TYPE.CLOUD */)) : Promise.resolve();
|
|
3157
3158
|
}
|
|
3158
3159
|
async finalizeCleanup() {
|
|
3159
3160
|
if (this.Compress) {
|
|
@@ -3248,7 +3249,7 @@ class FileManager extends core_1.Host {
|
|
|
3248
3249
|
const errorCount = this.errorCount;
|
|
3249
3250
|
const message = [];
|
|
3250
3251
|
if (errorCount) {
|
|
3251
|
-
message.push(
|
|
3252
|
+
message.push('ERROR ' + errorCount); // eslint-disable-line @typescript-eslint/no-base-to-string
|
|
3252
3253
|
}
|
|
3253
3254
|
let [size, count] = h;
|
|
3254
3255
|
if (count) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/file-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "FileManager constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,14 +20,14 @@
|
|
|
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.6.0",
|
|
24
|
+
"@e-mc/compress": "0.6.0",
|
|
25
|
+
"@e-mc/core": "0.6.0",
|
|
26
|
+
"@e-mc/document": "0.6.0",
|
|
27
|
+
"@e-mc/image": "0.6.0",
|
|
28
|
+
"@e-mc/request": "0.6.0",
|
|
29
|
+
"@e-mc/task": "0.6.0",
|
|
30
|
+
"@e-mc/types": "0.6.0",
|
|
31
|
+
"@e-mc/watch": "0.6.0"
|
|
32
32
|
}
|
|
33
33
|
}
|