OXYGENHUB
# 17ca6cddc534 oxygenhub / crates / hub / src / web / diffusion.rs
2.1 KiB · Rust · last changed Diffusion: see it, and landing refreshes the pin index 23 days ago source blame history raw
757195ad Andy McCall ↶ 1
//! Diffusion's views (#150, docs/diffusion.md): a repository's Diffusion
2
//! tab (the consumers that pin it, and what it follows itself), and Admin ›
3
//! Diffusion across the hub. Each consumer shows green, amber, red, grey
4
//! or up to date (`diffusion::Colour`).
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
    /// This repository has no checks of its own: its bumps are amber.
22
    unverified: bool,
23
}
24
25
/// `GET /{owner}/{name}/diffusion`.
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
/// `GET /admin/diffusion`: every upstream on the hub and its consumers.
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
}