image url

This commit is contained in:
Desktop
2025-11-12 10:46:01 +05:00
parent a61471c34a
commit 1a51e6bc39
3 changed files with 142 additions and 84 deletions

View File

@@ -395,39 +395,12 @@ class ImagesViewSet(SiteSectorModelViewSet):
file_path = image.image_path
# Verify file exists - if not, try alternative locations
# Verify file exists at the saved path
if not os.path.exists(file_path):
logger.warning(f"[serve_image_file] Image {pk} - File not found at saved path: {file_path}, trying alternative locations...")
# Try alternative locations based on the filename
filename = os.path.basename(file_path)
alternative_paths = [
'/data/app/igny8/frontend/public/images/ai-images/' + filename, # Primary location (web-accessible)
'/data/app/igny8/images/' + filename, # Secondary location
'/data/app/images/' + filename, # Fallback location
]
# Try each alternative path
found = False
for alt_path in alternative_paths:
if os.path.exists(alt_path):
file_path = alt_path
logger.info(f"[serve_image_file] Image {pk} - Found file at alternative location: {file_path}")
# Update database with correct path
try:
image.image_path = file_path
image.save(update_fields=['image_path'])
logger.info(f"[serve_image_file] Image {pk} - Updated database with correct path: {file_path}")
except Exception as update_error:
logger.warning(f"[serve_image_file] Image {pk} - Failed to update database path: {update_error}")
found = True
break
if not found:
logger.error(f"[serve_image_file] Image {pk} - File not found in any location. Tried: {[file_path] + alternative_paths}")
return Response({
'error': f'Image file not found at: {file_path} (also checked alternative locations)'
}, status=status.HTTP_404_NOT_FOUND)
logger.error(f"[serve_image_file] Image {pk} - File not found at saved path: {file_path}")
return Response({
'error': f'Image file not found at: {file_path}'
}, status=status.HTTP_404_NOT_FOUND)
# Check if file is readable
if not os.access(file_path, os.R_OK):