mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 12:51:09 -05:00
Refactor user account system and remove moderation integration
- Remove first_name and last_name fields from User model - Add user deletion and social provider services - Restructure auth serializers into separate directory - Update avatar upload functionality and API endpoints - Remove django-moderation integration documentation - Add mandatory compliance enforcement rules - Update frontend documentation with API usage examples
This commit is contained in:
@@ -857,17 +857,54 @@ class MarkNotificationsReadSerializer(serializers.Serializer):
|
||||
)
|
||||
]
|
||||
)
|
||||
class AvatarUploadSerializer(serializers.ModelSerializer):
|
||||
class AvatarUploadSerializer(serializers.Serializer):
|
||||
"""Serializer for uploading user avatar."""
|
||||
|
||||
class Meta:
|
||||
model = UserProfile
|
||||
fields = ["avatar"]
|
||||
# Use FileField instead of ImageField to bypass Django's image validation
|
||||
avatar = serializers.FileField()
|
||||
|
||||
def validate_avatar(self, value):
|
||||
"""Validate avatar file."""
|
||||
if value:
|
||||
# Add any avatar-specific validation here
|
||||
# The CloudflareImagesField will handle the upload
|
||||
if not value:
|
||||
raise serializers.ValidationError("No file provided")
|
||||
|
||||
# Check file size constraints (max 10MB for Cloudflare Images)
|
||||
if hasattr(value, 'size') and value.size > 10 * 1024 * 1024:
|
||||
raise serializers.ValidationError(
|
||||
"Image file too large. Maximum size is 10MB.")
|
||||
|
||||
# Try to validate with PIL
|
||||
try:
|
||||
from PIL import Image
|
||||
import io
|
||||
|
||||
value.seek(0)
|
||||
image_data = value.read()
|
||||
value.seek(0) # Reset for later use
|
||||
|
||||
if len(image_data) == 0:
|
||||
raise serializers.ValidationError("File appears to be empty")
|
||||
|
||||
# Try to open with PIL
|
||||
image = Image.open(io.BytesIO(image_data))
|
||||
|
||||
# Verify it's a valid image
|
||||
image.verify()
|
||||
|
||||
# Check image dimensions (max 12,000x12,000 for Cloudflare Images)
|
||||
if image.size[0] > 12000 or image.size[1] > 12000:
|
||||
raise serializers.ValidationError(
|
||||
"Image dimensions too large. Maximum is 12,000x12,000 pixels.")
|
||||
|
||||
# Check if it's a supported format
|
||||
if image.format not in ['JPEG', 'PNG', 'GIF', 'WEBP']:
|
||||
raise serializers.ValidationError(
|
||||
f"Unsupported image format: {image.format}. Supported formats: JPEG, PNG, GIF, WebP.")
|
||||
|
||||
except serializers.ValidationError:
|
||||
raise # Re-raise validation errors
|
||||
except Exception as e:
|
||||
# PIL validation failed, but let Cloudflare Images try to process it
|
||||
pass
|
||||
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user