added symlink creation

This commit is contained in:
Jonas_Jones 2025-06-09 01:36:18 +02:00
parent 6e4e68f85c
commit b0d53e496c

View file

@ -12,6 +12,17 @@ GRAB_SYMLINKS = True # Toggle symlink handling on/off
SYMLINK_DIR = os.path.abspath("symlinks") # Directory to resolve symlinks to SYMLINK_DIR = os.path.abspath("symlinks") # Directory to resolve symlinks to
STATIC_SHARE_RESTRICTION = True # Toggle restriction on/off STATIC_SHARE_RESTRICTION = True # Toggle restriction on/off
def create_symlink_to_dir(symlink_target, link_path):
try:
if os.path.islink(link_path) or os.path.exists(link_path):
print(f"Path '{link_path}' already exists.")
return
os.symlink(symlink_target, link_path)
print(f"Symlink created: {link_path} -> {symlink_target}")
except OSError as e:
print(f"Failed to create symlink: {e}")
def get_project_directory(project_id): def get_project_directory(project_id):
project_dir = os.path.join(BASE_DIR, "projects", project_id) project_dir = os.path.join(BASE_DIR, "projects", project_id)
if GRAB_SYMLINKS and not os.path.exists(project_dir): if GRAB_SYMLINKS and not os.path.exists(project_dir):
@ -21,8 +32,11 @@ def get_project_directory(project_id):
# Find the symlink directory that starts with the project_id # 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))] symlink_dirs = [d for d in os.listdir(SYMLINK_DIR) if os.path.isdir(os.path.join(SYMLINK_DIR, d))]
for symlink_dir in symlink_dirs: for symlink_dir in symlink_dirs:
if symlink_dir.startswith(project_id): if symlink_dir == project_id or symlink_dir.startswith(project_id + "-"):
return os.path.join(SYMLINK_DIR, symlink_dir) symlink_dir = os.path.join(SYMLINK_DIR, symlink_dir)
if os.path.exists(symlink_dir):
create_symlink_to_dir(symlink_dir, project_dir)
break
return project_dir return project_dir
class CustomHandler(http.server.SimpleHTTPRequestHandler): class CustomHandler(http.server.SimpleHTTPRequestHandler):