markdown-exit-s3-image 1.0.1 → 2.0.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/dist/index.mjs +5 -3
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { promises } from "node:fs";
|
|
2
2
|
import { thumbHashToDataURL } from "thumbhash";
|
|
3
|
+
import sharp from "sharp";
|
|
3
4
|
|
|
4
5
|
//#region src/cache.ts
|
|
5
6
|
var ImageCache = class {
|
|
@@ -40,7 +41,7 @@ var ImageCache = class {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
get(key) {
|
|
43
|
-
const decodedKey =
|
|
44
|
+
const decodedKey = decodeURI(key);
|
|
44
45
|
if (this.cache[decodedKey]) {
|
|
45
46
|
this.stats.cacheHits++;
|
|
46
47
|
return this.cache[decodedKey];
|
|
@@ -49,7 +50,7 @@ var ImageCache = class {
|
|
|
49
50
|
return null;
|
|
50
51
|
}
|
|
51
52
|
set(key, value) {
|
|
52
|
-
const decodedKey =
|
|
53
|
+
const decodedKey = decodeURI(key);
|
|
53
54
|
if (JSON.stringify(this.cache[decodedKey]) !== JSON.stringify(value)) {
|
|
54
55
|
this.cache[decodedKey] = value;
|
|
55
56
|
this.isDirty = true;
|
|
@@ -151,7 +152,8 @@ async function getBitifulThumbhash(imageUrl) {
|
|
|
151
152
|
const response = await fetch(`${baseUrl}?fmt=thumbhash`);
|
|
152
153
|
if (!response.ok) throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
153
154
|
const base64String = await response.text();
|
|
154
|
-
|
|
155
|
+
const base64Data = thumbHashToDataURL(new Uint8Array(Buffer.from(base64String.trim(), "base64"))).replace(/^data:image\/\w+;base64,/, "");
|
|
156
|
+
return `data:image/webp;base64,${(await sharp(Buffer.from(base64Data, "base64")).webp({ quality: 80 }).toBuffer()).toString("base64")}`;
|
|
155
157
|
} catch (error) {
|
|
156
158
|
console.warn(`[Bitiful] Thumbhash error for ${imageUrl}:`, error instanceof Error ? error.message : String(error));
|
|
157
159
|
return null;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "markdown-exit-s3-image",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"author": "GnixAij",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "2.0.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"typescript": "^5.9.3"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
+
"sharp": "^0.34.5",
|
|
45
46
|
"thumbhash": "^0.1.1"
|
|
46
47
|
}
|
|
47
48
|
}
|