豆瓣数据源增加备用源

This commit is contained in:
mtvpls
2026-04-09 21:30:07 +08:00
parent 204eec782f
commit 769dbf8310
11 changed files with 778 additions and 202 deletions
+49
View File
@@ -0,0 +1,49 @@
'use client';
import React from 'react';
import { processImageUrl, tryApplyDoubanImageFallback } from '@/lib/utils';
interface ProxyImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {
originalSrc: string;
displaySrc?: string;
retryDelay?: number;
retryOnError?: boolean;
}
const ProxyImage: React.FC<ProxyImageProps> = ({
originalSrc,
displaySrc,
retryDelay = 2000,
retryOnError = true,
onError,
src: _src,
...props
}) => {
const handleError = (e: React.SyntheticEvent<HTMLImageElement, Event>) => {
const img = e.currentTarget;
if (tryApplyDoubanImageFallback(img, originalSrc)) {
return;
}
if (retryOnError && !img.dataset.retried) {
img.dataset.retried = 'true';
window.setTimeout(() => {
img.src = displaySrc || processImageUrl(originalSrc);
}, retryDelay);
}
onError?.(e);
};
return (
<img
{...props}
src={displaySrc || processImageUrl(originalSrc)}
onError={handleError}
/>
);
};
export default ProxyImage;