//! `/log` (oxygenhub#238): the transparency log's latest checkpoint and //! its newest entries, with where to fetch the rest (C2SP tlog-tiles). use super::{filters, Page, Shell}; use crate::auth::Viewer; use crate::{db, Shared}; use askama::Template; use axum::extract::State; pub struct Row { pub idx: i64, pub kind: String, pub object: String, /// `owner/name`, when the entry is a repository's this hub still has. pub repo: Option, pub received_ms: i64, } #[derive(Template)] #[template(path = "log.html")] pub struct LogPage { shell: Shell, origin: String, size: u64, note: Option, base: String, rows: Vec, } pub async fn page(State(app): State, viewer: Viewer) -> Page { let shell = Shell::new(&app, "/log", &viewer); let recent = db::tlog::recent(&app.db, None, 50).await.unwrap_or_default(); let mut rows = Vec::with_capacity(recent.len()); for r in recent { // Entries of private repositories show only their hashes, and so // do a secret drop's (#279), whose address is its secret. let repo = match r.repo_id { Some(id) => match db::repos::get_by_id(&app.db, id).await { Ok(Some(row)) if (!row.is_drop() || crate::drops::listed_to(viewer.account(), &row)) && crate::auth::roles::allows( crate::auth::roles::role_for(&app.db, viewer.account(), &row).await.unwrap_or(None), crate::auth::roles::Access::Read, ) => { Some(row.slug()) } _ => None, }, None => None, }; rows.push(Row { idx: r.idx, kind: r.kind, object: r.object, repo, received_ms: r.received_ms }); } Page(LogPage { shell, origin: app.tlog.origin.clone(), size: app.tlog.size(), note: app.tlog.checkpoint(), base: app.config.base_url().trim_end_matches('/').to_string(), rows, }) }