fix(web): restore composer attachment uploads (#1313)

This commit is contained in:
Ananovo
2026-08-02 19:49:03 +08:00
committed by GitHub
parent 5b91504263
commit f018c6027b
4 changed files with 22 additions and 3 deletions
+8 -1
View File
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
describe('attachmentAdapter restored uploads', () => {
describe('attachmentAdapter', () => {
beforeEach(() => {
vi.stubGlobal('indexedDB', undefined)
vi.resetModules()
@@ -10,6 +10,13 @@ describe('attachmentAdapter restored uploads', () => {
vi.unstubAllGlobals()
})
it('uses the assistant-ui wildcard sentinel so all files reach the adapter', async () => {
const { createAttachmentAdapter } = await import('./attachmentAdapter')
const adapter = createAttachmentAdapter({} as never, 'session-1')
expect(adapter.accept).toBe('*')
})
it('restores an uploaded draft without uploading it again', async () => {
const drafts = await import('./composer-attachment-drafts')
const { createAttachmentAdapter } = await import('./attachmentAdapter')
+4 -1
View File
@@ -26,7 +26,10 @@ export function createAttachmentAdapter(api: ApiClient, sessionId: string): Atta
}
return {
accept: '*/*',
// assistant-ui uses the exact "*" sentinel for an allow-all adapter.
// "*/*" is forwarded to MIME matching and rejects every file before
// this adapter's add() method can run.
accept: '*',
async *add({ file }): AsyncGenerator<PendingAttachment> {
const restored = getRestoredUploadMetadata(file)
@@ -24,6 +24,12 @@ describe('hubAttachmentFromRestoredDraft', () => {
})
describe('createScratchlistAttachmentAdapter', () => {
it('uses the assistant-ui wildcard sentinel so all files reach the adapter', () => {
const adapter = createScratchlistAttachmentAdapter({} as never, 'session-1')
expect(adapter.accept).toBe('*')
})
it('reuses restored hub path without re-uploading', async () => {
const drafts = await import('./composer-attachment-drafts')
const hubId = 'a1b2c3d4-e5f6-4789-a012-3456789abcde'
+4 -1
View File
@@ -44,7 +44,10 @@ export function createScratchlistAttachmentAdapter(api: ApiClient, sessionId: st
const cancelledAttachmentIds = new Set<string>()
return {
accept: '*/*',
// assistant-ui uses the exact "*" sentinel for an allow-all adapter.
// "*/*" is forwarded to MIME matching and rejects every file before
// this adapter's add() method can run.
accept: '*',
async *add({ file }): AsyncGenerator<PendingAttachment> {
const contentType = file.type || 'application/octet-stream'