Open History to see the last commit
1import type { ComposerContextRecord, EnvironmentId } from "@t3tools/contracts";
2import { imageMimeType } from "@t3tools/shared/image";
3import type { FilePreviewItem } from "../components/ui/FilePreviewModal.types";
4import { composerImageGallery } from "./composerImageGallery";
5import type { DraftComposerAttachment } from "./composerImages";
6import { remoteAttachmentImageSource } from "./filePreviewGallery";
7
8export function contextImageGallery(
9 records: readonly ComposerContextRecord[],
10 attachments: readonly DraftComposerAttachment[],
11 environmentId?: EnvironmentId,
12): FilePreviewItem[] {
13 return records.flatMap((record): FilePreviewItem[] => {
14 if (!("attachmentId" in record) || (record.kind !== "image" && imageMimeType(record) === null))
15 return [];
16 const local = attachments.find((item) => item.id === record.attachmentId);
17 if (local) return composerImageGallery([local]);
18 return environmentId
19 ? [remoteAttachmentImageSource(environmentId, record.attachmentId, record)]
20 : [];
21 });
22}