diff --git a/src/components/MediaContent.tsx b/src/components/MediaContent.tsx index 18391823..45d7f368 100644 --- a/src/components/MediaContent.tsx +++ b/src/components/MediaContent.tsx @@ -1,48 +1,93 @@ import React from "react"; import Constants from "../constants/Constants"; +import LinkIcon from "./LinkIcon"; interface Props { question: object; } +const YOUTUBE_URL = "https://www.youtube.com/"; +const GOOGLE_DRIVE_URL = "https://drive.google.com/"; + const MediaContent = ({ question }: Props) => { - const renderMedia = () => { + const isGoogleDriveImage = (mediaContentUrl: string) => { + return ( + mediaContentUrl.includes("/file/d/") && + mediaContentUrl.includes(GOOGLE_DRIVE_URL) + ); + }; + + const isYoutubeVideo = (mediaContentUrl: string) => { + return ( + mediaContentUrl.includes("watch?v=") && + mediaContentUrl.includes(YOUTUBE_URL) + ); + }; + + const getMediaId = (mediaContentUrl: string) => { + if (isGoogleDriveImage(mediaContentUrl)) { + return mediaContentUrl.substring( + mediaContentUrl.indexOf("/file/d/") + 8, + mediaContentUrl.lastIndexOf("/") + ); + } + if (isYoutubeVideo(mediaContentUrl)) { + return mediaContentUrl.substring(mediaContentUrl.indexOf("watch?v=") + 8); + } + }; + + const getEmbedLink = (mediaContentUrl: string) => { + if (isGoogleDriveImage(mediaContentUrl)) { + return ( + GOOGLE_DRIVE_URL + "uc?export=view&id=" + getMediaId(mediaContentUrl) + ); + } + if (isYoutubeVideo(mediaContentUrl)) { + return YOUTUBE_URL + "embed/" + getMediaId(mediaContentUrl); + } + return mediaContentUrl; + }; + + const getMediaType = (mediaContentUrl: string) => { + if (mediaContentUrl.includes(YOUTUBE_URL)) { + return