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