OXYGENHUB
# baebdd18aaa2 oxygenhub / crates / hub / src / web / refs.rs
3.4 KiB · Rust · last changed Milestone 0.1: browse 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 = app.repos.read(&repo, move |r| view::bookmarks(r, &default)).await.map_err(|e| Error::from_repo(shell.clone(), e))?;
22
    Ok(Page(BookmarksPage { shell, repo: RepoShell::new(&app, &row, "bookmarks"), bookmarks }))
23
}
24
25
#[derive(Template)]
26
#[template(path = "tags.html")]
27
pub struct TagsPage {
28
    shell: Shell,
29
    repo: RepoShell,
30
    tags: Vec<view::TagView>,
31
}
32
33
pub async fn tags(State(app): State<Shared>, Path((owner, name)): Path<(String, String)>) -> Result<Page<TagsPage>, Error> {
34
    let shell = Shell::new(&app, &format!("/{owner}/{name}/tags"));
35
    let (repo, row) = lookup(&app, &shell, &owner, &name).await?;
36
    let tags = app.repos.read(&repo, view::tags).await.map_err(|e| Error::from_repo(shell.clone(), e))?;
37
    Ok(Page(TagsPage { shell, repo: RepoShell::new(&app, &row, "tags"), tags }))
38
}
39
40
#[derive(Template)]
41
#[template(path = "conflicts.html")]
42
pub struct ConflictsPage {
43
    shell: Shell,
44
    repo: RepoShell,
45
    conflicts: Vec<view::ConflictView>,
46
}
47
48
pub async fn conflicts(State(app): State<Shared>, Path((owner, name)): Path<(String, String)>) -> Result<Page<ConflictsPage>, Error> {
49
    let shell = Shell::new(&app, &format!("/{owner}/{name}/conflicts"));
50
    let (repo, row) = lookup(&app, &shell, &owner, &name).await?;
51
    let conflicts = app.repos.read(&repo, view::conflicts).await.map_err(|e| Error::from_repo(shell.clone(), e))?;
52
    Ok(Page(ConflictsPage { shell, repo: RepoShell::new(&app, &row, "conflicts"), conflicts }))
53
}
54
55
#[derive(Template)]
56
#[template(path = "trust.html")]
57
pub struct TrustPage {
58
    shell: Shell,
59
    repo: RepoShell,
60
    t: view::Trust,
61
}
62
63
pub async fn trust(State(app): State<Shared>, Path((owner, name)): Path<(String, String)>) -> Result<Page<TrustPage>, Error> {
64
    let shell = Shell::new(&app, &format!("/{owner}/{name}/trust"));
65
    let (repo, row) = lookup(&app, &shell, &owner, &name).await?;
66
    let key = app.hub_key.key;
67
    let t = app.repos.read(&repo, move |r| view::trust(r, &key)).await.map_err(|e| Error::from_repo(shell.clone(), e))?;
68
    Ok(Page(TrustPage { shell, repo: RepoShell::new(&app, &row, "trust"), t }))
69
}
70
71
#[derive(Template)]
72
#[template(path = "pushes.html")]
73
pub struct PushesPage {
74
    shell: Shell,
75
    repo: RepoShell,
76
    pushes: Vec<db::repos::PushRow>,
77
}
78
79
pub async fn pushes(State(app): State<Shared>, Path((owner, name)): Path<(String, String)>) -> Result<Page<PushesPage>, Error> {
80
    let shell = Shell::new(&app, &format!("/{owner}/{name}/pushes"));
81
    let (_, row) = lookup(&app, &shell, &owner, &name).await?;
82
    let pushes = db::repos::pushes(&app.db, row.id, 200).await.map_err(|e| Error::from_db(shell.clone(), e))?;
83
    Ok(Page(PushesPage { shell, repo: RepoShell::new(&app, &row, "pushes"), pushes }))
84
}