@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.
Files changed (4) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/index.js +77 -76
  4. package/package.json +11 -11
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 Mile Square Park
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
@@ -1,6 +1,6 @@
1
1
  # @e-mc/file-manager
2
2
 
3
- PEP 402 - Forever
3
+ PEP 402 - Forever Ryuko
4
4
 
5
5
  ## LICENSE
6
6
 
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)('1gb'),
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)('100mb'),
49
- LIMIT_ALL: (0, types_1.formatSize)('512mb'),
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
- const url = file.url;
2242
- if (file.fetchType === 1 && (cacheToDisk.has(url) || cacheToMemory.has(url))) {
2243
- const parent = assets.find(item => item.bundleIndex === 0 && item.bundleId === bundleId);
2244
- if (parent) {
2245
- (parent.bundleQueue || (parent.bundleQueue = [])).push(new Promise(resolve => {
2246
- this.Request.open(url, { method: 'HEAD', httpVersion: 1 })
2247
- .on('response', res => {
2248
- if (res.statusCode < 300) {
2249
- applyHeaders(file, res.headers);
2250
- }
2251
- resolve(file);
2252
- })
2253
- .on('error', () => resolve(file))
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 (file.bundleQueue) {
2323
- error = await Promise.all(file.bundleQueue).then(() => null).catch((err) => err);
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
- if (!item.filename) {
2607
- if (!(item.uri && core_1.Host.isFile(item.uri, 'torrent'))) {
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 && item.filename) {
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
- item.initialValue.buffer = buffer;
2731
- item.initialValue.etag = CACHE_ETAG[uri];
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
- item.sourceUTF8 = item.content;
2752
+ const content = item.content;
2753
+ item.sourceUTF8 = content;
2756
2754
  this.performAsyncTask();
2757
- fs.writeFile(localUri, item.content, item.encoding || (item.encoding = 'utf-8'), err => fileReceived(item, localUri, err));
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 if (uri = item.uri) {
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
- let isHttp;
2783
- if ((isHttp = type === 1) || type === 2) {
2784
- const url = item.url;
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
- if (image_1.default.isBinary(item.mimeType)) {
3092
- const localUri = item.localUri;
3093
- const files = [localUri];
3094
- if (item.transforms) {
3095
- files.push(...item.transforms);
3096
- }
3097
- const format = item.mimeType.split('/').pop();
3098
- for (const file of files) {
3099
- if (this.has(file)) {
3100
- const output = item.compress.filter(({ condition }) => !condition || withinSizeRange(file, condition));
3101
- if (output.length) {
3102
- const found = output.filter(value => value.format === format);
3103
- for (const config of found.length ? found : output) {
3104
- const options = { ...config };
3105
- options.timeout = this[kProcessTimeout].compress ?? PROCESS_TIMEOUT.compress;
3106
- options.proxyUrl = (uri) => {
3107
- const proxy = this.Request.proxyOf(uri);
3108
- return proxy ? proxy.host.href : '';
3109
- };
3110
- tasks.push(compress.tryImage(item.buffer && files.length === 1 ? item.buffer : file, file, options)
3111
- .then(result => {
3112
- if (result instanceof Buffer && file === localUri) {
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
- break;
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
- break;
3146
+ return;
3145
3147
  }
3146
3148
  }
3147
3149
  }
3148
3150
  }
3149
3151
  }
3150
3152
  async finalizeCloud() {
3151
- if (this.Cloud) {
3152
- return cloud_1.default.finalize.call(this, this.Cloud).catch(err => rejectModule.call(this.Cloud, err, 64));
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.5.4",
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": "git+https://github.com/anpham6/e-mc.git",
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.5.4",
24
- "@e-mc/compress": "0.5.4",
25
- "@e-mc/core": "0.5.4",
26
- "@e-mc/document": "0.5.4",
27
- "@e-mc/image": "0.5.4",
28
- "@e-mc/request": "0.5.4",
29
- "@e-mc/task": "0.5.4",
30
- "@e-mc/types": "0.5.4",
31
- "@e-mc/watch": "0.5.4"
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
  }