import React from "react"; import Icon from "./Icon"; import { getResourceUrl } from "@/utils/resource"; import showPreviewImageDialog from "./PreviewImageDialog"; import SquareDiv from "./kit/SquareDiv"; import "@/less/resource-cover.less"; interface ResourceCoverProps { resource: Resource; } const getResourceType = (resource: Resource) => { if (resource.type.startsWith("image")) { return "image/*"; } else if (resource.type.startsWith("video")) { return "video/*"; } else if (resource.type.startsWith("audio")) { return "audio/*"; } else if (resource.type.startsWith("text")) { return "text/*"; } else if (resource.type.startsWith("application/epub+zip")) { return "application/epub+zip"; } else if (resource.type.startsWith("application/pdf")) { return "application/pdf"; } else if (resource.type.includes("word")) { return "application/msword"; } else if (resource.type.includes("excel")) { return "application/msexcel"; } else if (resource.type.startsWith("application/zip")) { return "application/zip"; } else if (resource.type.startsWith("application/x-java-archive")) { return "application/x-java-archive"; } else { return "application/octet-stream"; } }; const ResourceCover = ({ resource }: ResourceCoverProps) => { const resourceType = getResourceType(resource); const resourceUrl = getResourceUrl(resource); switch (resourceType) { case "image/*": return ( showPreviewImageDialog(resourceUrl)} /> ); case "video/*": return ; case "audio/*": return ; case "text/*": return ; case "application/epub+zip": return ; case "application/pdf": return ; case "application/msword": return ; case "application/msexcel": return ; case "application/zip": return ; case "application/x-java-archive": return ; default: return ; } }; export default React.memo(ResourceCover);