fix: some stupid issue with sharp
All checks were successful
Deploy to SFTP Server / build (push) Successful in 21m19s
All checks were successful
Deploy to SFTP Server / build (push) Successful in 21m19s
This commit is contained in:
parent
0f1ece8a3e
commit
c513605de6
@ -1,19 +1,29 @@
|
||||
let loadingSharp = false;
|
||||
import { rgbaToThumbHash } from "thumbhash";
|
||||
|
||||
export async function generateThumbHash(image: { width: number, height: number }) {
|
||||
let s: typeof import("sharp") | undefined;
|
||||
|
||||
async function getSharp(): Promise<typeof import("sharp") | undefined> {
|
||||
|
||||
if (s) return s;
|
||||
|
||||
if (import.meta.env.MODE !== "development") {
|
||||
s = (await import("sharp")).default;
|
||||
return s;
|
||||
}
|
||||
|
||||
if (!loadingSharp) {
|
||||
loadingSharp = true;
|
||||
setTimeout(async () => {
|
||||
// @ts-ignore
|
||||
globalThis["sharp"] = (await import("sharp")).default;
|
||||
s = (await import("sharp")).default;
|
||||
}, 1000);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const sharp = globalThis["sharp"] as typeof import("sharp");
|
||||
export async function generateThumbHash(image: { width: number, height: number }) {
|
||||
|
||||
const sharp = await getSharp();
|
||||
if (!sharp) return;
|
||||
|
||||
const scaleFactor = 100 / Math.max(image.width, image.height);
|
||||
|
Loading…
Reference in New Issue
Block a user