@e-mc/file-manager 0.5.4 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/index.js +77 -76
- package/package.json +11 -11
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Studio Trigger
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -35,7 +35,7 @@ const CACHE_ETAG = {};
|
|
|
35
35
|
const DISK = {
|
|
36
36
|
ENABLED: false,
|
|
37
37
|
EXPIRES: 0,
|
|
38
|
-
LIMIT: (0, types_1.formatSize)(
|
|
38
|
+
LIMIT: (0, types_1.formatSize)("1gb"),
|
|
39
39
|
INCLUDE: [],
|
|
40
40
|
EXCLUDE: []
|
|
41
41
|
};
|
|
@@ -45,8 +45,8 @@ const MEMORY = {
|
|
|
45
45
|
SIZE: 0,
|
|
46
46
|
TOTAL: 0,
|
|
47
47
|
EXPIRES: 0,
|
|
48
|
-
LIMIT: (0, types_1.formatSize)(
|
|
49
|
-
LIMIT_ALL: (0, types_1.formatSize)(
|
|
48
|
+
LIMIT: (0, types_1.formatSize)("100mb"),
|
|
49
|
+
LIMIT_ALL: (0, types_1.formatSize)("512mb"),
|
|
50
50
|
INCLUDE: [],
|
|
51
51
|
EXCLUDE: [],
|
|
52
52
|
PURGE: 0.25,
|
|
@@ -2238,22 +2238,19 @@ class FileManager extends core_1.Host {
|
|
|
2238
2238
|
bundling[_l = file.uri] || (bundling[_l] = []);
|
|
2239
2239
|
if (bundleIndex > 0) {
|
|
2240
2240
|
items[bundleIndex - 1] = file;
|
|
2241
|
-
|
|
2242
|
-
if (file.fetchType === 1 && (cacheToDisk.has(url) || cacheToMemory.has(url))) {
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
.on('timeout', () => resolve(file));
|
|
2255
|
-
}));
|
|
2256
|
-
}
|
|
2241
|
+
let url, parent;
|
|
2242
|
+
if (file.fetchType === 1 && (cacheToDisk.has(url = file.url) || cacheToMemory.has(url)) && (parent = assets.find(item => item.bundleIndex === 0 && item.bundleId === bundleId))) {
|
|
2243
|
+
(parent.bundleQueue || (parent.bundleQueue = [])).push(new Promise(resolve => {
|
|
2244
|
+
this.Request.open(url, { method: 'HEAD', httpVersion: 1 })
|
|
2245
|
+
.on('response', res => {
|
|
2246
|
+
if (res.statusCode < 300) {
|
|
2247
|
+
applyHeaders(file, res.headers);
|
|
2248
|
+
}
|
|
2249
|
+
resolve(file);
|
|
2250
|
+
})
|
|
2251
|
+
.on('error', () => resolve(file))
|
|
2252
|
+
.on('timeout', () => resolve(file));
|
|
2253
|
+
}));
|
|
2257
2254
|
}
|
|
2258
2255
|
return true;
|
|
2259
2256
|
}
|
|
@@ -2318,9 +2315,10 @@ class FileManager extends core_1.Host {
|
|
|
2318
2315
|
completed[localUri] = file;
|
|
2319
2316
|
if (!(0, types_1.isEmpty)(file.bundleId) && file.bundleIndex === 0) {
|
|
2320
2317
|
this.setAssetContent(file, this.getUTF8String(file, localUri));
|
|
2318
|
+
const bundleQueue = file.bundleQueue;
|
|
2321
2319
|
let success = true, error, checkEtag = !file.trailingContent && hasEtag(file);
|
|
2322
|
-
if (
|
|
2323
|
-
error = await Promise.all(
|
|
2320
|
+
if (bundleQueue) {
|
|
2321
|
+
error = await Promise.all(bundleQueue).then(() => null).catch((err) => err);
|
|
2324
2322
|
delete file.bundleQueue;
|
|
2325
2323
|
}
|
|
2326
2324
|
const items = appending[localUri];
|
|
@@ -2603,8 +2601,9 @@ class FileManager extends core_1.Host {
|
|
|
2603
2601
|
if (item.invalid || (0, types_1.ignoreFlag)(item.flags)) {
|
|
2604
2602
|
continue;
|
|
2605
2603
|
}
|
|
2606
|
-
|
|
2607
|
-
|
|
2604
|
+
let { filename, uri } = item;
|
|
2605
|
+
if (!filename) {
|
|
2606
|
+
if (!(uri && core_1.Host.isFile(uri, 'torrent'))) {
|
|
2608
2607
|
item.invalid = true;
|
|
2609
2608
|
continue;
|
|
2610
2609
|
}
|
|
@@ -2636,13 +2635,13 @@ class FileManager extends core_1.Host {
|
|
|
2636
2635
|
item.incremental = undefined;
|
|
2637
2636
|
}
|
|
2638
2637
|
}
|
|
2639
|
-
if (valid &&
|
|
2640
|
-
let uri = item.uri, cached;
|
|
2638
|
+
if (valid && filename) {
|
|
2641
2639
|
const etag = (cacheEtag && type !== 'exists' || type === 'etag') && !!uri;
|
|
2642
2640
|
if (etag && imported.some(file => file.imported.includes(uri))) {
|
|
2643
2641
|
item.incremental = 'none';
|
|
2644
2642
|
}
|
|
2645
2643
|
else if (!(0, types_1.mainFlag)(item.flags)) {
|
|
2644
|
+
let cached;
|
|
2646
2645
|
const { bundleId, bundleIndex = -1 } = item;
|
|
2647
2646
|
const setBuffer = (target) => {
|
|
2648
2647
|
if (!etag && (uri = target.uri) && (cached = MEMORY.CACHE[uri])) {
|
|
@@ -2722,13 +2721,12 @@ class FileManager extends core_1.Host {
|
|
|
2722
2721
|
try {
|
|
2723
2722
|
const buffer = fs.readFileSync(localUri);
|
|
2724
2723
|
if (!etag) {
|
|
2725
|
-
(0, asset_1.setInitialValue)(item, false);
|
|
2726
|
-
item.initialValue.buffer = buffer;
|
|
2724
|
+
(0, asset_1.setInitialValue)(item, false).buffer = buffer;
|
|
2727
2725
|
}
|
|
2728
2726
|
else if (uri && CACHE_ETAG[uri]) {
|
|
2729
|
-
(0, asset_1.setInitialValue)(item, false);
|
|
2730
|
-
|
|
2731
|
-
|
|
2727
|
+
const initialValue = (0, asset_1.setInitialValue)(item, false);
|
|
2728
|
+
initialValue.buffer = buffer;
|
|
2729
|
+
initialValue.etag = CACHE_ETAG[uri];
|
|
2732
2730
|
}
|
|
2733
2731
|
}
|
|
2734
2732
|
catch {
|
|
@@ -2749,12 +2747,12 @@ class FileManager extends core_1.Host {
|
|
|
2749
2747
|
break;
|
|
2750
2748
|
}
|
|
2751
2749
|
const { pathname, localUri } = download;
|
|
2752
|
-
let uri;
|
|
2753
2750
|
if (item.content) {
|
|
2754
2751
|
if (!checkQueue(item, localUri, pathname, true)) {
|
|
2755
|
-
|
|
2752
|
+
const content = item.content;
|
|
2753
|
+
item.sourceUTF8 = content;
|
|
2756
2754
|
this.performAsyncTask();
|
|
2757
|
-
fs.writeFile(localUri,
|
|
2755
|
+
fs.writeFile(localUri, content, item.encoding || (item.encoding = 'utf-8'), err => fileReceived(item, localUri, err));
|
|
2758
2756
|
}
|
|
2759
2757
|
}
|
|
2760
2758
|
else if (item.dataView) {
|
|
@@ -2775,18 +2773,22 @@ class FileManager extends core_1.Host {
|
|
|
2775
2773
|
fs.writeFile(localUri, item.base64, 'base64', err => fileReceived(item, localUri, err, false, true));
|
|
2776
2774
|
}
|
|
2777
2775
|
}
|
|
2778
|
-
else
|
|
2776
|
+
else {
|
|
2777
|
+
const uri = item.uri;
|
|
2778
|
+
if (!uri) {
|
|
2779
|
+
item.invalid = true;
|
|
2780
|
+
continue;
|
|
2781
|
+
}
|
|
2779
2782
|
const checkDest = (src) => staging || !(0, lib_v4_1.hasSameStat)(src, localUri);
|
|
2780
|
-
const type = item.fetchType;
|
|
2783
|
+
const type = item.fetchType || 0;
|
|
2781
2784
|
const bundleMain = !(0, types_1.isEmpty)(item.bundleId) && item.bundleIndex === 0;
|
|
2782
|
-
|
|
2783
|
-
if (
|
|
2784
|
-
|
|
2785
|
-
const checkEtag = hasEtag(item);
|
|
2785
|
+
const isHttp = type === 1;
|
|
2786
|
+
if (isHttp || type === 2) {
|
|
2787
|
+
let checkEtag;
|
|
2786
2788
|
if ((0, types_1.isEmpty)(item.bundleId) && bundling[uri]) {
|
|
2787
2789
|
bundling[uri].push(item);
|
|
2788
2790
|
}
|
|
2789
|
-
else if (checkEtag || !checkQueue(item, localUri, pathname)) {
|
|
2791
|
+
else if ((checkEtag = hasEtag(item)) || !checkQueue(item, localUri, pathname)) {
|
|
2790
2792
|
if (!isHttp && !checkDest(uri)) {
|
|
2791
2793
|
fileReceived(item, localUri);
|
|
2792
2794
|
}
|
|
@@ -2800,6 +2802,7 @@ class FileManager extends core_1.Host {
|
|
|
2800
2802
|
if (!checkEtag) {
|
|
2801
2803
|
downloading[uri] = [];
|
|
2802
2804
|
}
|
|
2805
|
+
const url = item.url;
|
|
2803
2806
|
let cacheDir, cacheBuffer, mainEtag, encoding = item.encoding, client = null;
|
|
2804
2807
|
if (isHttp) {
|
|
2805
2808
|
cacheDir = cacheToDisk.has(url) && isCacheable(item);
|
|
@@ -3075,9 +3078,6 @@ class FileManager extends core_1.Host {
|
|
|
3075
3078
|
}
|
|
3076
3079
|
}
|
|
3077
3080
|
}
|
|
3078
|
-
else {
|
|
3079
|
-
item.invalid = true;
|
|
3080
|
-
}
|
|
3081
3081
|
}
|
|
3082
3082
|
this.cleared = true;
|
|
3083
3083
|
}
|
|
@@ -3088,35 +3088,37 @@ class FileManager extends core_1.Host {
|
|
|
3088
3088
|
}
|
|
3089
3089
|
const tasks = [];
|
|
3090
3090
|
for (const item of assets) {
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
item.buffer = result;
|
|
3114
|
-
}
|
|
3115
|
-
})
|
|
3116
|
-
.catch(err => this.writeFail(["Unable to compress file", path.basename(file)], err, { type: 8, startTime: options.startTime })));
|
|
3117
|
-
}
|
|
3091
|
+
const localUri = item.localUri;
|
|
3092
|
+
if (!(localUri && image_1.default.isBinary(item.mimeType))) {
|
|
3093
|
+
continue;
|
|
3094
|
+
}
|
|
3095
|
+
const files = [localUri];
|
|
3096
|
+
if (item.transforms) {
|
|
3097
|
+
files.push(...item.transforms);
|
|
3098
|
+
}
|
|
3099
|
+
const format = item.mimeType.split('/').pop();
|
|
3100
|
+
for (const file of files) {
|
|
3101
|
+
const output = item.compress.filter(({ condition }) => !condition || withinSizeRange(file, condition));
|
|
3102
|
+
if (!(output.length && this.has(file))) {
|
|
3103
|
+
continue;
|
|
3104
|
+
}
|
|
3105
|
+
const found = output.filter(value => value.format === format);
|
|
3106
|
+
for (const config of found.length ? found : output) {
|
|
3107
|
+
const options = {
|
|
3108
|
+
...config,
|
|
3109
|
+
timeout: this[kProcessTimeout].compress ?? PROCESS_TIMEOUT.compress,
|
|
3110
|
+
proxyUrl: (uri) => {
|
|
3111
|
+
const proxy = this.Request.proxyOf(uri);
|
|
3112
|
+
return proxy ? proxy.host.href : '';
|
|
3118
3113
|
}
|
|
3119
|
-
}
|
|
3114
|
+
};
|
|
3115
|
+
tasks.push(compress.tryImage(item.buffer && files.length === 1 ? item.buffer : file, file, options)
|
|
3116
|
+
.then(result => {
|
|
3117
|
+
if (result instanceof Buffer && file === localUri) {
|
|
3118
|
+
item.buffer = result;
|
|
3119
|
+
}
|
|
3120
|
+
})
|
|
3121
|
+
.catch(err => this.writeFail(["Unable to compress file", path.basename(file)], err, { type: 8, startTime: options.startTime })));
|
|
3120
3122
|
}
|
|
3121
3123
|
}
|
|
3122
3124
|
}
|
|
@@ -3129,7 +3131,7 @@ class FileManager extends core_1.Host {
|
|
|
3129
3131
|
if (constructor.finalize && instance.assets.length) {
|
|
3130
3132
|
await constructor.finalize.call(this, instance).catch(err => rejectModule.call(instance, err, 4));
|
|
3131
3133
|
if (this.aborted) {
|
|
3132
|
-
|
|
3134
|
+
return;
|
|
3133
3135
|
}
|
|
3134
3136
|
}
|
|
3135
3137
|
}
|
|
@@ -3141,16 +3143,15 @@ class FileManager extends core_1.Host {
|
|
|
3141
3143
|
if (items.length) {
|
|
3142
3144
|
await (constructor.using || constructor.finalize).call(this, instance, items).catch(err => rejectModule.call(instance, err, 4));
|
|
3143
3145
|
if (this.aborted) {
|
|
3144
|
-
|
|
3146
|
+
return;
|
|
3145
3147
|
}
|
|
3146
3148
|
}
|
|
3147
3149
|
}
|
|
3148
3150
|
}
|
|
3149
3151
|
}
|
|
3150
3152
|
async finalizeCloud() {
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
}
|
|
3153
|
+
const cloud = this.Cloud;
|
|
3154
|
+
return cloud ? cloud_1.default.finalize.call(this, cloud).catch(err => rejectModule.call(cloud, err, 64)) : Promise.resolve();
|
|
3154
3155
|
}
|
|
3155
3156
|
async finalizeCleanup() {
|
|
3156
3157
|
if (this.Compress) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/file-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "FileManager constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "
|
|
12
|
+
"url": "https://github.com/anpham6/e-mc.git",
|
|
13
13
|
"directory": "src/file-manager"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"license": "MIT",
|
|
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.1",
|
|
24
|
+
"@e-mc/compress": "0.6.1",
|
|
25
|
+
"@e-mc/core": "0.6.1",
|
|
26
|
+
"@e-mc/document": "0.6.1",
|
|
27
|
+
"@e-mc/image": "0.6.1",
|
|
28
|
+
"@e-mc/request": "0.6.1",
|
|
29
|
+
"@e-mc/task": "0.6.1",
|
|
30
|
+
"@e-mc/types": "0.6.1",
|
|
31
|
+
"@e-mc/watch": "0.6.1"
|
|
32
32
|
}
|
|
33
33
|
}
|