From 6f718f0753c9d26199261320308a6f77854f2626 Mon Sep 17 00:00:00 2001 From: "thomas.kopp" Date: Thu, 2 Apr 2026 10:55:19 +0200 Subject: [PATCH] feat: add Obsidian open button; fix folder button using dolphin --select --- api/router.py | 17 +++++++++++++---- frontend/app.js | 6 +++++- frontend/index.html | 5 +++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/api/router.py b/api/router.py index 2c43345..7b29ae2 100644 --- a/api/router.py +++ b/api/router.py @@ -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} diff --git a/frontend/app.js b/frontend/app.js index 01fda20..ec66e99 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -8,6 +8,7 @@ const logoutBtn = document.getElementById('logout-btn'); const modal = document.getElementById('modal'); const modalTitle = document.getElementById('modal-title'); const modalBody = document.getElementById('modal-body'); +const modalObsidianBtn = document.getElementById('modal-obsidian-btn'); const modalFolderBtn = document.getElementById('modal-folder-btn'); const modalOpenBtn = document.getElementById('modal-open-btn'); const modalCloseBtn = document.getElementById('modal-close-btn'); @@ -74,8 +75,11 @@ function closeModal() { modalCloseBtn.addEventListener('click', closeModal); modal.querySelector('.modal-backdrop').addEventListener('click', closeModal); document.addEventListener('keydown', e => { if (e.key === 'Escape') closeModal(); }); +modalObsidianBtn.addEventListener('click', () => { + if (_modalPath) apiFetch('/open', { method: 'POST', body: JSON.stringify({ path: _modalPath, mode: 'obsidian' }) }); +}); modalFolderBtn.addEventListener('click', () => { - if (_modalPath) apiFetch('/open', { method: 'POST', body: JSON.stringify({ path: _modalPath, folder: true }) }); + if (_modalPath) apiFetch('/open', { method: 'POST', body: JSON.stringify({ path: _modalPath, mode: 'folder' }) }); }); modalOpenBtn.addEventListener('click', () => { if (_modalPath) apiFetch('/open', { method: 'POST', body: JSON.stringify({ path: _modalPath }) }); diff --git a/frontend/index.html b/frontend/index.html index 89f66a5..3882189 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -256,6 +256,11 @@