user spaces

This commit is contained in:
2026-09-23 14:13:08 -07:00
parent 163cad4f5f
commit 67769c50d8
4 changed files with 50 additions and 17 deletions

View File

@@ -80,6 +80,7 @@ async def me(request: Request) -> dict:
ip = client_ip(request)
return {
"user": current_user(request),
"common_space": settings.common_space,
"local": auth.is_lan(ip),
"authed": not auth.is_lan(ip)
and bool(
@@ -140,8 +141,8 @@ async def list_notes(request: Request, _: None = Depends(require_access)):
@app.get("/api/notes/recent")
async def recent(_: None = Depends(require_access)):
return await notes.list_recent()
async def recent(request: Request, _: None = Depends(require_access)):
return await notes.list_recent(current_user(request))
@app.get("/api/notes/{note_id}")

View File

@@ -243,15 +243,15 @@ async def list_notes(username: str, limit: int = 100) -> list[dict]:
return notes
async def list_recent(limit: int = 30) -> list[dict]:
async def list_recent(username: str, limit: int = 30) -> list[dict]:
async with aiosqlite.connect(settings.database_path) as db:
db.row_factory = aiosqlite.Row
rows = await db.execute(
"SELECT n.id, n.title, n.updated_at, n.created_at, u.name AS username"
" FROM notes n JOIN users u ON u.id = n.user_id"
" WHERE n.deleted_at IS NULL"
" WHERE n.deleted_at IS NULL AND u.name IN (?, ?)"
" ORDER BY n.updated_at DESC LIMIT ?",
(limit,),
(username, settings.common_space, limit),
)
notes = [dict(r) for r in await rows.fetchall()]
for note in notes: