Open History to see the last commit
1import { imageMimeType } from "@t3tools/shared/image";
2import type { EnvironmentId } from "@t3tools/contracts";
3import type { FilePreviewItem } from "../components/ui/FilePreviewModal.types";
4import { isFileBackedComposerAttachment, type DraftComposerAttachment } from "./composerImages";
5import { remoteAttachmentImageSource } from "./filePreviewGallery";
6
7export function composerImageGallery(
8 attachments: readonly DraftComposerAttachment[],
9 environmentId?: EnvironmentId,
10): FilePreviewItem[] {
11 return attachments.flatMap((attachment): FilePreviewItem[] => {
12 if (attachment.type !== "image" && imageMimeType(attachment) === null) return [];
13 if (environmentId !== undefined && attachment.uploadedAttachmentId) {
14 return [
15 remoteAttachmentImageSource(environmentId, attachment.uploadedAttachmentId, attachment),
16 ];
17 }
18 if (isFileBackedComposerAttachment(attachment)) {
19 return [{ kind: "image", name: attachment.name, attachment }];
20 }
21 return attachment.type === "image"
22 ? [{ kind: "image", name: attachment.name, uri: attachment.dataUrl ?? attachment.previewUri }]
23 : [];
24 });
25}