fix: show missing tutorial file download, support more video formats
- Render the download button for a tutorial's uploaded file field (it was fetched from the API but never displayed). - Recognize mov/avi/wmv as video (the backend already accepts them as uploads) and add a download fallback for any media type the browser can't play inline instead of a dead "unknown file type" message. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KMLvfLviDB12t4U9UijE4k
This commit is contained in:
@@ -13,7 +13,7 @@ const getMediaType = (url: string) => {
|
|||||||
if (["jpg", "jpeg", "png", "gif"].includes(extension)) {
|
if (["jpg", "jpeg", "png", "gif"].includes(extension)) {
|
||||||
return "image";
|
return "image";
|
||||||
}
|
}
|
||||||
if (["mp4", "webm", "ogg"].includes(extension)) {
|
if (["mp4", "webm", "ogg", "mov", "avi", "wmv"].includes(extension)) {
|
||||||
return "video";
|
return "video";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,6 +117,7 @@ const Learn = ({ activeTutorial }: LearnProps) => {
|
|||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
medias: string[];
|
medias: string[];
|
||||||
|
file: string | null;
|
||||||
url_file: string;
|
url_file: string;
|
||||||
}) => (
|
}) => (
|
||||||
<div
|
<div
|
||||||
@@ -141,18 +142,36 @@ const Learn = ({ activeTutorial }: LearnProps) => {
|
|||||||
className="w-full h-full object-cover rounded-lg"
|
className="w-full h-full object-cover rounded-lg"
|
||||||
/>
|
/>
|
||||||
) : mediaType === "video" ? (
|
) : mediaType === "video" ? (
|
||||||
<video
|
<div className="w-full h-full flex flex-col gap-2">
|
||||||
src={media}
|
<video
|
||||||
controls
|
src={media}
|
||||||
className="w-full h-full object-cover rounded-lg"
|
controls
|
||||||
/>
|
className="w-full h-full object-cover rounded-lg"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
extra="!py-1 self-center"
|
||||||
|
onClick={() => saveAs(media)}
|
||||||
|
>
|
||||||
|
دانلود ویدیو
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<p>نوع فایل ناشناخته است</p>
|
<div className="w-full h-full flex flex-col gap-2 justify-center items-center">
|
||||||
|
<p>نوع فایل قابل نمایش نیست</p>
|
||||||
|
<Button extra="!py-1" onClick={() => saveAs(media)}>
|
||||||
|
دانلود فایل
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
{i.file && (
|
||||||
|
<Button extra="!mb-4" onClick={() => saveAs(i.file as string)}>
|
||||||
|
دانلود فایل آموزش
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
{i.url_file && (
|
{i.url_file && (
|
||||||
<>
|
<>
|
||||||
<Button extra="!mb-4" onClick={() => saveAs(i.url_file)}>
|
<Button extra="!mb-4" onClick={() => saveAs(i.url_file)}>
|
||||||
|
|||||||
Reference in New Issue
Block a user