fix(learning): load readme images over https

This commit is contained in:
2026-08-20 13:51:48 +08:00
parent 28bfd8bc3e
commit 9956739693
6 changed files with 103 additions and 7 deletions

View File

@@ -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);

View File

@@ -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,

View File

@@ -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: '',