修复videocard右键菜单不使用备用源

This commit is contained in:
mtvpls
2026-04-19 09:33:13 +08:00
parent a43af13193
commit abdc034140
+22 -8
View File
@@ -21,7 +21,12 @@ import {
saveFavorite, saveFavorite,
subscribeToDataUpdates, subscribeToDataUpdates,
} from '@/lib/db.client'; } from '@/lib/db.client';
import { processImageUrl, base58Decode, tryApplyDoubanImageFallback } from '@/lib/utils'; import {
processImageUrl,
base58Decode,
tryApplyDoubanImageFallback,
getDoubanImageFallbackUrl,
} from '@/lib/utils';
import { useLongPress } from '@/hooks/useLongPress'; import { useLongPress } from '@/hooks/useLongPress';
import AIChatPanel from '@/components/AIChatPanel'; import AIChatPanel from '@/components/AIChatPanel';
@@ -105,6 +110,9 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
ref ref
) { ) {
const router = useRouter(); const router = useRouter();
const actualTitle = title;
const actualPoster = poster;
const processedPoster = useMemo(() => processImageUrl(actualPoster), [actualPoster]);
const [favorited, setFavorited] = useState(false); const [favorited, setFavorited] = useState(false);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [showMobileActions, setShowMobileActions] = useState(false); const [showMobileActions, setShowMobileActions] = useState(false);
@@ -116,6 +124,7 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
const [showDetailPanel, setShowDetailPanel] = useState(false); const [showDetailPanel, setShowDetailPanel] = useState(false);
const [showImageViewer, setShowImageViewer] = useState(false); const [showImageViewer, setShowImageViewer] = useState(false);
const [showUpcomingInfo, setShowUpcomingInfo] = useState(false); // 控制即将上映倒计时的显示 const [showUpcomingInfo, setShowUpcomingInfo] = useState(false); // 控制即将上映倒计时的显示
const [displayPoster, setDisplayPoster] = useState(processedPoster);
// 检查AI功能是否启用 // 检查AI功能是否启用
useEffect(() => { useEffect(() => {
@@ -156,14 +165,16 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
setDynamicDoubanId(douban_id); setDynamicDoubanId(douban_id);
}, [douban_id]); }, [douban_id]);
useEffect(() => {
setDisplayPoster(processedPoster);
}, [processedPoster]);
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
setEpisodes: (eps?: number) => setDynamicEpisodes(eps), setEpisodes: (eps?: number) => setDynamicEpisodes(eps),
setSourceNames: (names?: string[]) => setDynamicSourceNames(names), setSourceNames: (names?: string[]) => setDynamicSourceNames(names),
setDoubanId: (id?: number) => setDynamicDoubanId(id), setDoubanId: (id?: number) => setDynamicDoubanId(id),
})); }));
const actualTitle = title;
const actualPoster = poster;
const actualSource = source; const actualSource = source;
const actualId = id; const actualId = id;
const actualDoubanId = dynamicDoubanId; const actualDoubanId = dynamicDoubanId;
@@ -738,7 +749,7 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
</div> </div>
) : ( ) : (
<Image <Image
src={processImageUrl(actualPoster)} src={displayPoster}
alt={actualTitle} alt={actualTitle}
fill fill
className={origin === 'live' ? 'object-contain' : orientation === 'horizontal' ? 'object-cover object-center' : 'object-cover'} className={origin === 'live' ? 'object-contain' : orientation === 'horizontal' ? 'object-cover object-center' : 'object-cover'}
@@ -751,7 +762,9 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
}} }}
onError={(e) => { onError={(e) => {
const img = e.currentTarget as HTMLImageElement; const img = e.currentTarget as HTMLImageElement;
if (tryApplyDoubanImageFallback(img, actualPoster)) { const fallbackPoster = getDoubanImageFallbackUrl(actualPoster);
if (fallbackPoster && tryApplyDoubanImageFallback(img, actualPoster)) {
setDisplayPoster(fallbackPoster);
return; return;
} }
@@ -759,7 +772,8 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
if (!img.dataset.retried) { if (!img.dataset.retried) {
img.dataset.retried = 'true'; img.dataset.retried = 'true';
setTimeout(() => { setTimeout(() => {
img.src = processImageUrl(actualPoster); setDisplayPoster(processedPoster);
img.src = processedPoster;
}, 2000); }, 2000);
} }
}} }}
@@ -1545,7 +1559,7 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
isOpen={showMobileActions} isOpen={showMobileActions}
onClose={() => setShowMobileActions(false)} onClose={() => setShowMobileActions(false)}
title={actualTitle} title={actualTitle}
poster={processImageUrl(actualPoster)} poster={displayPoster}
actions={mobileActions} actions={mobileActions}
sources={isAggregate && dynamicSourceNames ? Array.from(new Set(dynamicSourceNames)) : undefined} sources={isAggregate && dynamicSourceNames ? Array.from(new Set(dynamicSourceNames)) : undefined}
isAggregate={isAggregate} isAggregate={isAggregate}
@@ -1583,7 +1597,7 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
isOpen={showDetailPanel} isOpen={showDetailPanel}
onClose={() => setShowDetailPanel(false)} onClose={() => setShowDetailPanel(false)}
title={actualTitle} title={actualTitle}
poster={processImageUrl(actualPoster)} poster={displayPoster}
doubanId={actualDoubanId} doubanId={actualDoubanId}
bangumiId={isBangumi ? actualDoubanId : undefined} bangumiId={isBangumi ? actualDoubanId : undefined}
isBangumi={isBangumi} isBangumi={isBangumi}