This commit is contained in:
commit
0f20ad8ad2
204 files changed
+103917
-104799
No files matched your search
@@ -22,6 +22,24 @@ export default function SafeImage({
|
||||
const [error, setError] = React.useState(false);
|
||||
const [loading, setLoading] = React.useState(true);
|
||||
|
||||
// Check if external domain is in allowed remote patterns or relative path
|
||||
const isExternal = typeof src === 'string' && (src.startsWith('http://') || src.startsWith('https://'));
|
||||
const isBlobOrData = typeof src === 'string' && (src.startsWith('blob:') || src.startsWith('data:'));
|
||||
const isAllowedHost = React.useMemo(() => {
|
||||
if (!isExternal || !src) return true;
|
||||
try {
|
||||
const url = new URL(src);
|
||||
const allowedHosts = [
|
||||
'canina.ir', 'api.canina.ir', 'stage.canina.ir', 'stageapi.canina.ir',
|
||||
'apicanina.parsaaghayi.ir', 'canina.de', 'www.canina.de',
|
||||
'images.unsplash.com', 'plus.unsplash.com', 'localhost', '127.0.0.1'
|
||||
];
|
||||
return allowedHosts.some(h => url.hostname === h || url.hostname.endsWith(`.${h}`));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}, [src, isExternal]);
|
||||
|
||||
if (!src || error) {
|
||||
return (
|
||||
<div className={cn(
|
||||
@@ -43,24 +61,6 @@ export default function SafeImage({
|
||||
);
|
||||
}
|
||||
|
||||
// Check if external domain is in allowed remote patterns or relative path
|
||||
const isExternal = typeof src === 'string' && (src.startsWith('http://') || src.startsWith('https://'));
|
||||
const isBlobOrData = typeof src === 'string' && (src.startsWith('blob:') || src.startsWith('data:'));
|
||||
const isAllowedHost = React.useMemo(() => {
|
||||
if (!isExternal) return true;
|
||||
try {
|
||||
const url = new URL(src);
|
||||
const allowedHosts = [
|
||||
'canina.ir', 'api.canina.ir', 'stage.canina.ir', 'stageapi.canina.ir',
|
||||
'apicanina.parsaaghayi.ir', 'canina.de', 'www.canina.de',
|
||||
'images.unsplash.com', 'plus.unsplash.com', 'localhost', '127.0.0.1'
|
||||
];
|
||||
return allowedHosts.some(h => url.hostname === h || url.hostname.endsWith(`.${h}`));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}, [src, isExternal]);
|
||||
|
||||
return (
|
||||
<div className={cn("relative overflow-hidden group flex items-center justify-center", className)}>
|
||||
{loading && (
|
||||
|
||||
Reference in new issue
Block a user