@e-mc/compress 0.9.2 → 0.9.3
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 +4 -4
- package/index.js +22 -44
- package/package.json +3 -3
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.9.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.3/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { CompressLevel } from "./squared";
|
|
@@ -120,9 +120,9 @@ instance.tryImage("/tmp/image.png", "/path/output/compressed.png", options)
|
|
|
120
120
|
|
|
121
121
|
## References
|
|
122
122
|
|
|
123
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
124
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
125
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
123
|
+
- https://www.unpkg.com/@e-mc/types@0.9.3/lib/squared.d.ts
|
|
124
|
+
- https://www.unpkg.com/@e-mc/types@0.9.3/lib/compress.d.ts
|
|
125
|
+
- https://www.unpkg.com/@e-mc/types@0.9.3/lib/settings.d.ts
|
|
126
126
|
|
|
127
127
|
* https://www.npmjs.com/package/@types/node
|
|
128
128
|
|
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const fs = require("fs");
|
|
|
4
4
|
const stream = require("stream");
|
|
5
5
|
const zlib = require("zlib");
|
|
6
6
|
const wawoff2 = require("wawoff2");
|
|
7
|
+
const tinify = require("tinify");
|
|
7
8
|
const { toSfnt, toWoff } = require('woff2sfnt-sfnt2woff');
|
|
8
9
|
const types_1 = require("@e-mc/types");
|
|
9
10
|
const module_1 = require("@e-mc/module");
|
|
@@ -12,7 +13,6 @@ const CACHE_FONT = {};
|
|
|
12
13
|
const CACHE_FONTFROM = {};
|
|
13
14
|
const CACHE_FONTTO = {};
|
|
14
15
|
const CACHE_INIT = [false, false];
|
|
15
|
-
const CACHE_TINIFY = {};
|
|
16
16
|
let SINGLETON_INSTANCE;
|
|
17
17
|
let TEMP_DIR = '';
|
|
18
18
|
const GZIP_ZOPFLI = (function () {
|
|
@@ -227,10 +227,12 @@ class Compress extends module_1 {
|
|
|
227
227
|
options = output;
|
|
228
228
|
output = '';
|
|
229
229
|
}
|
|
230
|
+
else {
|
|
231
|
+
options || (options = {});
|
|
232
|
+
}
|
|
230
233
|
if (!(0, types_1.isString)(output)) {
|
|
231
234
|
output = typeof file === 'string' ? file : '';
|
|
232
235
|
}
|
|
233
|
-
options || (options = {});
|
|
234
236
|
const { filename, startTime = process.hrtime(), timeout = 0, sessionId, broadcastId } = options;
|
|
235
237
|
let format = options.format;
|
|
236
238
|
if (!format) {
|
|
@@ -517,7 +519,6 @@ class Compress extends module_1 {
|
|
|
517
519
|
else {
|
|
518
520
|
this.writeTimeProcess(ext, status, startTime, { type: 8, sessionId, broadcastId });
|
|
519
521
|
}
|
|
520
|
-
resolve(result);
|
|
521
522
|
if (!ctime && hash && cacheKey && TEMP_DIR) {
|
|
522
523
|
const pathname = path.join(TEMP_DIR, plugin, hash);
|
|
523
524
|
if (module_1.createDir(pathname)) {
|
|
@@ -529,6 +530,7 @@ class Compress extends module_1 {
|
|
|
529
530
|
});
|
|
530
531
|
}
|
|
531
532
|
}
|
|
533
|
+
resolve(result);
|
|
532
534
|
};
|
|
533
535
|
if (output) {
|
|
534
536
|
fs.writeFile(output, result, err => complete(err));
|
|
@@ -576,7 +578,7 @@ class Compress extends module_1 {
|
|
|
576
578
|
let stored;
|
|
577
579
|
try {
|
|
578
580
|
stored = (CACHE_IMAGE[plugin] || (CACHE_IMAGE[plugin] = {}))[hash = module_1.asHash(data)];
|
|
579
|
-
cacheKey =
|
|
581
|
+
cacheKey = plugin + ':' + module_1.asHash(apiKey ? format + apiKey : module_1.asString(options.options), 'md5');
|
|
580
582
|
const ctime = stored?.[cacheKey];
|
|
581
583
|
if (ctime) {
|
|
582
584
|
success(fs.readFileSync(path.join(TEMP_DIR, plugin, hash, cacheKey)), ctime);
|
|
@@ -595,47 +597,23 @@ class Compress extends module_1 {
|
|
|
595
597
|
}
|
|
596
598
|
if (apiKey) {
|
|
597
599
|
const apiProxy = proxyUrl && (typeof proxyUrl === 'function' ? proxyUrl("https://api.tinify.com") : proxyUrl) || this.module.tinify?.proxy || module_1.enabled("process.env.apply") && process.env.TINIFY_PROXY || '';
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
}
|
|
606
|
-
tinypng.validate(err => {
|
|
607
|
-
if (!err) {
|
|
608
|
-
fromBuffer();
|
|
609
|
-
CACHE_TINIFY[key] = tinypng;
|
|
610
|
-
}
|
|
611
|
-
else {
|
|
612
|
-
if (err instanceof tinypng.AccountError) {
|
|
613
|
-
delete CACHE_TINIFY[key];
|
|
600
|
+
tinify.key = apiKey;
|
|
601
|
+
tinify.proxy = apiProxy;
|
|
602
|
+
tinify.validate(err => {
|
|
603
|
+
if (!err) {
|
|
604
|
+
tinify.fromBuffer(data).toBuffer((error, result) => {
|
|
605
|
+
if (!error && result) {
|
|
606
|
+
success(result);
|
|
614
607
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
else if (cache) {
|
|
625
|
-
delete CACHE_TINIFY[key];
|
|
626
|
-
validate();
|
|
627
|
-
}
|
|
628
|
-
else {
|
|
629
|
-
failed(err || new Error("Unknown"));
|
|
630
|
-
}
|
|
631
|
-
});
|
|
632
|
-
};
|
|
633
|
-
if (!tinypng) {
|
|
634
|
-
validate();
|
|
635
|
-
}
|
|
636
|
-
else {
|
|
637
|
-
fromBuffer(true);
|
|
638
|
-
}
|
|
608
|
+
else {
|
|
609
|
+
failed(error || new Error("Unknown"));
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
else {
|
|
614
|
+
failed(err);
|
|
615
|
+
}
|
|
616
|
+
});
|
|
639
617
|
}
|
|
640
618
|
else {
|
|
641
619
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/compress",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Compress constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"license": "BSD 3-Clause",
|
|
24
24
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@e-mc/module": "0.9.
|
|
27
|
-
"@e-mc/types": "0.9.
|
|
26
|
+
"@e-mc/module": "0.9.3",
|
|
27
|
+
"@e-mc/types": "0.9.3",
|
|
28
28
|
"tinify": "^1.7.1",
|
|
29
29
|
"wawoff2": "^2.0.1",
|
|
30
30
|
"woff2sfnt-sfnt2woff": "^1.0.0"
|