feat: Initialize ObsiGate application with core frontend and backend components.
This commit is contained in:
+69
-4
@@ -50,7 +50,7 @@ from backend.vault_settings import (
|
||||
get_all_vault_settings,
|
||||
delete_vault_setting,
|
||||
)
|
||||
from backend.history import record_open, get_recent_opened
|
||||
from backend.history import record_open, get_recent_opened, toggle_bookmark, get_bookmarks, is_bookmarked
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
@@ -669,7 +669,8 @@ async def api_recent(limit: Optional[int] = Query(None), vault: Optional[str] =
|
||||
"mtime_human": humanize_mtime(item["opened_at"]),
|
||||
"size_bytes": f_idx.get("size", 0),
|
||||
"tags": [f"#{t}" for t in f_idx.get("tags", [])][:5],
|
||||
"preview": f_idx.get("content_preview", "")[:120]
|
||||
"preview": f_idx.get("content_preview", "")[:120],
|
||||
"bookmarked": is_bookmarked(username, v_name, f_idx["path"])
|
||||
})
|
||||
else:
|
||||
# File might have been renamed/deleted since last open
|
||||
@@ -680,7 +681,8 @@ async def api_recent(limit: Optional[int] = Query(None), vault: Optional[str] =
|
||||
"mtime": item["opened_at"],
|
||||
"mtime_human": humanize_mtime(item["opened_at"]),
|
||||
"tags": [],
|
||||
"preview": ""
|
||||
"preview": "",
|
||||
"bookmarked": is_bookmarked(username, v_name, item["path"])
|
||||
})
|
||||
return {
|
||||
"files": files_resp,
|
||||
@@ -721,7 +723,8 @@ async def api_recent(limit: Optional[int] = Query(None), vault: Optional[str] =
|
||||
"mtime_iso": iso_modified,
|
||||
"size_bytes": f.get("size", 0),
|
||||
"tags": [f"#{t}" for t in f.get("tags", [])][:5],
|
||||
"preview": f.get("content_preview", "")[:120]
|
||||
"preview": f.get("content_preview", "")[:120],
|
||||
"bookmarked": is_bookmarked(username, v_name, f["path"])
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -732,6 +735,68 @@ async def api_recent(limit: Optional[int] = Query(None), vault: Optional[str] =
|
||||
}
|
||||
|
||||
|
||||
@app.get("/api/bookmarks")
|
||||
async def api_bookmarks(vault: Optional[str] = Query(None), current_user=Depends(require_auth)):
|
||||
username = current_user.get("username")
|
||||
user_vaults = current_user.get("_token_vaults") or current_user.get("vaults", [])
|
||||
|
||||
if not username:
|
||||
return {"files": []}
|
||||
|
||||
history = get_bookmarks(username, vault_filter=vault)
|
||||
files_resp = []
|
||||
for item in history:
|
||||
v_name = item["vault"]
|
||||
if "*" not in user_vaults and v_name not in user_vaults:
|
||||
continue
|
||||
|
||||
# Find in index to get metadata
|
||||
f_idx = find_file_in_index(item["path"], v_name)
|
||||
if f_idx:
|
||||
files_resp.append({
|
||||
"path": f_idx["path"],
|
||||
"title": f_idx.get("title") or item["path"].split("/")[-1],
|
||||
"vault": v_name,
|
||||
"mtime": item["bookmarked_at"],
|
||||
"mtime_human": humanize_mtime(item["bookmarked_at"]),
|
||||
"size_bytes": f_idx.get("size", 0),
|
||||
"tags": [f"#{t}" for t in f_idx.get("tags", [])][:5],
|
||||
"bookmarked": True
|
||||
})
|
||||
else:
|
||||
files_resp.append({
|
||||
"path": item["path"],
|
||||
"title": item.get("title") or item["path"].split("/")[-1],
|
||||
"vault": v_name,
|
||||
"mtime": item["bookmarked_at"],
|
||||
"mtime_human": humanize_mtime(item["bookmarked_at"]),
|
||||
"tags": [],
|
||||
"bookmarked": True
|
||||
})
|
||||
return {
|
||||
"files": files_resp,
|
||||
"total": len(files_resp)
|
||||
}
|
||||
|
||||
class BookmarkToggleRequest(BaseModel):
|
||||
vault: str
|
||||
path: str
|
||||
title: Optional[str] = None
|
||||
|
||||
@app.post("/api/bookmarks/toggle")
|
||||
async def api_toggle_bookmark(req: BookmarkToggleRequest, current_user=Depends(require_auth)):
|
||||
username = current_user.get("username")
|
||||
if not username:
|
||||
raise HTTPException(status_code=401, detail="Not authenticated")
|
||||
|
||||
# Check vault access
|
||||
if not check_vault_access(req.vault, current_user):
|
||||
raise HTTPException(status_code=403, detail="Access denied to vault")
|
||||
|
||||
is_now_bookmarked = toggle_bookmark(username, req.vault, req.path, req.title)
|
||||
return {"bookmarked": is_now_bookmarked}
|
||||
|
||||
|
||||
@app.get("/api/browse/{vault_name}", response_model=BrowseResponse)
|
||||
async def api_browse(vault_name: str, path: str = "", current_user=Depends(require_auth)):
|
||||
"""Browse directories and files in a vault at a given path level.
|
||||
|
||||
Reference in New Issue
Block a user