refactor: Store pasted images in memory as base64 data URLs

- Remove save_clipboard_image and cleanup_temp_images backend commands
- Update FloatingPromptInput to store pasted images as data URLs in the prompt
- Update ImagePreview component to handle both file paths and data URLs
- Update extractImagePaths to properly handle quoted data URLs
- Update handleRemoveImage to handle data URL removal

This eliminates file system operations for pasted images and stores them directly
in the prompt as base64 data URLs (e.g., @"data:image/png;base64,...").
Images are now fully self-contained within the session without creating temp files.
This commit is contained in:
Vivek R
2025-07-06 16:45:12 +05:30
parent 2009601dd9
commit 4cd104b1dd
5 changed files with 52 additions and 145 deletions

View File

@@ -56,6 +56,16 @@ export const ImagePreview: React.FC<ImagePreviewProps> = ({
onRemove(index);
};
// Helper to get the image source - handles both file paths and data URLs
const getImageSrc = (imagePath: string): string => {
// If it's already a data URL, return as-is
if (imagePath.startsWith('data:')) {
return imagePath;
}
// Otherwise, convert the file path
return convertFileSrc(imagePath);
};
if (displayImages.length === 0) return null;
return (
@@ -83,7 +93,7 @@ export const ImagePreview: React.FC<ImagePreviewProps> = ({
</div>
) : (
<img
src={convertFileSrc(imagePath)}
src={getImageSrc(imagePath)}
alt={`Preview ${index + 1}`}
className="w-full h-full object-cover"
onError={() => handleImageError(index)}
@@ -131,7 +141,7 @@ export const ImagePreview: React.FC<ImagePreviewProps> = ({
{selectedImageIndex !== null && (
<div className="relative w-full h-full flex items-center justify-center p-4">
<img
src={convertFileSrc(displayImages[selectedImageIndex])}
src={getImageSrc(displayImages[selectedImageIndex])}
alt={`Full preview ${selectedImageIndex + 1}`}
className="max-w-full max-h-full object-contain"
onError={() => handleImageError(selectedImageIndex)}
@@ -164,4 +174,4 @@ export const ImagePreview: React.FC<ImagePreviewProps> = ({
</Dialog>
</>
);
};
};