mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
fix(web): restore composer attachment uploads (#1313)
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user