From 6e06fb051ab67cd587a9961132c37047b5e6d06d Mon Sep 17 00:00:00 2001 From: Physton Date: Wed, 27 Sep 2023 00:45:38 +0800 Subject: [PATCH] fix bug --- scripts/on_app_started.py | 2 +- scripts/physton_prompt/styles.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/on_app_started.py b/scripts/on_app_started.py index 79a92cf..6bd3a4a 100755 --- a/scripts/on_app_started.py +++ b/scripts/on_app_started.py @@ -340,7 +340,7 @@ def on_app_started(_: gr.Blocks, app: FastAPI): @app.get("/physton_prompt/styles") async def _styles(file: str): file_path = get_style_full_path(file) - if not os.path.exists(file_path): + if not file_path or not os.path.exists(file_path): return Response(status_code=404) return FileResponse(file_path, filename=os.path.basename(file_path)) diff --git a/scripts/physton_prompt/styles.py b/scripts/physton_prompt/styles.py index f3a62be..9c73124 100644 --- a/scripts/physton_prompt/styles.py +++ b/scripts/physton_prompt/styles.py @@ -9,7 +9,14 @@ styles_path = os.path.normpath(styles_path) def get_style_full_path(file): global styles_path - return os.path.join(styles_path, file) + path = os.path.join(styles_path, file) + path = os.path.abspath(path) + path = os.path.normpath(path) + if not os.path.exists(path): + return None + if styles_path not in path: + return None + return path def get_extension_css_list():