[Server] Move user files to trash on delete calls

This commit is contained in:
Chenlei Hu 2025-03-24 17:08:44 -04:00
parent eade1551bb
commit aefc6ffe5d
2 changed files with 11 additions and 2 deletions

View File

@ -1,4 +1,5 @@
from __future__ import annotations from __future__ import annotations
import json import json
import os import os
import re import re
@ -6,12 +7,15 @@ import uuid
import glob import glob
import shutil import shutil
import logging import logging
from typing import TypedDict
import send2trash
from aiohttp import web from aiohttp import web
from urllib import parse from urllib import parse
from comfy.cli_args import args from comfy.cli_args import args
import folder_paths import folder_paths
from .app_settings import AppSettings from .app_settings import AppSettings
from typing import TypedDict
default_user = "default" default_user = "default"
@ -274,7 +278,11 @@ class UserManager():
if not isinstance(path, str): if not isinstance(path, str):
return path return path
os.remove(path) try:
send2trash.send2trash(path)
except Exception as e:
logging.error(f"Error moving file to trash: {e}")
return web.Response(status=500, text="Failed to move file to trash")
return web.Response(status=204) return web.Response(status=204)

View File

@ -16,6 +16,7 @@ Pillow
scipy scipy
tqdm tqdm
psutil psutil
send2trash>=1.8.3
#non essential dependencies: #non essential dependencies:
kornia>=0.7.1 kornia>=0.7.1