fix(home): harden Qiniu featured previews

This commit is contained in:
134 2026-08-20 22:41:01 +08:00
parent d1582f33e8
commit afac47add2

View File

@ -13,6 +13,16 @@ type LovartFeaturedGalleryProps = {
setActiveCategory: (category: string) => void; setActiveCategory: (category: string) => void;
}; };
function getFeaturedPreviewUrl(item: FeaturedImage) {
const source = item.thumbnailUrl || item.originalUrl;
if (!source || !/^https:\/\/yybb\.top\//i.test(source) || source.includes("?")) {
return source;
}
return `${source}?imageView2/2/w/900/q/78`;
}
export function LovartFeaturedGallery({ export function LovartFeaturedGallery({
activeCategory, activeCategory,
categories, categories,
@ -60,10 +70,21 @@ export function LovartFeaturedGallery({
className="group mb-[24px] block w-full cursor-pointer break-inside-avoid text-left" className="group mb-[24px] block w-full cursor-pointer break-inside-avoid text-left"
> >
<img <img
src={item.thumbnailUrl || item.originalUrl} src={getFeaturedPreviewUrl(item)}
alt={item.prompt || "灵感图"} alt={item.prompt || "灵感图"}
loading="lazy" loading="lazy"
decoding="async" decoding="async"
onError={(event) => {
const image = event.currentTarget;
const fallbackUrl = item.originalUrl || item.thumbnailUrl;
if (!fallbackUrl || image.dataset.fallbackApplied === "true") {
return;
}
image.dataset.fallbackApplied = "true";
image.src = fallbackUrl;
}}
className="block h-auto w-full rounded-[6px] bg-[#e8e8e8] object-cover transition-transform duration-150 ease-out will-change-transform group-hover:scale-[1.008] dark:bg-[#1b1c20]" className="block h-auto w-full rounded-[6px] bg-[#e8e8e8] object-cover transition-transform duration-150 ease-out will-change-transform group-hover:scale-[1.008] dark:bg-[#1b1c20]"
/> />
<div className="mt-[8px] flex h-[22px] items-center justify-between text-[11px] font-normal leading-none text-[#b8b8b8] dark:text-white/45"> <div className="mt-[8px] flex h-[22px] items-center justify-between text-[11px] font-normal leading-none text-[#b8b8b8] dark:text-white/45">