The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { imageMimeType } from "@t3tools/shared/image"; |
| 2 | import type { EnvironmentId } from "@t3tools/contracts"; |
| 3 | import type { FilePreviewItem } from "../components/ui/FilePreviewModal.types"; |
| 4 | import { isFileBackedComposerAttachment, type DraftComposerAttachment } from "./composerImages"; |
| 5 | |
| 6 | export function composerImageGallery( |
| 7 | attachments: readonly DraftComposerAttachment[], |
| 8 | environmentId?: EnvironmentId, |
| 9 | ): FilePreviewItem[] { |
| 10 | return attachments.flatMap((attachment): FilePreviewItem[] => { |
| 11 | if (attachment.type !== "image" && imageMimeType(attachment) === null) return []; |
| 12 | if (environmentId !== undefined && attachment.uploadedAttachmentId) { |
| 13 | return [ |
| 14 | { |
| 15 | kind: "image", |
| 16 | name: attachment.name, |
| 17 | environmentId, |
| 18 | resource: { |
| 19 | _tag: "attachment", |
| 20 | attachmentId: attachment.uploadedAttachmentId, |
| 21 | fileName: attachment.name, |
| 22 | mimeType: attachment.mimeType, |
| 23 | }, |
| 24 | }, |
| 25 | ]; |
| 26 | } |
| 27 | if (isFileBackedComposerAttachment(attachment)) { |
| 28 | return [{ kind: "image", name: attachment.name, attachment }]; |
| 29 | } |
| 30 | return attachment.type === "image" |
| 31 | ? [{ kind: "image", name: attachment.name, uri: attachment.dataUrl ?? attachment.previewUri }] |
| 32 | : []; |
| 33 | }); |
| 34 | } |