Skip to content

Commit 8ea57ac

Browse files
fix(web): reattach legacy DNG draft markers
1 parent 3674ccd commit 8ea57ac

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎apps/web/src/composerDraftStore.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,42 @@ describe("composerDraftStore file attachments", () => {
521521
expect(draft?.files.map((file) => file.id)).toEqual(["file-accepted"]);
522522
});
523523

524+
it("reattaches a DNG with an older generic-MIME marker at attachment capacity", () => {
525+
const store = useComposerDraftStore.getState();
526+
const file = new File(["raw"], "photo.DNG", { type: "image/x-adobe-dng" });
527+
const marker: ComposerFileAttachment = {
528+
type: "file",
529+
id: "dng-marker",
530+
name: file.name,
531+
mimeType: "application/octet-stream",
532+
sizeBytes: file.size,
533+
file: null,
534+
};
535+
store.addFiles(threadRef, [marker]);
536+
store.addImages(
537+
threadRef,
538+
Array.from({ length: PROVIDER_SEND_TURN_MAX_ATTACHMENTS - 1 }, (_, index) =>
539+
makeImage({
540+
id: `image-${index}`,
541+
name: `image-${index}.png`,
542+
previewUrl: `blob:image-${index}`,
543+
}),
544+
),
545+
);
546+
547+
const repicked: ComposerFileAttachment = {
548+
...marker,
549+
id: "dng-repicked",
550+
mimeType: file.type,
551+
file,
552+
};
553+
store.addFiles(threadRef, [repicked]);
554+
555+
const files = store.getComposerDraft(threadRef)?.files;
556+
expect(files).toEqual([repicked]);
557+
expect(files?.some(composerFileNeedsReattach)).toBe(false);
558+
});
559+
524560
it("replaces a needs-reattach marker when the same file is picked again", () => {
525561
const store = useComposerDraftStore.getState();
526562
const marker: ComposerFileAttachment = { ...makeFile("file-marker"), file: null };

‎apps/web/src/composerDraftStore.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { stripInlineContextReferences } from "./lib/composerContextReferences";
2+
import { composerFileAttachmentMimeType } from "./components/chat/composerAttachmentFiles";
23
import { elementContextToPreviewAnnotation } from "./lib/elementContext";
34
import {
45
ElementContextDetails,
@@ -804,6 +805,17 @@ export function composerFileMatchesReattachMarker(
804805
): boolean {
805806
if (marker.name !== file.name || marker.sizeBytes !== file.sizeBytes) return false;
806807
if (marker.mimeType === file.mimeType) return true;
808+
const normalizedMarkerMimeType = composerFileAttachmentMimeType({
809+
name: marker.name,
810+
type: marker.mimeType,
811+
});
812+
if (
813+
normalizedMarkerMimeType === "image/x-adobe-dng" &&
814+
normalizedMarkerMimeType ===
815+
composerFileAttachmentMimeType({ name: file.name, type: file.mimeType })
816+
) {
817+
return true;
818+
}
807819
const markerMimeType = marker.mimeType.toLowerCase();
808820
return (
809821
(markerMimeType === "" || markerMimeType === "application/octet-stream") &&

0 commit comments

Comments
 (0)