feat(attachments): support local files and video attachments (#6321)
* feat(attachments): support local files and video attachments Share gateway inspection and send validation for borrowed local paths while preserving binary uploads, original-file ownership, and existing limits. Related to NAN-284. Native provider video input remains outside this change. * test: make cross-platform verification fixtures self-contained * test(webui): align typed fixtures with runtime contracts * fix(webui): preserve uploaded video playback during history sync * test(tui): preserve local attachment drafts across resizes * perf(attachments): preserve upload caches and release video previews * docs(webui): keep attachment guidance user-focused * chore: remove redundant dependency comment * test(providers): make stream idle renewal timing deterministic * fix(attachments): keep upload byte limits out of local references Validate common format/count rules separately from upload byte budgets. Keep local inspection and send-time checks metadata-only, and exclude local references from composer and pending-upload totals. Explain upload size rejections with actual size and maximum in all ten locales. Related to NAN-284. * fix(attachments): retain image references and draft order * fix(attachments): close local reference UX and authorization gaps * fix(attachments): preserve focus during asynchronous path confirmation
This commit is contained in:
1 parent
7dfeff9ddf
commit
254f94b068
65 files changed
+1816
-292
No files matched your search
@@ -8,7 +8,7 @@ const draft: ComposerDraft = {
|
||||
text: " Keep this draft\n继续编辑",
|
||||
quotedContext: "Quoted answer",
|
||||
sessionMentions: [{ name: "other", title: "Other topic", session_key: "websocket:other" }],
|
||||
files: [new File(["attachment"], "draft.txt", { type: "text/plain" })],
|
||||
attachments: [new File(["attachment"], "draft.txt", { type: "text/plain" })],
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
@@ -21,15 +21,15 @@ describe("composer draft storage", () => {
|
||||
const store = new ComposerDraftStore();
|
||||
store.set(key, draft, true);
|
||||
expect(store.get(key)).toBe(draft);
|
||||
expect(new ComposerDraftStore().get(key, true)).toEqual({ ...draft, files: [] });
|
||||
expect(new ComposerDraftStore().get(key, true)).toEqual({ ...draft, attachments: [] });
|
||||
expect(new ComposerDraftStore().get("websocket:other", true)).toBeUndefined();
|
||||
expect(localStorage.getItem(storageKey)).not.toContain("files");
|
||||
expect(JSON.parse(localStorage.getItem(storageKey)!).attachments).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps the identity of an unchanged restored draft but advances it for edits", () => {
|
||||
const store = new ComposerDraftStore();
|
||||
store.set(key, draft, true);
|
||||
store.set(key, { ...draft, files: [...draft.files], sessionMentions: [...draft.sessionMentions] }, true);
|
||||
store.set(key, { ...draft, attachments: [...draft.attachments], sessionMentions: [...draft.sessionMentions] }, true);
|
||||
expect(store.get(key)).toBe(draft);
|
||||
const edited = { ...draft, text: "edited draft" };
|
||||
store.set(key, edited, true);
|
||||
@@ -39,6 +39,27 @@ describe("composer draft storage", () => {
|
||||
expect(store.get(key)).toBe(reverted);
|
||||
});
|
||||
|
||||
it("keeps mixed attachment order in memory and the local subsequence after reload", () => {
|
||||
const first = { path: "/project/first.png", name: "first.png", size: 8, mime: "image/png", kind: "image" as const, url: "" };
|
||||
const last = { ...first, path: "/project/last.png", name: "last.png" };
|
||||
const mixed = { ...draft, attachments: [first, draft.attachments[0], last] };
|
||||
const store = new ComposerDraftStore();
|
||||
store.set(key, mixed, true);
|
||||
store.set(key, { ...mixed, attachments: [...mixed.attachments] }, true);
|
||||
expect(store.get(key)).toBe(mixed);
|
||||
expect(new ComposerDraftStore().get(key, true)?.attachments).toEqual([first, last]);
|
||||
const reordered = { ...mixed, attachments: [last, draft.attachments[0], first] };
|
||||
store.set(key, reordered, true);
|
||||
expect(store.get(key)).toBe(reordered);
|
||||
expect(new ComposerDraftStore().get(key, true)?.attachments).toEqual([last, first]);
|
||||
});
|
||||
|
||||
it("reads local references already saved in v1 drafts", () => {
|
||||
const local = { path: "/project/previous.png", name: "previous.png", size: 8, mime: "image/png", kind: "image", url: "" };
|
||||
localStorage.setItem(storageKey, JSON.stringify({ text: "previous draft", quotedContext: null, sessionMentions: [], localAttachments: [local] }));
|
||||
expect(new ComposerDraftStore().get(key, true)?.attachments).toEqual([local]);
|
||||
});
|
||||
|
||||
it("requires explicit opt-in for both saving and restoring", () => {
|
||||
const store = new ComposerDraftStore();
|
||||
store.set(key, draft);
|
||||
@@ -52,7 +73,7 @@ describe("composer draft storage", () => {
|
||||
const store = new ComposerDraftStore();
|
||||
store.set(key, draft, true);
|
||||
store.set(key, { ...draft, text: "", quotedContext: null, sessionMentions: [] }, true);
|
||||
expect(store.get(key)?.files).toEqual(draft.files);
|
||||
expect(store.get(key)?.attachments).toEqual(draft.attachments);
|
||||
expect(new ComposerDraftStore().get(key, true)).toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -82,7 +103,7 @@ describe("composer draft storage", () => {
|
||||
localStorage.setItem(storageKey, JSON.stringify({
|
||||
...draft, sessionMentions: [null, { name: 42 }, ...draft.sessionMentions],
|
||||
}));
|
||||
expect(new ComposerDraftStore().get(key, true)).toEqual({ ...draft, files: [] });
|
||||
expect(new ComposerDraftStore().get(key, true)).toEqual({ ...draft, attachments: [] });
|
||||
});
|
||||
|
||||
it("keeps editing usable when storage is unavailable and removes stale saved text", () => {
|
||||
|
||||
Reference in new issue
Block a user