remove /api/cleanup and /api/cleanupzip endpoints in favour of websocket handling cleanups

This commit is contained in:
Joel Mathew Thomas
2025-03-20 00:19:52 +05:30
parent 397e4f2c99
commit b8a8be5ae5
2 changed files with 1 additions and 47 deletions
-11
View File
@@ -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
+1 -36
View File
@@ -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))