1234
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 164 KiB |
@@ -171,29 +171,9 @@ class ContentImageSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
def get_image_url(self, obj):
|
def get_image_url(self, obj):
|
||||||
"""
|
"""
|
||||||
Return proper HTTP URL for image.
|
Return original image_url from database (Runware/OpenAI URL).
|
||||||
Priority: If image_path exists and is in ai-images folder, return web URL,
|
No transformation - returns the exact value stored in image_url field.
|
||||||
otherwise return file endpoint URL or image_url (API URL).
|
|
||||||
"""
|
"""
|
||||||
if obj.image_path:
|
|
||||||
# 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
|
|
||||||
file_url = request.build_absolute_uri(f'/api/v1/writer/images/{obj.id}/file/')
|
|
||||||
return file_url
|
|
||||||
else:
|
|
||||||
# Fallback: return relative URL if no request context
|
|
||||||
return f'/api/v1/writer/images/{obj.id}/file/'
|
|
||||||
# Fallback to original image_url (API URL) if no local path
|
|
||||||
return obj.image_url
|
return obj.image_url
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user