feat: Implement core application structure with frontend styling, JavaScript, and Python backend services.

This commit is contained in:
2026-03-27 13:54:08 -04:00
parent 4afa0ab5f9
commit f71d97e06c
4 changed files with 150 additions and 41 deletions
+51 -2
View File
@@ -50,6 +50,7 @@ from backend.vault_settings import (
get_all_vault_settings,
delete_vault_setting,
)
from backend.history import record_open, get_recent_opened
logging.basicConfig(
level=logging.INFO,
@@ -641,12 +642,54 @@ def humanize_mtime(mtime: float) -> str:
@app.get("/api/recent")
async def api_recent(limit: Optional[int] = Query(None), vault: Optional[str] = Query(None), current_user=Depends(require_auth)):
async def api_recent(limit: Optional[int] = Query(None), vault: Optional[str] = Query(None), mode: Optional[str] = Query("opened"), current_user=Depends(require_auth)):
config = _load_config()
actual_limit = limit if limit is not None else config.get("recent_files_limit", 20)
username = current_user.get("username")
user_vaults = current_user.get("_token_vaults") or current_user.get("vaults", [])
if mode == "opened" and username:
# Use history file for "last opened"
history = get_recent_opened(username, vault_filter=vault, limit=actual_limit)
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/preview
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["opened_at"],
"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]
})
else:
# File might have been renamed/deleted since last open
files_resp.append({
"path": item["path"],
"title": item.get("title") or item["path"].split("/")[-1],
"vault": v_name,
"mtime": item["opened_at"],
"mtime_human": humanize_mtime(item["opened_at"]),
"tags": [],
"preview": ""
})
return {
"files": files_resp,
"total": len(files_resp),
"limit": actual_limit,
"mode": "opened"
}
# Fallback to "last modified" (original logic)
all_files = []
for v_name, v_data in index.items():
if vault and v_name != vault:
@@ -685,7 +728,7 @@ async def api_recent(limit: Optional[int] = Query(None), vault: Optional[str] =
"files": files_resp,
"total": len(all_files),
"limit": actual_limit,
"generated_at": time.time()
"mode": "modified"
}
@@ -840,6 +883,9 @@ async def api_file_download(vault_name: str, path: str = Query(..., description=
if not file_path.exists() or not file_path.is_file():
raise HTTPException(status_code=404, detail=f"File not found: {path}")
# Record history
record_open(current_user.get("username"), vault_name, path)
return FileResponse(
path=str(file_path),
filename=file_path.name,
@@ -955,6 +1001,9 @@ async def api_file(vault_name: str, path: str = Query(..., description="Relative
if not file_path.exists() or not file_path.is_file():
raise HTTPException(status_code=404, detail=f"File not found: {path}")
# Record history
record_open(current_user.get("username"), vault_name, path, title=file_path.name)
try:
raw = file_path.read_text(encoding="utf-8", errors="replace")
except PermissionError as e: