| 757195ad Andy McCall ↶ |
1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
use super::{filters, lookup, Error, Page, RepoShell, Shell}; |
| 7 |
use crate::auth::Viewer; |
| 8 |
use crate::db::repos::RepoRow; |
| 9 |
use crate::diffusion::Consumer; |
| 10 |
use crate::Shared; |
| 11 |
use askama::Template; |
| 12 |
use axum::extract::{Path, State}; |
| 13 |
|
| 14 |
#[derive(Template)] |
| 15 |
#[template(path = "diffusion.html")] |
| 16 |
pub struct DiffusionPage { |
| 17 |
shell: Shell, |
| 18 |
repo: RepoShell, |
| 19 |
used_by: Vec<Consumer>, |
| 20 |
follows: Vec<(RepoRow, Consumer)>, |
| 21 |
|
| 22 |
unverified: bool, |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
pub async fn page( |
| 27 |
State(app): State<Shared>, |
| 28 |
viewer: Viewer, |
| 29 |
Path((owner, name)): Path<(String, String)>, |
| 30 |
) -> Result<Page<DiffusionPage>, Error> { |
| 31 |
let shell = Shell::new(&app, &format!("/{owner}/{name}/diffusion"), &viewer); |
| 32 |
let (_, row, role) = lookup(&app, &shell, &viewer, &owner, &name).await?; |
| 33 |
let used_by = crate::diffusion::consumers(&app, &row, viewer.account()).await.unwrap_or_default(); |
| 34 |
let follows = crate::diffusion::follows(&app, &row, viewer.account()).await; |
| 35 |
let unverified = crate::diffusion::unverified(&app, &row).await; |
| 36 |
Ok(Page(DiffusionPage { shell, repo: RepoShell::new(&app, &row, "diffusion").with_role(role), used_by, follows, unverified })) |
| 37 |
} |
| 38 |
|
| 39 |
#[derive(Template)] |
| 40 |
#[template(path = "admin_diffusion.html")] |
| 41 |
pub struct AdminPage { |
| 42 |
shell: Shell, |
| 43 |
upstreams: Vec<(RepoRow, Vec<Consumer>, bool)>, |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
pub async fn admin(State(app): State<Shared>, viewer: Viewer) -> Result<Page<AdminPage>, Error> { |
| 48 |
let shell = Shell::new(&app, "/admin/diffusion", &viewer); |
| 49 |
if !viewer.is_admin() { |
| 50 |
return Err(Error::not_found(shell)); |
| 51 |
} |
| 52 |
let upstreams = crate::diffusion::everything(&app, viewer.account()).await; |
| 53 |
Ok(Page(AdminPage { shell, upstreams })) |
| 54 |
} |