mirror of
https://github.com/JonasunderscoreJones/selfhosted-overleaf-project-share.git
synced 2025-10-25 09:59:19 +02:00
added symlink creation
This commit is contained in:
parent
6e4e68f85c
commit
b0d53e496c
1 changed files with 16 additions and 2 deletions
18
serve.py
18
serve.py
|
|
@ -12,6 +12,17 @@ GRAB_SYMLINKS = True # Toggle symlink handling on/off
|
|||
SYMLINK_DIR = os.path.abspath("symlinks") # Directory to resolve symlinks to
|
||||
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):
|
||||
project_dir = os.path.join(BASE_DIR, "projects", project_id)
|
||||
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
|
||||
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:
|
||||
if symlink_dir.startswith(project_id):
|
||||
return os.path.join(SYMLINK_DIR, symlink_dir)
|
||||
if symlink_dir == project_id or symlink_dir.startswith(project_id + "-"):
|
||||
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
|
||||
|
||||
class CustomHandler(http.server.SimpleHTTPRequestHandler):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue