feat: improve some error messages
All checks were successful
Deploy to SFTP Server / build (push) Successful in 4m6s
All checks were successful
Deploy to SFTP Server / build (push) Successful in 4m6s
This commit is contained in:
parent
c74b314b1e
commit
b32ca7d65e
@ -3,7 +3,7 @@ import type { ImageMetadata } from "astro";
|
|||||||
import { Picture as AstroImage } from "astro:assets";
|
import { Picture as AstroImage } from "astro:assets";
|
||||||
import { generateThumbHash, getExifData } from "@helpers/image";
|
import { generateThumbHash, getExifData } from "@helpers/image";
|
||||||
interface Props {
|
interface Props {
|
||||||
src: ImageMetadata;
|
src: ImageMetadata & { fsPath?: string };
|
||||||
alt: string;
|
alt: string;
|
||||||
pictureClass?: string;
|
pictureClass?: string;
|
||||||
class?: string;
|
class?: string;
|
||||||
@ -22,7 +22,7 @@ const {
|
|||||||
maxWidth,
|
maxWidth,
|
||||||
} = Astro.props;
|
} = Astro.props;
|
||||||
|
|
||||||
let thumbhash = hash ? await generateThumbHash(image) : "";
|
let thumbhash = hash && image.fsPath ? await generateThumbHash(image) : "";
|
||||||
|
|
||||||
let exif = await getExifData(image);
|
let exif = await getExifData(image);
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ async function getSharp(): Promise<typeof import("sharp") | undefined> {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function generateThumbHash(image: ImageMetadata) {
|
export async function generateThumbHash(image: ImageMetadata & { fsPath?: string }) {
|
||||||
|
|
||||||
const sharp = await getSharp();
|
const sharp = await getSharp();
|
||||||
if (!sharp) return;
|
if (!sharp) return;
|
||||||
@ -20,7 +20,6 @@ export async function generateThumbHash(image: ImageMetadata) {
|
|||||||
const smallHeight = Math.floor(image.height * scaleFactor);
|
const smallHeight = Math.floor(image.height * scaleFactor);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//@ts-ignore
|
|
||||||
const smallImg = await sharp(image.fsPath)
|
const smallImg = await sharp(image.fsPath)
|
||||||
.resize(smallWidth, smallHeight)
|
.resize(smallWidth, smallHeight)
|
||||||
.withMetadata()
|
.withMetadata()
|
||||||
@ -31,9 +30,8 @@ export async function generateThumbHash(image: ImageMetadata) {
|
|||||||
const buffer = rgbaToThumbHash(smallWidth, smallHeight, smallImg);
|
const buffer = rgbaToThumbHash(smallWidth, smallHeight, smallImg);
|
||||||
return Buffer.from(buffer).toString("base64");
|
return Buffer.from(buffer).toString("base64");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//@ts-ignore
|
|
||||||
console.log(`Could not generate thumbhash for ${image.fsPath}`, error)
|
console.log(`Could not generate thumbhash for ${image.fsPath}`, error)
|
||||||
return undefined
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user