Open History to see the last commit
1import { DownloadIcon, ExternalLinkIcon } from "lucide-react";
2
3import { resolveExternalWebLinkHost } from "../chat/externalLinkContextMenu";
4import { Button } from "../ui/button";
5import { resolveProtocolRelativeMediaUrl } from "./mediaContent";
6
7export function OpenMediaLink(props: {
8 readonly originalUrl?: string | undefined;
9 readonly src?: string | null | undefined;
10 readonly fileName?: string | undefined;
11 readonly className?: string | undefined;
12}) {
13 const originalUrl =
14 resolveExternalWebLinkHost(props.originalUrl) !== null ? props.originalUrl : undefined;
15 const source = originalUrl ?? props.src;
16 if (!source) return null;
17 const url = resolveProtocolRelativeMediaUrl(source);
18 let isBlob = false;
19 try {
20 const protocol = new URL(url).protocol;
21 if (protocol !== "http:" && protocol !== "https:" && protocol !== "blob:") return null;
22 isBlob = protocol === "blob:";
23 } catch {
24 return null;
25 }
26 return (
27 <Button
28 size="sm"
29 variant="secondary"
30 className={props.className}
31 render={
32 <a
33 href={url}
34 target={isBlob ? undefined : "_blank"}
35 download={isBlob ? props.fileName || true : undefined}
36 rel="noopener noreferrer"
37 />
38 }
39 >
40 {isBlob ? <DownloadIcon /> : <ExternalLinkIcon />}
41 {originalUrl ? "Open original" : isBlob ? "Download video" : "Open in browser"}
42 </Button>
43 );
44}