some basic statistics and invite tree, plus watch new data
This commit is contained in:
@@ -29,6 +29,7 @@ from bincio.serve.db import (
|
||||
create_user,
|
||||
delete_session,
|
||||
get_invite,
|
||||
get_member_tree,
|
||||
get_session,
|
||||
get_setting,
|
||||
get_user,
|
||||
@@ -173,6 +174,27 @@ async def me(bincio_session: Optional[str] = Cookie(default=None)) -> JSONRespon
|
||||
})
|
||||
|
||||
|
||||
@app.get("/api/stats")
|
||||
async def stats() -> JSONResponse:
|
||||
"""Public endpoint: member count, join dates, and invitation tree."""
|
||||
import time as _time
|
||||
now = int(_time.time())
|
||||
members = get_member_tree(_get_db())
|
||||
return JSONResponse({
|
||||
"user_count": len(members),
|
||||
"members": [
|
||||
{
|
||||
"handle": m["handle"],
|
||||
"display_name": m["display_name"],
|
||||
"member_since": m["created_at"],
|
||||
"member_for_days": (now - m["created_at"]) // 86400,
|
||||
"invited_by": m["invited_by"],
|
||||
}
|
||||
for m in members
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
@app.post("/api/auth/login")
|
||||
async def login(request: Request) -> JSONResponse:
|
||||
ip = request.client.host if request.client else "unknown"
|
||||
|
||||
Reference in New Issue
Block a user