//! Bookmarks, tags, conflicts, trust and pushes pages. use super::{filters, lookup, Error, Page, RepoShell, Shell}; use crate::repos::view; use crate::{db, Shared}; use askama::Template; use axum::extract::{Path, State}; #[derive(Template)] #[template(path = "bookmarks.html")] pub struct BookmarksPage { shell: Shell, repo: RepoShell, bookmarks: Vec, } pub async fn bookmarks(State(app): State, Path((owner, name)): Path<(String, String)>) -> Result, Error> { let shell = Shell::new(&app, &format!("/{owner}/{name}/bookmarks")); let (repo, row) = lookup(&app, &shell, &owner, &name).await?; let default = row.default_bookmark.clone(); let bookmarks = app.repos.read(&repo, move |r| view::bookmarks(r, &default)).await.map_err(|e| Error::from_repo(shell.clone(), e))?; Ok(Page(BookmarksPage { shell, repo: RepoShell::new(&app, &row, "bookmarks"), bookmarks })) } #[derive(Template)] #[template(path = "tags.html")] pub struct TagsPage { shell: Shell, repo: RepoShell, tags: Vec, } pub async fn tags(State(app): State, Path((owner, name)): Path<(String, String)>) -> Result, Error> { let shell = Shell::new(&app, &format!("/{owner}/{name}/tags")); let (repo, row) = lookup(&app, &shell, &owner, &name).await?; let tags = app.repos.read(&repo, view::tags).await.map_err(|e| Error::from_repo(shell.clone(), e))?; Ok(Page(TagsPage { shell, repo: RepoShell::new(&app, &row, "tags"), tags })) } #[derive(Template)] #[template(path = "conflicts.html")] pub struct ConflictsPage { shell: Shell, repo: RepoShell, conflicts: Vec, } pub async fn conflicts(State(app): State, Path((owner, name)): Path<(String, String)>) -> Result, Error> { let shell = Shell::new(&app, &format!("/{owner}/{name}/conflicts")); let (repo, row) = lookup(&app, &shell, &owner, &name).await?; let conflicts = app.repos.read(&repo, view::conflicts).await.map_err(|e| Error::from_repo(shell.clone(), e))?; Ok(Page(ConflictsPage { shell, repo: RepoShell::new(&app, &row, "conflicts"), conflicts })) } #[derive(Template)] #[template(path = "trust.html")] pub struct TrustPage { shell: Shell, repo: RepoShell, t: view::Trust, } pub async fn trust(State(app): State, Path((owner, name)): Path<(String, String)>) -> Result, Error> { let shell = Shell::new(&app, &format!("/{owner}/{name}/trust")); let (repo, row) = lookup(&app, &shell, &owner, &name).await?; let key = app.hub_key.key; let t = app.repos.read(&repo, move |r| view::trust(r, &key)).await.map_err(|e| Error::from_repo(shell.clone(), e))?; Ok(Page(TrustPage { shell, repo: RepoShell::new(&app, &row, "trust"), t })) } #[derive(Template)] #[template(path = "pushes.html")] pub struct PushesPage { shell: Shell, repo: RepoShell, pushes: Vec, } pub async fn pushes(State(app): State, Path((owner, name)): Path<(String, String)>) -> Result, Error> { let shell = Shell::new(&app, &format!("/{owner}/{name}/pushes")); let (_, row) = lookup(&app, &shell, &owner, &name).await?; let pushes = db::repos::pushes(&app.db, row.id, 200).await.map_err(|e| Error::from_db(shell.clone(), e))?; Ok(Page(PushesPage { shell, repo: RepoShell::new(&app, &row, "pushes"), pushes })) }