mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-01-23 02:35:14 +00:00
Fixes being unable to add a new logo via URL.
This commit is contained in:
parent
7eef45f1c0
commit
1475ca70ab
5 changed files with 36 additions and 20 deletions
|
|
@ -1122,7 +1122,7 @@ class CleanupUnusedLogosAPIView(APIView):
|
|||
def post(self, request):
|
||||
"""Delete all logos with no channel associations"""
|
||||
delete_files = request.data.get("delete_files", False)
|
||||
|
||||
|
||||
unused_logos = Logo.objects.filter(channels__isnull=True)
|
||||
deleted_count = unused_logos.count()
|
||||
logo_names = list(unused_logos.values_list('name', flat=True))
|
||||
|
|
@ -1204,7 +1204,13 @@ class LogoViewSet(viewsets.ModelViewSet):
|
|||
|
||||
def update(self, request, *args, **kwargs):
|
||||
"""Update an existing logo"""
|
||||
return super().update(request, *args, **kwargs)
|
||||
partial = kwargs.pop('partial', False)
|
||||
instance = self.get_object()
|
||||
serializer = self.get_serializer(instance, data=request.data, partial=partial)
|
||||
if serializer.is_valid():
|
||||
logo = serializer.save()
|
||||
return Response(self.get_serializer(logo).data)
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
"""Delete a logo and remove it from any channels using it"""
|
||||
|
|
|
|||
|
|
@ -38,6 +38,17 @@ class LogoSerializer(serializers.ModelSerializer):
|
|||
|
||||
return value
|
||||
|
||||
def create(self, validated_data):
|
||||
"""Handle logo creation with proper URL validation"""
|
||||
return Logo.objects.create(**validated_data)
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
"""Handle logo updates"""
|
||||
for attr, value in validated_data.items():
|
||||
setattr(instance, attr, value)
|
||||
instance.save()
|
||||
return instance
|
||||
|
||||
def get_cache_url(self, obj):
|
||||
# return f"/api/channels/logos/{obj.id}/cache/"
|
||||
request = self.context.get("request")
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ def json_success_response(data=None, status=200):
|
|||
|
||||
def validate_logo_file(file):
|
||||
"""Validate uploaded logo file size and MIME type."""
|
||||
valid_mime_types = ["image/jpeg", "image/png", "image/gif", "image/webp"]
|
||||
valid_mime_types = ["image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml"]
|
||||
if file.content_type not in valid_mime_types:
|
||||
raise ValidationError("Unsupported file type. Allowed types: JPEG, PNG, GIF, WebP.")
|
||||
if file.size > 5 * 1024 * 1024: # Increased to 5MB
|
||||
raise ValidationError("Unsupported file type. Allowed types: JPEG, PNG, GIF, WebP, SVG.")
|
||||
if file.size > 5 * 1024 * 1024: # 5MB
|
||||
raise ValidationError("File too large. Max 5MB.")
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1299,9 +1299,17 @@ export default class API {
|
|||
|
||||
static async createLogo(values) {
|
||||
try {
|
||||
// Use FormData for logo creation to match backend expectations
|
||||
const formData = new FormData();
|
||||
for (const [key, value] of Object.entries(values)) {
|
||||
if (value !== null && value !== undefined) {
|
||||
formData.append(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
const response = await request(`${host}/api/channels/logos/`, {
|
||||
method: 'POST',
|
||||
body: values,
|
||||
body: formData,
|
||||
});
|
||||
|
||||
useChannelsStore.getState().addLogo(response);
|
||||
|
|
@ -1314,19 +1322,9 @@ export default class API {
|
|||
|
||||
static async updateLogo(id, values) {
|
||||
try {
|
||||
// Convert values to FormData for the multipart/form-data content type
|
||||
const formData = new FormData();
|
||||
|
||||
// Add each field to the form data
|
||||
Object.keys(values).forEach(key => {
|
||||
if (values[key] !== null && values[key] !== undefined) {
|
||||
formData.append(key, values[key]);
|
||||
}
|
||||
});
|
||||
|
||||
const response = await request(`${host}/api/channels/logos/${id}/`, {
|
||||
method: 'PUT',
|
||||
body: formData, // Send as FormData instead of JSON
|
||||
body: values, // This will be converted to JSON in the request function
|
||||
});
|
||||
|
||||
useChannelsStore.getState().updateLogo(response);
|
||||
|
|
|
|||
|
|
@ -206,9 +206,10 @@ const LogoForm = ({ logo = null, isOpen, onClose }) => {
|
|||
</Text>
|
||||
<Dropzone
|
||||
onDrop={handleFileUpload}
|
||||
accept={['image/png', 'image/jpeg', 'image/gif', 'image/webp']}
|
||||
maxFiles={1}
|
||||
loading={uploading}
|
||||
accept={{ "image/*": [".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg"] }}
|
||||
multiple={false}
|
||||
maxSize={5 * 1024 * 1024} // 5MB limit
|
||||
>
|
||||
<Group justify="center" gap="xl" mih={120} style={{ pointerEvents: 'none' }}>
|
||||
<Dropzone.Accept>
|
||||
|
|
@ -226,7 +227,7 @@ const LogoForm = ({ logo = null, isOpen, onClose }) => {
|
|||
Drag image here or click to select
|
||||
</Text>
|
||||
<Text size="sm" color="dimmed" inline mt={7}>
|
||||
Supports PNG, JPEG, GIF, WebP files
|
||||
Supports PNG, JPEG, GIF, WebP, SVG files
|
||||
</Text>
|
||||
</div>
|
||||
</Group>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue