The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients"; |
| 2 | import { SOURCE_CONTROL_MEDIA_ASSET, type EnvironmentId } from "@t3tools/contracts"; |
| 3 | import type { FilePreviewItem } from "../../components/ui/FilePreviewModal.types"; |
| 4 | |
| 5 | export interface PullRequestMediaLocation { |
| 6 | readonly environmentId: EnvironmentId; |
| 7 | readonly cwd: string; |
| 8 | readonly repository?: string; |
| 9 | } |
| 10 | |
| 11 | /** Keep the original resource identity so previewers can resolve and renew its capability. */ |
| 12 | export function pullRequestMediaSource(url: string, location: PullRequestMediaLocation | null) { |
| 13 | const fetchUrl = sourceControlClients.mediaUrl(url)?.fetchUrl; |
| 14 | return location && fetchUrl |
| 15 | ? { |
| 16 | environmentId: location.environmentId, |
| 17 | resource: { |
| 18 | _tag: SOURCE_CONTROL_MEDIA_ASSET, |
| 19 | cwd: location.cwd, |
| 20 | url: fetchUrl, |
| 21 | ...(location.repository ? { repository: location.repository } : {}), |
| 22 | }, |
| 23 | } |
| 24 | : { uri: url }; |
| 25 | } |
| 26 | |
| 27 | export function pullRequestImageSource( |
| 28 | url: string, |
| 29 | location: PullRequestMediaLocation | null, |
| 30 | ): FilePreviewItem { |
| 31 | return { kind: "image", ...pullRequestMediaSource(url, location) }; |
| 32 | } |