OXYGENHUB
# 076c7a7c86b1 oxygenhub / crates / hub / src / web / help.rs
1.8 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
    /// Trust this hub's certificate, when it is self-signed (empty otherwise).
31
    pub fn ca_setup(&self) -> String {
32
        match &self.q.ca_url {
33
            Some(url) => format!("mkdir -p ~/.config/oxy\ncurl -fsSL {url} -o {}", self.q.ca_file),
34
            None => String::new(),
35
        }
36
    }
37
38
    /// An example repository address on this hub.
39
    pub fn repo_url(&self) -> String {
40
        format!("{}/{}/REPOSITORY", self.base, self.who)
41
    }
42
43
    pub fn delegate_cmd(&self) -> String {
b43a9ab0 Andy McCall ↶ 44
        format!(
45
            "curl -fsSL {}/.well-known/oxyhub-key -o hub.identity\noxy identity delegate add hub.identity --scope changes,refs",
46
            self.base
47
        )
43e8ca33 Andy McCall ↶ 48
    }
49
50
    pub fn clone_cmd(&self) -> String {
51
        let url = self.repo_url();
52
        match &self.q.ca_url {
53
            Some(_) => format!("OXY_CA={} oxy clone {url}", self.q.ca_file),
54
            None => format!("oxy clone {url}"),
55
        }
56
    }
57
}