Skip to content

Commit 70dc36b

Browse files
committed
feat: drop sharp for built-in Bun image transform
1 parent 35b45f8 commit 70dc36b

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

server/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@riffyh/server",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/rayriffy/rayriffy-h.git"
@@ -29,7 +29,6 @@
2929
"@toon-tools/elysia": "1.1.0",
3030
"debug": "4.4.3",
3131
"elysia": "1.4.29",
32-
"sharp": "0.35.2",
3332
"tweetnacl": "1.0.3",
3433
"tweetnacl-util": "0.15.1"
3534
},

server/src/index.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { cors } from "@elysiajs/cors";
66
import { toon } from "@toon-tools/elysia";
77

88
import { defineCacheInstance } from "@rayriffy/filesystem";
9-
import sharp from "sharp";
109
import { galleryModel, listingResultModel, type Config } from "@riffyh/commons";
1110
import debug from "debug";
1211
import path from "node:path";
@@ -166,17 +165,23 @@ const server = new Elysia()
166165
const dataSource = config.dataSources.find((o) => o.key === query.dataSource);
167166
if (dataSource === undefined) throw new Error(`data source ${query.dataSource} not found`);
168167

169-
const fetchedImage = await dataSource.getImage({
170-
url: query.url,
171-
});
172-
const resizedImage = await sharp(fetchedImage)
173-
.resize({
174-
width: query.type === "cover" ? 640 : 1280,
175-
})
176-
.toFormat(query.format, {
168+
const fetchedImage = new Bun.Image(
169+
await dataSource.getImage({
170+
url: query.url,
171+
}),
172+
).resize(query.type === "cover" ? 640 : 1280);
173+
174+
// if query.format is webp, then convert to webp
175+
if (query.format === "webp")
176+
fetchedImage.webp({
177177
quality: 72,
178-
})
179-
.toBuffer();
178+
});
179+
else if (query.format === "jpeg")
180+
fetchedImage.jpeg({
181+
quality: 72,
182+
});
183+
184+
const resizedImage = await fetchedImage.buffer();
180185
await cache.write(
181186
cacheKeys,
182187
resizedImage,

0 commit comments

Comments
 (0)