OXYGENHUB
◆ v0.5.1 oxygenhub / crates / hub / src / web / help.rs
1.5 KiB · Rust · last changed Pin oxygen main: scoped delegates; the hub needs changes and refs 1 month ago source blame history raw
43e8ca33 Andy McCall ↶ 1
//! `/help` (hub spec §6.3): getting started with this hub's own address,
2
//! remote name and certificate filled in, the keyboard, and a glossary
3
//! for people coming from GitHub.
4
5
use super::repo::Quickstart;
6
use super::{Page, Shell};
7
use crate::auth::Viewer;
8
use crate::Shared;
9
use askama::Template;
10
use axum::extract::State;
11
12
#[derive(Template)]
13
#[template(path = "help.html")]
14
pub struct HelpPage {
15
    shell: Shell,
16
    q: Quickstart,
17
    base: String,
18
    /// The signed-in user, or a placeholder, for example URLs.
19
    who: String,
20
}
21
22
pub async fn help(State(app): State<Shared>, viewer: Viewer) -> Page<HelpPage> {
23
    let shell = Shell::new(&app, "/help", &viewer);
24
    let who = shell.user.clone().unwrap_or_else(|| "OWNER".into());
25
    let base = app.config.base_url().trim_end_matches('/').to_string();
26
    Page(HelpPage { shell, q: Quickstart::new(&app, true), base, who })
27
}
28
29
impl HelpPage {
30
    /// An example repository address on this hub.
31
    pub fn repo_url(&self) -> String {
32
        format!("{}/{}/REPOSITORY", self.base, self.who)
33
    }
34
35
    pub fn delegate_cmd(&self) -> String {
b43a9ab0 Andy McCall ↶ 36
        format!(
37
            "curl -fsSL {}/.well-known/oxyhub-key -o hub.identity\noxy identity delegate add hub.identity --scope changes,refs",
38
            self.base
39
        )
43e8ca33 Andy McCall ↶ 40
    }
41
42
    pub fn clone_cmd(&self) -> String {
43
        let url = self.repo_url();
44
        match &self.q.ca_url {
45
            Some(_) => format!("OXY_CA={} oxy clone {url}", self.q.ca_file),
46
            None => format!("oxy clone {url}"),
47
        }
48
    }
49
}