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;
|
let loadingSharp = false;
|
||||||
import { rgbaToThumbHash } from "thumbhash";
|
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) {
|
if (!loadingSharp) {
|
||||||
loadingSharp = true;
|
loadingSharp = true;
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
// @ts-ignore
|
s = (await import("sharp")).default;
|
||||||
globalThis["sharp"] = (await import("sharp")).default;
|
|
||||||
}, 1000);
|
}, 1000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
export async function generateThumbHash(image: { width: number, height: number }) {
|
||||||
const sharp = globalThis["sharp"] as typeof import("sharp");
|
|
||||||
|
|
||||||
|
const sharp = await getSharp();
|
||||||
if (!sharp) return;
|
if (!sharp) return;
|
||||||
|
|
||||||
const scaleFactor = 100 / Math.max(image.width, image.height);
|
const scaleFactor = 100 / Math.max(image.width, image.height);
|
||||||
|
Loading…
Reference in New Issue
Block a user