From 9143d783ba3f150d1bfb8e6725137df100516cfb Mon Sep 17 00:00:00 2001 From: Jonas_Jones Date: Mon, 9 Jun 2025 21:26:47 +0200 Subject: [PATCH 1/2] fixed symlink dir not being fetched I can't believe this was the issue... --- .env.defaults | 2 +- serve.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.defaults b/.env.defaults index 661e585..ea98216 100644 --- a/.env.defaults +++ b/.env.defaults @@ -1,4 +1,4 @@ PORT = 8000 GRAB_SYMLINKS = true -SYMLINKS_DIR = "symlinks" +SYMLINK_DIR = "symlinks" STATIC_SHARE_RESTRICTION = true \ No newline at end of file diff --git a/serve.py b/serve.py index 83f50fe..89dfc4b 100644 --- a/serve.py +++ b/serve.py @@ -31,7 +31,7 @@ def get_project_directory(project_id): if GRAB_SYMLINKS and not os.path.exists(project_dir): # If the project does not exist in the projects dir, check if it exists in the symlinks dir if not os.path.exists(SYMLINK_DIR) or not os.path.isdir(SYMLINK_DIR): - return None + return "" # Find the symlink directory that starts with the project_id symlink_dirs = [d for d in os.listdir(SYMLINK_DIR) if os.path.isdir(os.path.join(SYMLINK_DIR, d))] # Sort by last modified time (descending) From d638dfe38cc153c038277ee0ddd75a339358b75b Mon Sep 17 00:00:00 2001 From: Jonas_Jones Date: Mon, 9 Jun 2025 21:34:46 +0200 Subject: [PATCH 2/2] fixed error handling on wrong symlink directory --- serve.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/serve.py b/serve.py index 89dfc4b..8ddf373 100644 --- a/serve.py +++ b/serve.py @@ -31,7 +31,7 @@ def get_project_directory(project_id): if GRAB_SYMLINKS and not os.path.exists(project_dir): # If the project does not exist in the projects dir, check if it exists in the symlinks dir if not os.path.exists(SYMLINK_DIR) or not os.path.isdir(SYMLINK_DIR): - return "" + return None # Find the symlink directory that starts with the project_id symlink_dirs = [d for d in os.listdir(SYMLINK_DIR) if os.path.isdir(os.path.join(SYMLINK_DIR, d))] # Sort by last modified time (descending) @@ -56,6 +56,8 @@ class CustomHandler(http.server.SimpleHTTPRequestHandler): project_id = parts[0] project_dir = get_project_directory(project_id) + if not project_dir: + return os.path.join(BASE_DIR, "404.html") # Check .staticshare restriction if STATIC_SHARE_RESTRICTION: staticshare_path = os.path.join(project_dir, ".staticshare") @@ -88,6 +90,14 @@ class CustomHandler(http.server.SimpleHTTPRequestHandler): project_dir = get_project_directory(project_id) + if not project_dir: + self.send_response(404) + self.send_header("Content-type", "text/html") + self.end_headers() + with open(os.path.join(BASE_DIR, "404.html"), "rb") as f: + self.wfile.write(f.read()) + return + if STATIC_SHARE_RESTRICTION: staticshare_path = os.path.join(project_dir, ".staticshare") if not os.path.isfile(staticshare_path):