This commit is contained in:
MythEclipse
2026-06-02 22:55:32 +07:00
parent f4b2b76881
commit ce2b789282
@@ -285,9 +285,10 @@ export async function computeImagePhash(
buffer: Buffer, buffer: Buffer,
): Promise<string | null> { ): Promise<string | null> {
try { try {
// Dynamic import to avoid issues if imghash native bindings aren't available // Dynamic import — imghash is ESM with a default export containing { hash, hashRaw, ... }
const imghashModule = await import("imghash"); const imghashModule: { default?: { hash?: (buf: Buffer) => Promise<string> } } =
const hashFn = imghashModule.default?.hash ?? imghashModule.hash; await import("imghash");
const hashFn = imghashModule.default?.hash;
if (typeof hashFn !== "function") return null; if (typeof hashFn !== "function") return null;
const hash = await hashFn(buffer); const hash = await hashFn(buffer);
return hash; return hash;