fix: lazily import sharp to fix commonjs error
This commit is contained in:
@@ -8,7 +8,6 @@ import { DATA_DIR } from "@lib/env.ts";
|
||||
import { db } from "@lib/db/sqlite.ts";
|
||||
import { imageTable } from "@lib/db/schema.ts";
|
||||
import { eq } from "drizzle-orm";
|
||||
import sharp from "sharp";
|
||||
|
||||
const log = createLogger("cache/image");
|
||||
|
||||
@@ -158,6 +157,8 @@ async function resizeImage(
|
||||
mediaType: string;
|
||||
},
|
||||
) {
|
||||
const sharp = (await import("sharp")).default;
|
||||
|
||||
try {
|
||||
log.debug("Resizing image", { params });
|
||||
|
||||
@@ -211,6 +212,8 @@ async function resizeImage(
|
||||
async function createThumbhash(
|
||||
image: Uint8Array,
|
||||
): Promise<{ hash: string; average: string }> {
|
||||
const sharp = (await import("sharp")).default;
|
||||
|
||||
try {
|
||||
const resizedImage = await sharp(image)
|
||||
.resize(100, 100, { fit: "cover" }) // Keep aspect ratio within bounds
|
||||
@@ -238,6 +241,8 @@ async function createThumbhash(
|
||||
* Verifies that an image buffer contains valid image data
|
||||
*/
|
||||
async function verifyImage(imageBuffer: Uint8Array): Promise<boolean> {
|
||||
const sharp = (await import("sharp")).default;
|
||||
|
||||
try {
|
||||
const metadata = await sharp(imageBuffer).metadata();
|
||||
return !!(metadata.width && metadata.height && metadata.format);
|
||||
|
||||
Reference in New Issue
Block a user