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}
+5 -1
View File
@@ -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 }) });
+5
View File
@@ -256,6 +256,11 @@
<div class="modal-header">
<span id="modal-title" class="modal-title"></span>
<div class="modal-actions">
<button id="modal-obsidian-btn" class="modal-btn" title="In Obsidian öffnen">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 14H9V8h2v8zm4 0h-2V8h2v8z"/>
</svg>
</button>
<button id="modal-folder-btn" class="modal-btn" title="Verzeichnis öffnen">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path d="M10 4H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-8l-2-2z"/>