OXYGENHUB
# 736ae87ef318 oxygenhub / crates / hub / src / web / refs.rs
3.4 KiB · Rust · last changed State cache keyed by heads; history and graph through oxy-core's lanes and log window 1 month ago source blame history raw
1
//! Bookmarks, tags, conflicts, trust and pushes pages.
2
3
use super::{filters, lookup, Error, Page, RepoShell, Shell};
4
use crate::repos::view;
5
use crate::{db, Shared};
6
use askama::Template;
7
use axum::extract::{Path, State};
8
9
#[derive(Template)]
10
#[template(path = "bookmarks.html")]
11
pub struct BookmarksPage {
12
    shell: Shell,
13
    repo: RepoShell,
14
    bookmarks: Vec<view::BookmarkView>,
15
}
16
17
pub async fn bookmarks(State(app): State<Shared>, Path((owner, name)): Path<(String, String)>) -> Result<Page<BookmarksPage>, Error> {
18
    let shell = Shell::new(&app, &format!("/{owner}/{name}/bookmarks"));
19
    let (repo, row) = lookup(&app, &shell, &owner, &name).await?;
20
    let default = row.default_bookmark.clone();
21
    let bookmarks =
22
        app.repos.read(&repo, move |r, cache| view::bookmarks(r, cache, &default)).await.map_err(|e| Error::from_repo(shell.clone(), e))?;
23
    Ok(Page(BookmarksPage { shell, repo: RepoShell::new(&app, &row, "bookmarks"), bookmarks }))
24
}
25
26
#[derive(Template)]
27
#[template(path = "tags.html")]
28
pub struct TagsPage {
29
    shell: Shell,
30
    repo: RepoShell,
31
    tags: Vec<view::TagView>,
32
}
33
34
pub async fn tags(State(app): State<Shared>, Path((owner, name)): Path<(String, String)>) -> Result<Page<TagsPage>, Error> {
35
    let shell = Shell::new(&app, &format!("/{owner}/{name}/tags"));
36
    let (repo, row) = lookup(&app, &shell, &owner, &name).await?;
37
    let tags = app.repos.read(&repo, |r, _| view::tags(r)).await.map_err(|e| Error::from_repo(shell.clone(), e))?;
38
    Ok(Page(TagsPage { shell, repo: RepoShell::new(&app, &row, "tags"), tags }))
39
}
40
41
#[derive(Template)]
42
#[template(path = "conflicts.html")]
43
pub struct ConflictsPage {
44
    shell: Shell,
45
    repo: RepoShell,
46
    conflicts: Vec<view::ConflictView>,
47
}
48
49
pub async fn conflicts(State(app): State<Shared>, Path((owner, name)): Path<(String, String)>) -> Result<Page<ConflictsPage>, Error> {
50
    let shell = Shell::new(&app, &format!("/{owner}/{name}/conflicts"));
51
    let (repo, row) = lookup(&app, &shell, &owner, &name).await?;
52
    let conflicts = app.repos.read(&repo, view::conflicts).await.map_err(|e| Error::from_repo(shell.clone(), e))?;
53
    Ok(Page(ConflictsPage { shell, repo: RepoShell::new(&app, &row, "conflicts"), conflicts }))
54
}
55
56
#[derive(Template)]
57
#[template(path = "trust.html")]
58
pub struct TrustPage {
59
    shell: Shell,
60
    repo: RepoShell,
61
    t: view::Trust,
62
}
63
64
pub async fn trust(State(app): State<Shared>, Path((owner, name)): Path<(String, String)>) -> Result<Page<TrustPage>, Error> {
65
    let shell = Shell::new(&app, &format!("/{owner}/{name}/trust"));
66
    let (repo, row) = lookup(&app, &shell, &owner, &name).await?;
67
    let key = app.hub_key.key;
68
    let t = app.repos.read(&repo, move |r, cache| view::trust(r, cache, &key)).await.map_err(|e| Error::from_repo(shell.clone(), e))?;
69
    Ok(Page(TrustPage { shell, repo: RepoShell::new(&app, &row, "trust"), t }))
70
}
71
72
#[derive(Template)]
73
#[template(path = "pushes.html")]
74
pub struct PushesPage {
75
    shell: Shell,
76
    repo: RepoShell,
77
    pushes: Vec<db::repos::PushRow>,
78
}
79
80
pub async fn pushes(State(app): State<Shared>, Path((owner, name)): Path<(String, String)>) -> Result<Page<PushesPage>, Error> {
81
    let shell = Shell::new(&app, &format!("/{owner}/{name}/pushes"));
82
    let (_, row) = lookup(&app, &shell, &owner, &name).await?;
83
    let pushes = db::repos::pushes(&app.db, row.id, 200).await.map_err(|e| Error::from_db(shell.clone(), e))?;
84
    Ok(Page(PushesPage { shell, repo: RepoShell::new(&app, &row, "pushes"), pushes }))
85
}