fix:imagetools

This commit is contained in:
2025-03-18 10:09:29 +01:00
parent 0f6bcc4267
commit a64acb9f71
11 changed files with 141 additions and 138 deletions
@@ -6,28 +6,32 @@ import { getSrcPath } from "./getSrcPath.js";
import getResolvedSrc from "./getResolvedSrc.js";
import { cwd, sharp } from "../../utils/runtimeChecks.js";
import throwErrorIfUnsupported from "./throwErrorIfUnsupported.js";
import { retryAsync } from "ts-retry";
import { DEFAULT_IO_DELAY } from "../../constants.js";
const { getImageDetails } = await (sharp
? import("./imagetools.js")
: import("./codecs.js"));
export default async function getProcessedImage(src, transformConfigs) {
throwErrorIfUnsupported(src, extname(src).slice(1));
export async function _getProcessedImage(src, transformConfigs) {
throwErrorIfUnsupported(src, extname(src).slice(1));
let base;
if (src.match("(http://|https://|data:image/).*")) {
({ src, base } = await getResolvedSrc(src))
({ src, base } = await getResolvedSrc(src));
} else {
const {
default: { isSsrBuild },
} = await import("../../astroViteConfigs.js")
} = await import("../../astroViteConfigs.js");
if (isSsrBuild) {
const filename = fileURLToPath(import.meta.url)
const assetPath = resolve(filename, "../../client") + src
const filename = fileURLToPath(import.meta.url);
const assetPath = resolve(filename, "../../client") + src;
src = "/" + relative(cwd, assetPath);
}
}
const {
w,
h,
@@ -57,3 +61,8 @@ export default async function getProcessedImage(src, transformConfigs) {
imageFormat,
};
}
export default async function getProcessedImage(src, transformConfigs) {
//@todo : hiccups in vips/sharp
return retryAsync(() => _getProcessedImage(src, transformConfigs), { delay: DEFAULT_IO_DELAY, maxTry: 3 })
}