MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / destroy

Method destroy

apps/channels/api_views.py:2655–2679  ·  view source on GitHub ↗

Delete a logo and remove it from any channels using it

(self, request, *args, **kwargs)

Source from the content-addressed store, hash-verified

2653 return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
2654
2655 def destroy(self, request, *args, **kwargs):
2656 """Delete a logo and remove it from any channels using it"""
2657 logo = self.get_object()
2658 delete_file = request.query_params.get('delete_file', 'false').lower() == 'true'
2659
2660 # Check if it's a local file that should be deleted
2661 if delete_file and logo.url and logo.url.startswith('/data/logos'):
2662 try:
2663 if os.path.exists(logo.url):
2664 os.remove(logo.url)
2665 logger.info(f"Deleted local logo file: {logo.url}")
2666 except Exception as e:
2667 logger.error(f"Failed to delete logo file {logo.url}: {str(e)}")
2668 return Response(
2669 {"error": f"Failed to delete logo file: {str(e)}"},
2670 status=status.HTTP_500_INTERNAL_SERVER_ERROR
2671 )
2672
2673 # Instead of preventing deletion, remove the logo from channels
2674 if logo.channels.exists():
2675 channel_count = logo.channels.count()
2676 logo.channels.update(logo=None)
2677 logger.info(f"Removed logo {logo.name} from {channel_count} channels before deletion")
2678
2679 return super().destroy(request, *args, **kwargs)
2680
2681 @action(detail=False, methods=["post"])
2682 def upload(self, request):

Callers 2

destroyMethod · 0.45
destroyMethod · 0.45

Calls 3

getMethod · 0.45
existsMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected