feat: add Obsidian open button; fix folder button using dolphin --select

This commit is contained in:
2026-04-02 10:55:19 +02:00
parent 348ce332c7
commit 6f718f0753
3 changed files with 23 additions and 5 deletions
+13 -4
View File
@@ -208,12 +208,21 @@ async def put_config(body: dict, user: dict = Depends(current_user)):
@router.post("/open")
async def open_file(body: dict, user: dict = Depends(current_user)):
import subprocess
import subprocess, shutil
path = body.get("path", "")
user_dir = os.path.join(user["output_dir"], user["username"])
if path and os.path.exists(path) and os.path.abspath(path).startswith(os.path.abspath(user_dir)):
target = os.path.dirname(path) if body.get("folder") else path
subprocess.Popen(["xdg-open", target])
if not (path and os.path.exists(path) and os.path.abspath(path).startswith(os.path.abspath(user_dir))):
return {"ok": False}
mode = body.get("mode", "editor") # "editor" | "folder" | "obsidian"
if mode == "obsidian":
from urllib.parse import quote
subprocess.Popen(["xdg-open", f"obsidian://open?path={quote(path, safe='/')}"])
elif mode == "folder" and shutil.which("dolphin"):
subprocess.Popen(["dolphin", "--select", path])
elif mode == "folder":
subprocess.Popen(["xdg-open", os.path.dirname(path)])
else:
subprocess.Popen(["xdg-open", path])
return {"ok": True}