fix: make image loading more robust
All checks were successful
Deploy to SFTP Server / build (push) Successful in 6m38s
All checks were successful
Deploy to SFTP Server / build (push) Successful in 6m38s
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import type { ImageMetadata } from "astro";
|
||||
import { Picture as AstroImage } from "astro:assets";
|
||||
import { generateThumbHash, getExifData } from "@helpers/image";
|
||||
import sharp from "sharp";
|
||||
interface Props {
|
||||
src: ImageMetadata & { fsPath?: string };
|
||||
alt: string;
|
||||
@@ -16,8 +17,8 @@ interface Props {
|
||||
async function checkImage(src: string) {
|
||||
try {
|
||||
if (src.startsWith("/@fs") || src.startsWith("/_astro")) return true;
|
||||
const res = await fetch(src);
|
||||
if (res.ok) {
|
||||
const res = await sharp(src).metadata();
|
||||
if (res.format) {
|
||||
return true;
|
||||
}else {
|
||||
console.log("Failed to fetch: ", src);
|
||||
|
||||
Reference in New Issue
Block a user