@e-mc/compress 0.7.0 → 0.7.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/LICENSE +10 -10
- package/README.md +5 -3
- package/index.d.ts +4 -4
- package/index.js +21 -21
- package/package.json +5 -5
package/LICENSE
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Copyright 2023
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
-
|
|
5
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
-
|
|
7
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
1
|
+
Copyright 2023 Wit Studio
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
+
|
|
11
11
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CompressConstructor } from '../types/lib';
|
|
2
|
-
|
|
3
|
-
declare const Compress: CompressConstructor;
|
|
4
|
-
|
|
1
|
+
import type { CompressConstructor } from '../types/lib';
|
|
2
|
+
|
|
3
|
+
declare const Compress: CompressConstructor;
|
|
4
|
+
|
|
5
5
|
export = Compress;
|
package/index.js
CHANGED
|
@@ -6,9 +6,9 @@ const stream = require("stream");
|
|
|
6
6
|
const zlib = require("zlib");
|
|
7
7
|
const wawoff2 = require("wawoff2");
|
|
8
8
|
const { toSfnt, toWoff } = require('woff2sfnt-sfnt2woff');
|
|
9
|
-
const types_1 = require("
|
|
10
|
-
const lib_v4_1 = require("
|
|
11
|
-
const module_1 = require("
|
|
9
|
+
const types_1 = require("@e-mc/types");
|
|
10
|
+
const lib_v4_1 = require("@e-mc/module/lib-v4");
|
|
11
|
+
const module_1 = require("@e-mc/module");
|
|
12
12
|
const CACHE_IMAGE = {};
|
|
13
13
|
const CACHE_FONT = {};
|
|
14
14
|
const CACHE_FONTFROM = {};
|
|
@@ -53,7 +53,7 @@ function setCacheData(index) {
|
|
|
53
53
|
try {
|
|
54
54
|
const stat = fs.lstatSync(pathname);
|
|
55
55
|
if (stat.atimeMs + expires > current) {
|
|
56
|
-
if (index === 0
|
|
56
|
+
if (index === 0) {
|
|
57
57
|
CACHE_FONT[paths.concat(filename).join('_')] = [pathname, stat.ctime];
|
|
58
58
|
CACHE_FONTFROM[filename] = paths[0];
|
|
59
59
|
CACHE_FONTTO[filename] = paths[1];
|
|
@@ -207,7 +207,7 @@ class Compress extends module_1.default {
|
|
|
207
207
|
createWriteStreamAsBrotli(file, output, options) {
|
|
208
208
|
return this.createBrotliCompress(file, options).pipe(fs.createWriteStream(output));
|
|
209
209
|
}
|
|
210
|
-
tryFile(file, output, config, callback) {
|
|
210
|
+
async tryFile(file, output, config, callback) {
|
|
211
211
|
if (typeof config === 'function') {
|
|
212
212
|
callback = config;
|
|
213
213
|
config = undefined;
|
|
@@ -244,7 +244,7 @@ class Compress extends module_1.default {
|
|
|
244
244
|
}
|
|
245
245
|
else {
|
|
246
246
|
if (!fromCache) {
|
|
247
|
-
this.writeTimeProcess(ext || format, (0, types_1.isString)(result) ? path.basename(result) : filename || 'Completed', startTime, { type: 8
|
|
247
|
+
this.writeTimeProcess(ext || format, (0, types_1.isString)(result) ? path.basename(result) : filename || 'Completed', startTime, { type: 8, sessionId, broadcastId });
|
|
248
248
|
}
|
|
249
249
|
if (callback) {
|
|
250
250
|
callback(null, result || data, ext);
|
|
@@ -256,10 +256,10 @@ class Compress extends module_1.default {
|
|
|
256
256
|
if (timeout > 0) {
|
|
257
257
|
timer = setTimeout(() => {
|
|
258
258
|
aborted = true;
|
|
259
|
-
endProcess((0, types_1.errorValue)("Timeout was exceeded"
|
|
259
|
+
endProcess((0, types_1.errorValue)("Timeout was exceeded", format));
|
|
260
260
|
}, timeout);
|
|
261
261
|
}
|
|
262
|
-
this.formatMessage(8
|
|
262
|
+
this.formatMessage(8, format, [compressing ? 'Compressing file...' : 'Decompressing file...', filename || (output ? path.basename(output) : '')], (0, types_1.isString)(file) ? file : '', { titleColor: 'magenta', sessionId, broadcastId });
|
|
263
263
|
};
|
|
264
264
|
try {
|
|
265
265
|
const writeFont = (data, ext, from) => {
|
|
@@ -296,7 +296,7 @@ class Compress extends module_1.default {
|
|
|
296
296
|
};
|
|
297
297
|
const hasFont = () => {
|
|
298
298
|
let from, to;
|
|
299
|
-
if (cache && (CACHE_INIT[0] || setCacheData.call(this, 0
|
|
299
|
+
if (cache && (CACHE_INIT[0] || setCacheData.call(this, 0)) && (from = CACHE_FONTFROM[hash]) && (to = CACHE_FONTTO[hash])) {
|
|
300
300
|
const cacheKey = from + `_${to}_` + hash;
|
|
301
301
|
const tempFont = CACHE_FONT[cacheKey];
|
|
302
302
|
if (tempFont) {
|
|
@@ -311,7 +311,7 @@ class Compress extends module_1.default {
|
|
|
311
311
|
else {
|
|
312
312
|
endProcess(null, data, to, '', true);
|
|
313
313
|
}
|
|
314
|
-
this.formatMessage(8
|
|
314
|
+
this.formatMessage(8, from, [pathname ? path.basename(pathname) : `Completed -> font/${to}`, 'cache'], tempFont[1].toLocaleString(), { ...module_1.default.LOG_STYLE_NOTICE, hintBold: true, sessionId, broadcastId });
|
|
315
315
|
return true;
|
|
316
316
|
}
|
|
317
317
|
catch {
|
|
@@ -322,7 +322,7 @@ class Compress extends module_1.default {
|
|
|
322
322
|
return false;
|
|
323
323
|
}
|
|
324
324
|
};
|
|
325
|
-
const errorResponse = (font) => endProcess((0, types_1.errorValue)('Invalid MIME', (font ? font.mime : "Unknown"
|
|
325
|
+
const errorResponse = (font) => endProcess((0, types_1.errorValue)('Invalid MIME', (font ? font.mime : "Unknown") + ': ' + (output || filename || "Unknown")));
|
|
326
326
|
const data = Buffer.isBuffer(file) ? file : fs.readFileSync(file);
|
|
327
327
|
switch (format = format.toLowerCase()) {
|
|
328
328
|
case 'gz':
|
|
@@ -467,7 +467,7 @@ class Compress extends module_1.default {
|
|
|
467
467
|
}
|
|
468
468
|
});
|
|
469
469
|
}
|
|
470
|
-
tryImage(file, output, config, callback) {
|
|
470
|
+
async tryImage(file, output, config, callback) {
|
|
471
471
|
if (typeof config === 'function') {
|
|
472
472
|
callback = config;
|
|
473
473
|
config = undefined;
|
|
@@ -483,7 +483,7 @@ class Compress extends module_1.default {
|
|
|
483
483
|
if (!(0, types_1.isString)(output)) {
|
|
484
484
|
output = typeof file === 'string' ? file : '';
|
|
485
485
|
}
|
|
486
|
-
const ext = output ? path.extname(output).substring(1) : config.format || "Unknown"
|
|
486
|
+
const ext = output ? path.extname(output).substring(1) : config.format || "Unknown";
|
|
487
487
|
const format = config.format || ext;
|
|
488
488
|
return new Promise((resolve, reject) => {
|
|
489
489
|
let timer = null, hash, cacheKey, aborted, apiKey;
|
|
@@ -511,10 +511,10 @@ class Compress extends module_1.default {
|
|
|
511
511
|
const value = output ? path.basename(output) : filename || (0, types_1.isString)(file) && path.basename(file);
|
|
512
512
|
const status = value ? plugin + ' -> ' + value : 'Completed';
|
|
513
513
|
if (ctime) {
|
|
514
|
-
this.formatMessage(8
|
|
514
|
+
this.formatMessage(8, value ? path.extname(value).substring(1) : '', [status, 'cache'], ctime.toLocaleString(), { ...module_1.default.LOG_STYLE_NOTICE, hintBold: true, sessionId, broadcastId });
|
|
515
515
|
}
|
|
516
516
|
else {
|
|
517
|
-
this.writeTimeProcess(ext, status, startTime, { type: 8
|
|
517
|
+
this.writeTimeProcess(ext, status, startTime, { type: 8, sessionId, broadcastId });
|
|
518
518
|
}
|
|
519
519
|
if (callback) {
|
|
520
520
|
callback(err, result);
|
|
@@ -546,7 +546,7 @@ class Compress extends module_1.default {
|
|
|
546
546
|
case 'jpg':
|
|
547
547
|
case 'jpeg':
|
|
548
548
|
case 'webp':
|
|
549
|
-
apiKey = config.options?.apiKey || (module_1.default.enabled("process.env.apply"
|
|
549
|
+
apiKey = config.options?.apiKey || (module_1.default.enabled("process.env.apply") ? process.env.TINIFY_KEY : '');
|
|
550
550
|
break;
|
|
551
551
|
default:
|
|
552
552
|
failed((0, types_1.errorMessage)(plugin, 'Unsupported MIME', format));
|
|
@@ -574,7 +574,7 @@ class Compress extends module_1.default {
|
|
|
574
574
|
failed(err);
|
|
575
575
|
return;
|
|
576
576
|
}
|
|
577
|
-
if (this.settings.cache && setCacheData.call(this, 1
|
|
577
|
+
if (this.settings.cache && setCacheData.call(this, 1)) {
|
|
578
578
|
let stored;
|
|
579
579
|
try {
|
|
580
580
|
stored = (CACHE_IMAGE[plugin] || (CACHE_IMAGE[plugin] = {}))[hash = module_1.default.asHash(data)];
|
|
@@ -591,12 +591,12 @@ class Compress extends module_1.default {
|
|
|
591
591
|
}
|
|
592
592
|
}
|
|
593
593
|
}
|
|
594
|
-
this.formatMessage(8
|
|
594
|
+
this.formatMessage(8, ext, ['Compressing image...', plugin], filename || output, { titleColor: 'magenta', sessionId, broadcastId });
|
|
595
595
|
if (timeout > 0) {
|
|
596
|
-
timer = setTimeout(() => failed((0, types_1.errorMessage)(plugin, "Timeout was exceeded"
|
|
596
|
+
timer = setTimeout(() => failed((0, types_1.errorMessage)(plugin, "Timeout was exceeded")), timeout);
|
|
597
597
|
}
|
|
598
598
|
if (apiKey) {
|
|
599
|
-
const apiProxy = proxyUrl && (typeof proxyUrl === 'function' ? proxyUrl("https://api.tinify.com"
|
|
599
|
+
const apiProxy = proxyUrl && (typeof proxyUrl === 'function' ? proxyUrl("https://api.tinify.com") : proxyUrl) || this.module.tinify?.proxy || module_1.default.enabled("process.env.apply") && process.env.TINIFY_PROXY || '';
|
|
600
600
|
const key = apiKey + apiProxy;
|
|
601
601
|
let tinypng = CACHE_TINIFY[key];
|
|
602
602
|
const validate = () => {
|
|
@@ -628,7 +628,7 @@ class Compress extends module_1.default {
|
|
|
628
628
|
validate();
|
|
629
629
|
}
|
|
630
630
|
else {
|
|
631
|
-
failed(err || new Error("Unknown"
|
|
631
|
+
failed(err || new Error("Unknown"));
|
|
632
632
|
}
|
|
633
633
|
});
|
|
634
634
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/compress",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Compress 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": "https://github.com/anpham6/e-mc.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/e-mc.git",
|
|
13
13
|
"directory": "src/compress"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"name": "An Pham",
|
|
21
21
|
"email": "anpham6@gmail.com"
|
|
22
22
|
},
|
|
23
|
-
"license": "
|
|
23
|
+
"license": "MIT",
|
|
24
24
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@e-mc/module": "0.7.
|
|
27
|
-
"@e-mc/types": "0.7.
|
|
26
|
+
"@e-mc/module": "0.7.2",
|
|
27
|
+
"@e-mc/types": "0.7.2",
|
|
28
28
|
"tinify": "^1.7.1",
|
|
29
29
|
"wawoff2": "^2.0.1",
|
|
30
30
|
"woff2sfnt-sfnt2woff": "^1.0.0"
|