Skip to content

Commit

Permalink
Remove empty spaces in user_manager.py (comfyanonymous#4917)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Sep 14, 2024
1 parent b3ce8fb commit 369a6dd
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions app/user_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from aiohttp import web
from urllib import parse
from comfy.cli_args import args
import folder_paths
import folder_paths
from .app_settings import AppSettings

default_user = "default"
Expand Down Expand Up @@ -65,7 +65,7 @@ def get_request_user_filepath(self, request, file, type="userdata", create_dir=T
# Check if filename is url encoded
if "%" in file:
file = parse.unquote(file)

# prevent leaving /{type}/{user}
path = os.path.abspath(os.path.join(user_root, file))
if os.path.commonpath((user_root, path)) != user_root:
Expand Down Expand Up @@ -165,30 +165,30 @@ def get_user_data_path(request, check_exists = False, param = "file"):
file = request.match_info.get(param, None)
if not file:
return web.Response(status=400)

path = self.get_request_user_filepath(request, file)
if not path:
return web.Response(status=403)

if check_exists and not os.path.exists(path):
return web.Response(status=404)

return path

@routes.get("/userdata/{file}")
async def getuserdata(request):
path = get_user_data_path(request, check_exists=True)
if not isinstance(path, str):
return path

return web.FileResponse(path)

@routes.post("/userdata/{file}")
async def post_userdata(request):
path = get_user_data_path(request)
if not isinstance(path, str):
return path

overwrite = request.query["overwrite"] != "false"
if not overwrite and os.path.exists(path):
return web.Response(status=409)
Expand All @@ -197,7 +197,7 @@ async def post_userdata(request):

with open(path, "wb") as f:
f.write(body)

resp = os.path.relpath(path, self.get_request_user_filepath(request, None))
return web.json_response(resp)

Expand All @@ -208,25 +208,25 @@ async def delete_userdata(request):
return path

os.remove(path)

return web.Response(status=204)

@routes.post("/userdata/{file}/move/{dest}")
async def move_userdata(request):
source = get_user_data_path(request, check_exists=True)
if not isinstance(source, str):
return source

dest = get_user_data_path(request, check_exists=False, param="dest")
if not isinstance(source, str):
return dest

overwrite = request.query["overwrite"] != "false"
if not overwrite and os.path.exists(dest):
return web.Response(status=409)

print(f"moving '{source}' -> '{dest}'")
shutil.move(source, dest)

resp = os.path.relpath(dest, self.get_request_user_filepath(request, None))
return web.json_response(resp)

0 comments on commit 369a6dd

Please sign in to comment.