markdown-exit-s3-image 1.0.2 → 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.
Files changed (2) hide show
  1. package/dist/index.mjs +3 -1
  2. 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 {
@@ -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
- return thumbHashToDataURL(new Uint8Array(Buffer.from(base64String.trim(), "base64")));
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": "1.0.2",
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
  }