From e8168f4e99887be6b8dc9587890c199b2fc7a26c Mon Sep 17 00:00:00 2001 From: freddyaboulton Date: Wed, 14 Feb 2024 10:38:41 -0500 Subject: [PATCH 1/4] Improve File route --- gradio/routes.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gradio/routes.py b/gradio/routes.py index 45af1a2bb644a..1c9564e4b0627 100644 --- a/gradio/routes.py +++ b/gradio/routes.py @@ -420,7 +420,7 @@ async def reverse_proxy(url_path: str): @app.head("/file={path_or_url:path}", dependencies=[Depends(login_check)]) @app.get("/file={path_or_url:path}", dependencies=[Depends(login_check)]) - async def file(path_or_url: str, request: fastapi.Request): + def file(path_or_url: str, request: fastapi.Request): blocks = app.get_blocks() if client_utils.is_http_url_like(path_or_url): return RedirectResponse( @@ -437,7 +437,11 @@ async def file(path_or_url: str, request: fastapi.Request): if in_blocklist or is_dir: raise HTTPException(403, f"File not allowed: {path_or_url}.") - created_by_app = str(abs_path) in set().union(*blocks.temp_file_sets) + created_by_app = False + for temp_file_set in blocks.temp_file_sets: + if abs_path in temp_file_set: + created_by_app = True + break in_allowlist = any( utils.is_in_or_equal(abs_path, allowed_path) for allowed_path in blocks.allowed_paths @@ -512,7 +516,7 @@ def stream_wrapper(): @app.get("/file/{path:path}", dependencies=[Depends(login_check)]) async def file_deprecated(path: str, request: fastapi.Request): - return await file(path, request) + return file(path, request) @app.post("/reset/") @app.post("/reset") From aabb08191a7d94d2a1e9ff87b0d3c3987cd519c5 Mon Sep 17 00:00:00 2001 From: freddyaboulton Date: Wed, 14 Feb 2024 10:40:16 -0500 Subject: [PATCH 2/4] file route fix --- gradio/routes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradio/routes.py b/gradio/routes.py index 1c9564e4b0627..a63040caba21d 100644 --- a/gradio/routes.py +++ b/gradio/routes.py @@ -420,7 +420,7 @@ async def reverse_proxy(url_path: str): @app.head("/file={path_or_url:path}", dependencies=[Depends(login_check)]) @app.get("/file={path_or_url:path}", dependencies=[Depends(login_check)]) - def file(path_or_url: str, request: fastapi.Request): + async def file(path_or_url: str, request: fastapi.Request): blocks = app.get_blocks() if client_utils.is_http_url_like(path_or_url): return RedirectResponse( @@ -516,7 +516,7 @@ def stream_wrapper(): @app.get("/file/{path:path}", dependencies=[Depends(login_check)]) async def file_deprecated(path: str, request: fastapi.Request): - return file(path, request) + return await file(path, request) @app.post("/reset/") @app.post("/reset") From 824f605a2b3635afcb6ba45f460bd4eaf01689ae Mon Sep 17 00:00:00 2001 From: gradio-pr-bot Date: Wed, 14 Feb 2024 15:55:48 +0000 Subject: [PATCH 3/4] add changeset --- .changeset/evil-lamps-refuse.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/evil-lamps-refuse.md diff --git a/.changeset/evil-lamps-refuse.md b/.changeset/evil-lamps-refuse.md new file mode 100644 index 0000000000000..cca2570695403 --- /dev/null +++ b/.changeset/evil-lamps-refuse.md @@ -0,0 +1,5 @@ +--- +"gradio": minor +--- + +feat:WIP: Optimize /file route From 0950dd0d6f1611c6d53b8560752b79a70adabf55 Mon Sep 17 00:00:00 2001 From: gradio-pr-bot Date: Thu, 15 Feb 2024 20:56:30 +0000 Subject: [PATCH 4/4] add changeset --- .changeset/evil-lamps-refuse.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/evil-lamps-refuse.md b/.changeset/evil-lamps-refuse.md index cca2570695403..a345e27815071 100644 --- a/.changeset/evil-lamps-refuse.md +++ b/.changeset/evil-lamps-refuse.md @@ -1,5 +1,5 @@ --- -"gradio": minor +"gradio": patch --- feat:WIP: Optimize /file route