This commit is contained in:
Desktop
2025-11-12 10:57:34 +05:00
parent 8496043258
commit f90979a2b0
2 changed files with 22 additions and 5 deletions

7
.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
# AI Generated Images - Do not commit generated images
frontend/public/images/ai-images/
**/ai-images/
# Also ignore in dist/build output
frontend/dist/images/ai-images/

View File

@@ -25,6 +25,16 @@ interface ContentImageCellProps {
export default function ContentImageCell({ image, maxPromptLength = 100 }: ContentImageCellProps) { export default function ContentImageCell({ image, maxPromptLength = 100 }: ContentImageCellProps) {
const [showFullPrompt, setShowFullPrompt] = useState(false); const [showFullPrompt, setShowFullPrompt] = useState(false);
// Check if image_path is a valid local file path (not a URL)
const isValidLocalPath = (imagePath: string): boolean => {
// Reject URLs (http:// or https://)
if (imagePath.startsWith('http://') || imagePath.startsWith('https://')) {
return false;
}
// Must contain 'ai-images' to be a valid local path
return imagePath.includes('ai-images');
};
// Convert local file path to web-accessible URL // Convert local file path to web-accessible URL
const getLocalImageUrl = (imagePath: string): string => { const getLocalImageUrl = (imagePath: string): string => {
// If path contains 'ai-images', convert to web URL // If path contains 'ai-images', convert to web URL
@@ -97,15 +107,15 @@ export default function ContentImageCell({ image, maxPromptLength = 100 }: Conte
{image.status === 'generated' && ( {image.status === 'generated' && (
<div className="space-y-1"> <div className="space-y-1">
{/* Always load from image_path - no fallback */} {/* Only use image_path if it's a valid local file path (not a URL) */}
{image.image_path && image.image_path.trim() ? ( {image.image_path && image.image_path.trim() && isValidLocalPath(image.image_path) ? (
<> <>
<img <img
src={getLocalImageUrl(image.image_path)} src={getLocalImageUrl(image.image_path)}
alt={prompt || 'Generated image'} alt={prompt || 'Generated image'}
className="w-full h-24 object-cover rounded border border-gray-300 dark:border-gray-600" className="w-full h-24 object-cover rounded border border-gray-300 dark:border-gray-600"
onError={(e) => { onError={(e) => {
// Show error placeholder if local image fails (no fallback to image_url) // Show empty placeholder if local image fails to load
const target = e.target as HTMLImageElement; const target = e.target as HTMLImageElement;
target.style.display = 'none'; target.style.display = 'none';
const parent = target.parentElement; const parent = target.parentElement;
@@ -131,8 +141,8 @@ export default function ContentImageCell({ image, maxPromptLength = 100 }: Conte
)} )}
</> </>
) : ( ) : (
<div className="w-full h-24 bg-yellow-100 dark:bg-yellow-900/20 rounded border border-yellow-300 dark:border-yellow-700 flex items-center justify-center"> <div className="w-full h-24 bg-gray-200 dark:bg-gray-700 rounded border-2 border-dashed border-gray-300 dark:border-gray-600 flex items-center justify-center">
<p className="text-xs text-yellow-700 dark:text-yellow-400">No image available</p> <p className="text-xs text-gray-500 dark:text-gray-400">No image available</p>
</div> </div>
)} )}
</div> </div>