| d23464c0 Andy McCall ↶ |
1 |
|
| 2 |
|
| 3 |
use super::{filters, lookup, Error, Page, RepoShell, Shell}; |
| 19bb31ff Andy McCall ↶ |
4 |
use crate::auth::Viewer; |
| d23464c0 Andy McCall ↶ |
5 |
use crate::repos::view; |
| 6 |
use crate::{db, Shared}; |
| 7 |
use askama::Template; |
| 8 |
use axum::extract::{Path, State}; |
| 9 |
|
| 10 |
#[derive(Template)] |
| 11 |
#[template(path = "bookmarks.html")] |
| 12 |
pub struct BookmarksPage { |
| 13 |
shell: Shell, |
| 14 |
repo: RepoShell, |
| 15 |
bookmarks: Vec<view::BookmarkView>, |
| 16 |
} |
| 17 |
|
| 19bb31ff Andy McCall ↶ |
18 |
pub async fn bookmarks( |
| 19 |
State(app): State<Shared>, |
| 20 |
viewer: Viewer, |
| 21 |
Path((owner, name)): Path<(String, String)>, |
| 22 |
) -> Result<Page<BookmarksPage>, Error> { |
| 23 |
let shell = Shell::new(&app, &format!("/{owner}/{name}/bookmarks"), &viewer); |
| 24 |
let (repo, row, role) = lookup(&app, &shell, &viewer, &owner, &name).await?; |
| d23464c0 Andy McCall ↶ |
25 |
let default = row.default_bookmark.clone(); |
| 9ff27da5 Andy McCall ↶ |
26 |
let bookmarks = |
| 27 |
app.repos.read(&repo, move |r, cache| view::bookmarks(r, cache, &default)).await.map_err(|e| Error::from_repo(shell.clone(), e))?; |
| 19bb31ff Andy McCall ↶ |
28 |
Ok(Page(BookmarksPage { shell, repo: RepoShell::new(&app, &row, "bookmarks").with_role(role), bookmarks })) |
| d23464c0 Andy McCall ↶ |
29 |
} |
| 30 |
|
| 31 |
#[derive(Template)] |
| 32 |
#[template(path = "tags.html")] |
| 33 |
pub struct TagsPage { |
| 34 |
shell: Shell, |
| 35 |
repo: RepoShell, |
| 36 |
tags: Vec<view::TagView>, |
| 37 |
} |
| 38 |
|
| 19bb31ff Andy McCall ↶ |
39 |
pub async fn tags(State(app): State<Shared>, viewer: Viewer, Path((owner, name)): Path<(String, String)>) -> Result<Page<TagsPage>, Error> { |
| 40 |
let shell = Shell::new(&app, &format!("/{owner}/{name}/tags"), &viewer); |
| 41 |
let (repo, row, role) = lookup(&app, &shell, &viewer, &owner, &name).await?; |
| 9ff27da5 Andy McCall ↶ |
42 |
let tags = app.repos.read(&repo, |r, _| view::tags(r)).await.map_err(|e| Error::from_repo(shell.clone(), e))?; |
| 19bb31ff Andy McCall ↶ |
43 |
Ok(Page(TagsPage { shell, repo: RepoShell::new(&app, &row, "tags").with_role(role), tags })) |
| d23464c0 Andy McCall ↶ |
44 |
} |
| 45 |
|
| 46 |
#[derive(Template)] |
| 47 |
#[template(path = "conflicts.html")] |
| 48 |
pub struct ConflictsPage { |
| 49 |
shell: Shell, |
| 50 |
repo: RepoShell, |
| 51 |
conflicts: Vec<view::ConflictView>, |
| 52 |
} |
| 53 |
|
| 19bb31ff Andy McCall ↶ |
54 |
pub async fn conflicts( |
| 55 |
State(app): State<Shared>, |
| 56 |
viewer: Viewer, |
| 57 |
Path((owner, name)): Path<(String, String)>, |
| 58 |
) -> Result<Page<ConflictsPage>, Error> { |
| 59 |
let shell = Shell::new(&app, &format!("/{owner}/{name}/conflicts"), &viewer); |
| 60 |
let (repo, row, role) = lookup(&app, &shell, &viewer, &owner, &name).await?; |
| d23464c0 Andy McCall ↶ |
61 |
let conflicts = app.repos.read(&repo, view::conflicts).await.map_err(|e| Error::from_repo(shell.clone(), e))?; |
| 19bb31ff Andy McCall ↶ |
62 |
Ok(Page(ConflictsPage { shell, repo: RepoShell::new(&app, &row, "conflicts").with_role(role), conflicts })) |
| d23464c0 Andy McCall ↶ |
63 |
} |
| 64 |
|
| 65 |
#[derive(Template)] |
| 66 |
#[template(path = "trust.html")] |
| 67 |
pub struct TrustPage { |
| 68 |
shell: Shell, |
| 69 |
repo: RepoShell, |
| 70 |
t: view::Trust, |
| 71 |
} |
| 72 |
|
| 19bb31ff Andy McCall ↶ |
73 |
pub async fn trust( |
| 74 |
State(app): State<Shared>, |
| 75 |
viewer: Viewer, |
| 76 |
Path((owner, name)): Path<(String, String)>, |
| 77 |
) -> Result<Page<TrustPage>, Error> { |
| 78 |
let shell = Shell::new(&app, &format!("/{owner}/{name}/trust"), &viewer); |
| 79 |
let (repo, row, role) = lookup(&app, &shell, &viewer, &owner, &name).await?; |
| d23464c0 Andy McCall ↶ |
80 |
let key = app.hub_key.key; |
| 9ff27da5 Andy McCall ↶ |
81 |
let t = app.repos.read(&repo, move |r, cache| view::trust(r, cache, &key)).await.map_err(|e| Error::from_repo(shell.clone(), e))?; |
| 19bb31ff Andy McCall ↶ |
82 |
Ok(Page(TrustPage { shell, repo: RepoShell::new(&app, &row, "trust").with_role(role), t })) |
| d23464c0 Andy McCall ↶ |
83 |
} |
| 84 |
|
| 85 |
#[derive(Template)] |
| 86 |
#[template(path = "pushes.html")] |
| 87 |
pub struct PushesPage { |
| 88 |
shell: Shell, |
| 89 |
repo: RepoShell, |
| 90 |
pushes: Vec<db::repos::PushRow>, |
| 91 |
} |
| 92 |
|
| 19bb31ff Andy McCall ↶ |
93 |
pub async fn pushes( |
| 94 |
State(app): State<Shared>, |
| 95 |
viewer: Viewer, |
| 96 |
Path((owner, name)): Path<(String, String)>, |
| 97 |
) -> Result<Page<PushesPage>, Error> { |
| 98 |
let shell = Shell::new(&app, &format!("/{owner}/{name}/pushes"), &viewer); |
| 99 |
let (_, row, role) = lookup(&app, &shell, &viewer, &owner, &name).await?; |
| d23464c0 Andy McCall ↶ |
100 |
let pushes = db::repos::pushes(&app.db, row.id, 200).await.map_err(|e| Error::from_db(shell.clone(), e))?; |
| 19bb31ff Andy McCall ↶ |
101 |
Ok(Page(PushesPage { shell, repo: RepoShell::new(&app, &row, "pushes").with_role(role), pushes })) |
| d23464c0 Andy McCall ↶ |
102 |
} |