remove file_dir on websocket disconnect
This commit is contained in:
@@ -1,7 +1,12 @@
|
|||||||
# api/consumers.py
|
# api/consumers.py
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
from channels.generic.websocket import WebsocketConsumer
|
from channels.generic.websocket import WebsocketConsumer
|
||||||
|
|
||||||
|
UPLOAD_DIR = Path("/tmp/freqsplit")
|
||||||
|
|
||||||
class MediaConsumer(WebsocketConsumer):
|
class MediaConsumer(WebsocketConsumer):
|
||||||
def connect(self):
|
def connect(self):
|
||||||
self.accept()
|
self.accept()
|
||||||
@@ -27,3 +32,10 @@ class MediaConsumer(WebsocketConsumer):
|
|||||||
def disconnect(self, close_code):
|
def disconnect(self, close_code):
|
||||||
print("Disconnected from Websocket")
|
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}")
|
||||||
Reference in New Issue
Block a user