@@ -733,48 +733,45 @@ def set_thumbnail_from_bbox(self, request, resource_id, *args, **kwargs):
733733 methods = ["post" ],
734734 permission_classes = [IsAuthenticated , UserHasPerms (perms_dict = {"default" : {"POST" : ["base.add_resourcebase" ]}})],
735735 )
736-
737736 def delete_thumbnail (self , request , resource_id , * args , ** kwargs ):
738-
737+
739738 try :
740739 resource = ResourceBase .objects .get (id = int (resource_id ))
741740
742- if not isinstance (resource .get_real_instance (), (Dataset , Map )):
743- return Response (
744- {"message" : "Endpoint only available for Datasets and Maps." , "success" : False },
745- status = status .HTTP_400_BAD_REQUEST
746- )
747-
748741 # Check if thumbnail exists
749742 if not resource .thumbnail_url :
750743 return Response (
751744 {"message" : "The thumbnail URL field is already empty." , "success" : False },
752- status = status .HTTP_200_OK
745+ status = status .HTTP_200_OK ,
753746 )
754747
755- # request_body = request.data if request.data else json.loads(request.body)
756748 thumb_parsed_url = urlparse (resource .thumbnail_url )
757749 thumb_filename = thumb_parsed_url .path .split ("/" )[- 1 ]
750+ if thumb_filename .rsplit ("." )[- 1 ] not in ["png" , "jpeg" , "jpg" ]:
751+ return Response (
752+ "The file name is not a valid image with a format png, jpeg or jpg" ,
753+ status = status .HTTP_400_BAD_REQUEST ,
754+ )
755+
758756 # remove_thumb will call the thumb_path function and then the storage_manager which will delete it
759757 remove_thumb (thumb_filename )
760758
761- # Clear the field in the database
762- resource .thumbnail_url = ""
763- resource .save (update_fields = ["thumbnail_url" ])
759+ # Clear the related fields in the database
760+ resource .thumbnail_url = None
761+ resource .thumbnail_path = None
762+ resource .save (update_fields = ["thumbnail_url" , "thumbnail_path" ])
764763
765- return Response (
766- {"message" : "Thumbnail deleted successfully." , "success" : True }, status = status .HTTP_200_OK
767- )
764+ return Response ({"message" : "Thumbnail deleted successfully." , "success" : True }, status = status .HTTP_200_OK )
768765
769766 except ResourceBase .DoesNotExist :
770767 return Response ({"message" : "Resource not found." , "success" : False }, status = status .HTTP_404_NOT_FOUND )
771- except ValueError :
772- return Response ({"message" : "Invalid resource ID." , "success" : False }, status = status .HTTP_400_BAD_REQUEST )
773768 except Exception as e :
774769 logger .error (e )
775- return Response ({"message" : "Unexpected error occurred." , "success" : False }, status = status .HTTP_500_INTERNAL_SERVER_ERROR )
770+ return Response (
771+ {"message" : "Unexpected error occurred." , "success" : False },
772+ status = status .HTTP_500_INTERNAL_SERVER_ERROR ,
773+ )
776774
777-
778775 @extend_schema (
779776 methods = ["post" ], responses = {200 }, description = "Instructs the Async dispatcher to execute a 'INGEST' operation."
780777 )
0 commit comments