final sharp fetch
This commit is contained in:
@@ -8,11 +8,34 @@ async function getSharp(): Promise<typeof import("sharp") extends { default: inf
|
|||||||
try {
|
try {
|
||||||
_sharp = (await import("sharp")).default as any;
|
_sharp = (await import("sharp")).default as any;
|
||||||
return _sharp!;
|
return _sharp!;
|
||||||
|
} catch (bareErr) {
|
||||||
|
try {
|
||||||
|
const { createRequire } = await import("node:module");
|
||||||
|
const path = await import("node:path");
|
||||||
|
const root = process.env.OVERLORD_ROOT || process.cwd();
|
||||||
|
const req = createRequire(path.join(root, "noop.js"));
|
||||||
|
const candidates = [
|
||||||
|
path.join(root, "node_modules", "sharp"),
|
||||||
|
"sharp",
|
||||||
|
];
|
||||||
|
let lastErr: unknown = bareErr;
|
||||||
|
for (const id of candidates) {
|
||||||
|
try {
|
||||||
|
const mod = req(id);
|
||||||
|
_sharp = (mod && (mod.default ?? mod)) as any;
|
||||||
|
return _sharp!;
|
||||||
|
} catch (err) {
|
||||||
|
lastErr = err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.error("[thumbnails] Failed to load sharp module. Thumbnails will be unavailable.", lastErr);
|
||||||
|
throw lastErr;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("[thumbnails] Failed to load sharp module. Thumbnails will be unavailable.", err);
|
console.error("[thumbnails] Failed to load sharp module. Thumbnails will be unavailable.", err);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const THUMBNAIL_WIDTH = Math.max(64, Number(process.env.OVERLORD_THUMBNAIL_WIDTH || 640));
|
const THUMBNAIL_WIDTH = Math.max(64, Number(process.env.OVERLORD_THUMBNAIL_WIDTH || 640));
|
||||||
const THUMBNAIL_HEIGHT = Math.max(48, Number(process.env.OVERLORD_THUMBNAIL_HEIGHT || 360));
|
const THUMBNAIL_HEIGHT = Math.max(48, Number(process.env.OVERLORD_THUMBNAIL_HEIGHT || 360));
|
||||||
|
|||||||
Reference in New Issue
Block a user