(imageContexts: ImageContext[])
| 16 | } |
| 17 | |
| 18 | export async function buildImagePayload(imageContexts: ImageContext[]): Promise<ImagePayload | undefined> { |
| 19 | if (imageContexts.length === 0) { |
| 20 | return undefined; |
| 21 | } |
| 22 | |
| 23 | const clipboardImages = imageContexts.filter(ctx => !ctx.isLocal && ctx.dataUrl); |
| 24 | const uploadedImagePaths = new Map<string, string>(); |
| 25 | |
| 26 | if (clipboardImages.length > 0) { |
| 27 | const uploadResults = await api.invoke<Array<{ id: string; image_path?: string | null }>>( |
| 28 | 'upload_image_contexts', |
| 29 | { |
| 30 | request: { |
| 31 | images: clipboardImages.map(ctx => ({ |
| 32 | id: ctx.id, |
| 33 | image_path: ctx.imagePath || null, |
| 34 | data_url: ctx.dataUrl || null, |
| 35 | mime_type: ctx.mimeType, |
| 36 | image_name: ctx.imageName, |
| 37 | file_size: ctx.fileSize, |
| 38 | width: ctx.width || null, |
| 39 | height: ctx.height || null, |
| 40 | source: ctx.source, |
| 41 | })), |
| 42 | }, |
| 43 | } |
| 44 | ); |
| 45 | |
| 46 | for (const result of uploadResults) { |
| 47 | if (result.image_path) { |
| 48 | uploadedImagePaths.set(result.id, result.image_path); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return { |
| 54 | imageContexts: imageContexts.map(ctx => ({ |
| 55 | id: ctx.id, |
| 56 | image_path: ctx.isLocal ? ctx.imagePath : uploadedImagePaths.get(ctx.id), |
| 57 | data_url: undefined, |
| 58 | mime_type: ctx.mimeType, |
| 59 | metadata: { |
| 60 | name: ctx.imageName, |
| 61 | width: ctx.width, |
| 62 | height: ctx.height, |
| 63 | file_size: ctx.fileSize, |
| 64 | source: ctx.source, |
| 65 | }, |
| 66 | })), |
| 67 | imageDisplayData: imageContexts.map(ctx => ({ |
| 68 | id: ctx.id, |
| 69 | name: ctx.imageName || 'Image', |
| 70 | dataUrl: ctx.dataUrl, |
| 71 | imagePath: ctx.isLocal ? ctx.imagePath : uploadedImagePaths.get(ctx.id), |
| 72 | mimeType: ctx.mimeType, |
| 73 | })), |
| 74 | }; |
| 75 | } |
no test coverage detected