~/selfhut

selfhut/src/repository/refs.rs -rw-r--r-- 1.87 kB
e4d868e2 — Arthur Melton cargo fmt 2 years ago

            
b1605a54 Arthur Melton
b1605a54 Arthur Melton
e4d868e2 Arthur Melton
b1605a54 Arthur Melton
19f9b68c arthurmelton
b1605a54 Arthur Melton
0016c2cc arthurmelton
b1605a54 Arthur Melton
144cd6f8 arthurmelton
b1605a54 Arthur Melton
0016c2cc arthurmelton
b1605a54 Arthur Melton
0016c2cc arthurmelton
b1605a54 Arthur Melton
0016c2cc arthurmelton
b1605a54 Arthur Melton









































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::config::CONFIG;
use crate::git::branches::branches;

use crate::git::tag::get_tag;
use crate::utils::repo_config::repo_config;
use rocket_dyn_templates::{context, Template};

#[get("/<repo>/refs?<page>", rank = 2)]
pub fn refs(repo: String, page: Option<usize>) -> Option<Template> {
    let mut tags = get_tag(repo.clone(), 10, (page.unwrap_or(1) - 1) * 10, None);
    let mut pages = 1;
    match tags {
        Some(ref mut x) => pages = x.1 / 10 + 1,
        None => {}
    }
    Some(Template::render(
        "repository/refs",
        context! {
            title: format!("/ :: {}", repo.clone()),
            repo: repo.clone(),
            config: repo_config(repo.clone()),
            domain: CONFIG.domain.to_string(),
            active: "refs",
            current_dir_file: "/",
            current_dir: "/",
            payment: CONFIG.payment_link.clone(),
            mailing_list: CONFIG.mailing_list.clone(),
            branch: branches(repo.clone()),
            tag: tags,
            page_dec: page.unwrap_or(1)-1,
            page_inc: page.unwrap_or(1)+1,
            total_page: pages,
            page: page.unwrap_or(1)
        },
    ))
}

#[get("/<repo>/refs/<name>", rank = 2)]
pub fn refs_id(repo: String, name: String) -> Option<Template> {
    let binding = get_tag(repo.clone(), 1, 0, Some(name))?;
    let tag = binding.0.first()?;
    Some(Template::render(
        "repository/ref",
        context! {
            title: format!("/ :: {}", repo.clone()),
            repo: repo.clone(),
            config: repo_config(repo.clone()),
            domain: CONFIG.domain.to_string(),
            active: "refs",
            current_dir_file: "/",
            current_dir: "/",
            payment: CONFIG.payment_link.clone(),
            mailing_list: CONFIG.mailing_list.clone(),
            tag: tag,
        },
    ))
}