mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-18 07:16:34 +00:00
fix(video-embed): refactor URL generation and prevent Bilibili autoplay
This commit is contained in:
parent
95eed59c26
commit
e490f1bcea
@ -3,25 +3,19 @@ interface VideoEmbedProps {
|
|||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const platformSrcMap: Record<VideoEmbedProps["platform"], string> = {
|
const platformSrcMap = {
|
||||||
youtube: "https://www.youtube.com/embed/",
|
youtube: (id: string) => `https://www.youtube.com/embed/${id}`,
|
||||||
bilibili: "https://player.bilibili.com/player.html?bvid=",
|
bilibili: (id: string) =>
|
||||||
};
|
`https://player.bilibili.com/player.html?bvid=${id}&autoplay=0`,
|
||||||
|
} as const;
|
||||||
export function VideoEmbed({
|
|
||||||
platform,
|
|
||||||
id,
|
|
||||||
}: VideoEmbedProps) {
|
|
||||||
const src = platformSrcMap[platform] + id;
|
|
||||||
|
|
||||||
|
export function VideoEmbed({ platform, id }: VideoEmbedProps) {
|
||||||
return (
|
return (
|
||||||
<div>
|
|
||||||
<iframe
|
<iframe
|
||||||
className="aspect-video w-full"
|
className="aspect-video w-full"
|
||||||
src={src}
|
src={platformSrcMap[platform](id)}
|
||||||
title={`${platform} Video Player`}
|
title={`${platform} Video Player`}
|
||||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; fullscreen"
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; fullscreen"
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user