From b8a8be5ae5bd03375ee3cbe542bb54015c52ceae Mon Sep 17 00:00:00 2001 From: Joel Mathew Thomas <90510078+joelmathewthomas@users.noreply.github.com> Date: Thu, 20 Mar 2025 00:19:52 +0530 Subject: [PATCH] remove /api/cleanup and /api/cleanupzip endpoints in favour of websocket handling cleanups --- api/api/tasks.py | 11 ----------- api/api/views.py | 37 +------------------------------------ 2 files changed, 1 insertion(+), 47 deletions(-) diff --git a/api/api/tasks.py b/api/api/tasks.py index 0c5cc54..f8955b2 100644 --- a/api/api/tasks.py +++ b/api/api/tasks.py @@ -142,16 +142,5 @@ def generate_spectrogram_task(file_path): spec_data_json = json.dumps(spec_db.tolist()) return True, spec_data_json, plot_data['sr'] - except Exception as e: - return False -@shared_task -def cleanup_task(file_path): - """Celery task to cleanup files""" - file_path = Path(file_path) - - # Cleanup - try: - shutil.rmtree(os.path.dirname(file_path)) - return True except Exception as e: return False \ No newline at end of file diff --git a/api/api/views.py b/api/api/views.py index c9ea3c0..1655b7d 100644 --- a/api/api/views.py +++ b/api/api/views.py @@ -13,7 +13,6 @@ from .tasks import resample_audio_task from .tasks import music_separation_task from .tasks import noisereduce_task from .tasks import generate_spectrogram_task -from .tasks import cleanup_task from freqsplit.input.format_checker import is_supported_format UPLOAD_DIR = "/tmp/freqsplit" @@ -220,38 +219,4 @@ def download_audio(request): zipf.write(file_path, arcname) # Stream the ZIP file - return FileResponse(open(zip_file_path, "rb"), as_attachment=True, filename=os.path.basename(zip_file_path)) - -@api_view(['POST']) -def cleanup(request): - """Handles file cleanup after pipeline processing""" - stat, result, status_code = get_audio_file_path(request, UPLOAD_DIR) - if stat == False: - return Response({"error": result}, status=status_code) - - # Call Celery task synchronously - task = cleanup_task.apply(args=(result,)) - - if task.get(): - return Response({"message": f"Successfully cleaned up files on the server"}, status=status.HTTP_200_OK) - else: - return Response({"error": "Failed to cleanup files on the server"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - -@api_view(['POST']) -def cleanup_zip(request): - """Handles cleanup of all zip files leftover by api/download""" - deleted_files = [] - - for file in os.listdir(UPLOAD_DIR): - if file.endswith(".zip"): - file_path = os.path.join(UPLOAD_DIR, file) - try: - os.remove(file_path) - deleted_files.append(file) - except Exception as e: - return Response({"message": f"Error deleting {file_path}: {e}"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - - if deleted_files: - return Response({"message": f"Deleted ZIP files: {deleted_files}"}, status=status.HTTP_200_OK) - else: - return Response({"message": "No ZIP files found to clean up."}, status=status.HTTP_200_OK) + return FileResponse(open(zip_file_path, "rb"), as_attachment=True, filename=os.path.basename(zip_file_path)) \ No newline at end of file