Enhance image processing and error handling in AICore and tasks
- Improved response parsing in AICore to handle both array and dictionary formats, including detailed error logging. - Updated image directory handling in tasks to prioritize web-accessible paths for image storage, with robust fallback mechanisms. - Adjusted image URL generation in serializers and frontend components to support new directory structure and ensure proper accessibility.
This commit is contained in:
@@ -172,10 +172,19 @@ class ContentImageSerializer(serializers.ModelSerializer):
|
||||
def get_image_url(self, obj):
|
||||
"""
|
||||
Return proper HTTP URL for image.
|
||||
Priority: If image_path exists, return file endpoint URL, otherwise return image_url (API URL).
|
||||
Priority: If image_path exists and is in ai-images folder, return web URL,
|
||||
otherwise return file endpoint URL or image_url (API URL).
|
||||
"""
|
||||
if obj.image_path:
|
||||
# Return file endpoint URL for locally saved images
|
||||
# Check if path is in ai-images folder (web-accessible)
|
||||
if 'ai-images' in obj.image_path:
|
||||
# Extract filename from path
|
||||
filename = obj.image_path.split('ai-images/')[-1] if 'ai-images/' in obj.image_path else obj.image_path.split('ai-images\\')[-1]
|
||||
if filename:
|
||||
# Return web-accessible URL (like /images/logo/logo.svg)
|
||||
return f'/images/ai-images/{filename}'
|
||||
|
||||
# For other local paths, use file endpoint
|
||||
request = self.context.get('request')
|
||||
if request:
|
||||
# Build absolute URL for file endpoint
|
||||
|
||||
Reference in New Issue
Block a user