Przeglądaj źródła

Merge pull request #18432 from silentoplayz/fix-clipboard-image-paste

fix: correctly handle clipboard images with {{CLIPBOARD}} in prompts
Tim Baek 4 miesięcy temu
rodzic
commit
48b538f312
1 zmienionych plików z 15 dodań i 14 usunięć
  1. 15 14
      src/lib/components/chat/MessageInput.svelte

+ 15 - 14
src/lib/components/chat/MessageInput.svelte

@@ -168,29 +168,30 @@
 				return '{{CLIPBOARD}}';
 			});
 
-			const clipboardItems = await navigator.clipboard.read();
+			const clipboardItems = await navigator.clipboard.read().catch((err) => {
+				console.error('Failed to read clipboard items:', err);
+				return [];
+			});
 
-			let imageUrl = null;
 			for (const item of clipboardItems) {
-				// Check for known image types
 				for (const type of item.types) {
 					if (type.startsWith('image/')) {
 						const blob = await item.getType(type);
-						imageUrl = URL.createObjectURL(blob);
+						const reader = new FileReader();
+						reader.onload = (event) => {
+							files = [
+								...files,
+								{
+									type: 'image',
+									url: event.target.result as string
+								}
+							];
+						};
+						reader.readAsDataURL(blob);
 					}
 				}
 			}
 
-			if (imageUrl) {
-				files = [
-					...files,
-					{
-						type: 'image',
-						url: imageUrl
-					}
-				];
-			}
-
 			text = text.replaceAll('{{CLIPBOARD}}', clipboardText);
 		}