The best way to control Claude Code, Codex and more from any computer or phone

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