| 1 | import type { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import { githubMediaFetchUrl } from "@t3tools/shared/githubMedia"; |
| 3 | import type { FilePreviewItem } from "../../components/FilePreviewModal.types"; |
| 4 | |
| 5 | export interface PullRequestMediaLocation { |
| 6 | readonly environmentId: EnvironmentId; |
| 7 | readonly cwd: string; |
| 8 | } |
| 9 | |
| 10 | /** Keep the original resource identity so previewers can resolve and renew its capability. */ |
| 11 | export function pullRequestMediaSource(url: string, location: PullRequestMediaLocation | null) { |
| 12 | const fetchUrl = githubMediaFetchUrl(url); |
| 13 | return location && fetchUrl |
| 14 | ? { |
| 15 | environmentId: location.environmentId, |
| 16 | resource: { _tag: "github-media" as const, cwd: location.cwd, url: fetchUrl }, |
| 17 | } |
| 18 | : { uri: url }; |
| 19 | } |
| 20 | |
| 21 | export function pullRequestImageSource( |
| 22 | url: string, |
| 23 | location: PullRequestMediaLocation | null, |
| 24 | ): FilePreviewItem { |
| 25 | return { kind: "image", ...pullRequestMediaSource(url, location) }; |
| 26 | } |