fix(learning): load readme images over https
This commit is contained in:
@@ -132,7 +132,7 @@ export function isLearningProjectMediaUrl(value: string): boolean {
|
||||
return PROJECT_MEDIA_URL_PATTERN.test(value);
|
||||
}
|
||||
|
||||
export function isSafeLearningCoverUrl(value: string): boolean {
|
||||
export function isSafeLearningImageUrl(value: string): boolean {
|
||||
if (PROJECT_MEDIA_URL_PATTERN.test(value)) return true;
|
||||
try {
|
||||
const url = new URL(value);
|
||||
|
||||
@@ -146,6 +146,7 @@ export function LearningProjectDetail() {
|
||||
<ProjectImage
|
||||
src={src}
|
||||
alt={alt || '项目说明图片'}
|
||||
allowHttps
|
||||
className="my-6 max-h-[34rem] w-full rounded-2xl border border-black/10 object-contain"
|
||||
/>
|
||||
) : null,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ImageOff, Loader2 } from 'lucide-react';
|
||||
import {
|
||||
fetchLearningProjectMedia,
|
||||
isLearningProjectMediaUrl,
|
||||
isSafeLearningCoverUrl,
|
||||
isSafeLearningImageUrl,
|
||||
} from '@/lib/learning';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
@@ -16,7 +16,7 @@ type ProjectImageProps = {
|
||||
|
||||
export function ProjectImage({ src, alt, className, allowHttps = false }: ProjectImageProps) {
|
||||
const controlledMedia = isLearningProjectMediaUrl(src);
|
||||
const directSource = allowHttps && isSafeLearningCoverUrl(src) && !controlledMedia ? src : null;
|
||||
const directSource = allowHttps && isSafeLearningImageUrl(src) && !controlledMedia ? src : null;
|
||||
const [failedSource, setFailedSource] = useState<string | null>(null);
|
||||
const [state, setState] = useState<{ input: string; source: string; status: 'ready' | 'error' }>({
|
||||
input: '',
|
||||
|
||||
Reference in New Issue
Block a user