index : gitrs
A lightweight web interface for browsing Git repositories, implemented in Rust
about summary refs log tree commit diff
gitrs / src / routes / repository / snapshot.rs
-rw-r--r-- blob e5d56024eb069cdfe436276e4b9d0f218426e746 603 bytes (plain)
1
use crate::{prelude::*, routes::PageQuery};
2
3
#[get("/{repo}/snapshot/")]
4
pub async fn download(
5
    path: web::Path<String>,
6
    query: web::Query<PageQuery>,
7
    data: web::Data<App>,
8
) -> Result<HttpResponse, Error> {
9
    let repo = data.get_repo(&path)?;
10
    let current_ref = Ref::resolve(&repo, &query)?;
11
    let (bytes, filename) = repo.archive(&current_ref, &query.id)?;
12
13
    Ok(HttpResponse::Ok()
14
        .content_type("application/gzip")
15
        .append_header((
16
            "Content-Disposition",
17
            format!(r#"attachment; filename="{filename}""#),
18
        ))
19
        .body(bytes))
20
}