| 965b950f Andy McCall ↶ |
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 |
pub async fn page(State(app): State<Shared>, viewer: Viewer) -> Page<LogPage> { |
| 31 |
let shell = Shell::new(&app, "/log", &viewer); |
| 32 |
let recent = db::tlog::recent(&app.db, None, 50).await.unwrap_or_default(); |
| 33 |
let mut rows = Vec::with_capacity(recent.len()); |
| 34 |
for r in recent { |
| 35 |
|
| 36 |
let repo = match r.repo_id { |
| 37 |
Some(id) => match db::repos::get_by_id(&app.db, id).await { |
| 38 |
Ok(Some(row)) |
| 39 |
if crate::auth::roles::allows( |
| 40 |
crate::auth::roles::role_for(&app.db, viewer.account(), &row).await.unwrap_or(None), |
| 41 |
crate::auth::roles::Access::Read, |
| 42 |
) => |
| 43 |
{ |
| 44 |
Some(row.slug()) |
| 45 |
} |
| 46 |
_ => None, |
| 47 |
}, |
| 48 |
None => None, |
| 49 |
}; |
| 50 |
rows.push(Row { idx: r.idx, kind: r.kind, object: r.object, repo, received_ms: r.received_ms }); |
| 51 |
} |
| 52 |
Page(LogPage { |
| 53 |
shell, |
| 54 |
origin: app.tlog.origin.clone(), |
| 55 |
size: app.tlog.size(), |
| 56 |
note: app.tlog.checkpoint(), |
| 57 |
base: app.config.base_url().trim_end_matches('/').to_string(), |
| 58 |
rows, |
| 59 |
}) |
| 60 |
} |