remove file_dir on websocket disconnect

This commit is contained in:
Joel Mathew Thomas
2025-03-20 00:12:10 +05:30
parent 1cb3a1f197
commit a5705fffd0
+13 -1
View File
@@ -1,7 +1,12 @@
# api/consumers.py
import json
import os
import shutil
from pathlib import Path
from channels.generic.websocket import WebsocketConsumer
UPLOAD_DIR = Path("/tmp/freqsplit")
class MediaConsumer(WebsocketConsumer):
def connect(self):
self.accept()
@@ -26,4 +31,11 @@ class MediaConsumer(WebsocketConsumer):
def disconnect(self, close_code):
print("Disconnected from Websocket")
print("Stored file UUIDs:", self.file_uuid)
print("Stored file UUIDs:", self.file_uuid)
for file_uuid in self.file_uuid:
dir_path = os.path.join(UPLOAD_DIR, file_uuid);
try:
if os.path.exists(dir_path):
shutil.rmtree(dir_path)
except Exception as e:
print(f"Error: Failed to cleanup {dir_path}: {e}")