"""FlowDeck — Board : library. Découpe A28 de l'ancien app/routers/board.py (2 101 lignes, 53 routes) — un module par concern, contrat inchangé. """ from __future__ import annotations import logging from fastapi import APIRouter, Query, Request from fastapi.responses import HTMLResponse from app.db import get_conn from ._common import _sidebar_data logger = logging.getLogger(__name__) router = APIRouter(tags=["board"], prefix="/board") # ═══════════ Library page ═══════════ @router.get("/library", response_class=HTMLResponse) def library_page(request: Request, owner: str = Query(default=""), repo: str = Query(default="")): """Library page avec onglets Recents, Favorites, Shared, Private — scopé au workspace.""" from app.templating import ENV env = ENV sidebar = _sidebar_data(request, owner, repo) # Load all pages for the workspace from DB ws_key = f"{owner}/{repo}" if owner and repo else "" with get_conn() as conn: if ws_key: rows = conn.execute( "SELECT id, title, workspace, updated_at FROM pages " "WHERE workspace=? AND collection_row_id IS NULL ORDER BY updated_at DESC", (ws_key,), ).fetchall() else: rows = conn.execute( "SELECT id, title, workspace, updated_at FROM pages " "WHERE collection_row_id IS NULL ORDER BY updated_at DESC", ).fetchall() all_pages = [] for r in rows: page = dict(r) all_pages.append({ "id": f"page/{page['id']}", "name": page["title"] or "Untitled", "icon": "📄", "url": f"/pages/{page['id']}", "created_by": "You", "source": page.get("workspace") or "Private", "last_edited": page.get("updated_at", "now"), "last_visited": page.get("updated_at", "now"), }) sidebar["recent_pages"] = all_pages sidebar["favorite_pages"] = [] sidebar["private_pages"] = [p for p in all_pages if p.get("source") == "🔒 Private"] sidebar["shared_pages"] = [] sidebar["shared_made_pages"] = [] sidebar["shared_received_pages"] = [] template = env.get_template("library.html") return template.render(**sidebar) # ═══════════ Favorites API ═══════════