| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | | use super::{filters, Page, Shell}; |
| 5 | | use crate::auth::Viewer; |
| 6 | | use crate::{db, Shared}; |
| 7 | | use askama::Template; |
| 8 | | use axum::extract::State; |
| 9 | |
|
| 10 | | pub struct Row { |
| 11 | | pub idx: i64, |
| 12 | | pub kind: String, |
| 13 | | pub object: String, |
| 14 | | |
| 15 | | pub repo: Option<String>, |
| 16 | | pub received_ms: i64, |
| 17 | | } |
| 18 | |
|
| 19 | | #[derive(Template)] |
| 20 | | #[template(path = "log.html")] |
| 21 | | pub struct LogPage { |
| 22 | | shell: Shell, |
| 23 | | origin: String, |
| 24 | | size: u64, |
| 25 | | note: Option<String>, |
| 26 | | base: String, |
| 27 | | rows: Vec<Row>, |
| 28 | | } |
| 29 | |
|
| 30 | 1× | pub async fn page(State(app): State<Shared>, viewer: Viewer) -> Page<LogPage> { |
| 31 | 1× | let shell = Shell::new(&app, "/log", &viewer); |
| 32 | 1× | let recent = db::tlog::recent(&app.db, None, 50).await.unwrap_or_default(); |
| 33 | 1× | let mut rows = Vec::with_capacity(recent.len()); |
| 34 | 3× | for r in recent { |
| 35 | | |
| 36 | | |
| 37 | 3× | let repo = match r.repo_id { |
| 38 | 3× | Some(id) => match db::repos::get_by_id(&app.db, id).await { |
| 39 | 3× | Ok(Some(row)) |
| 40 | 3× | if (!row.is_drop() || crate::drops::listed_to(viewer.account(), &row)) |
| 41 | 3× | && crate::auth::roles::allows( |
| 42 | 3× | crate::auth::roles::role_for(&app.db, viewer.account(), &row).await.unwrap_or(None), |
| 43 | 3× | crate::auth::roles::Access::Read, |
| 44 | 3× | ) => |
| 45 | | { |
| 46 | 3× | Some(row.slug()) |
| 47 | | } |
| 48 | 0× | _ => None, |
| 49 | | }, |
| 50 | 0× | None => None, |
| 51 | | }; |
| 52 | 3× | rows.push(Row { idx: r.idx, kind: r.kind, object: r.object, repo, received_ms: r.received_ms }); |
| 53 | | } |
| 54 | 1× | Page(LogPage { |
| 55 | 1× | shell, |
| 56 | 1× | origin: app.tlog.origin.clone(), |
| 57 | 1× | size: app.tlog.size(), |
| 58 | 1× | note: app.tlog.checkpoint(), |
| 59 | 1× | base: app.config.base_url().trim_end_matches('/').to_string(), |
| 60 | 1× | rows, |
| 61 | 1× | }) |
| 62 | 1× | } |