Skip to content
Clone
e034b46
39 lines 1.2 KB Rust
use axum::extract::{Path, State};
use axum::http::HeaderValue;
use axum::http::header;
use axum::response::{IntoResponse, Response};
use jwt::extractor::AuthUser;
use uuid::Uuid;
use crate::error::RepoResult;
use crate::features::RepoService;
use crate::features::git_ref::CommitDiffPayload;
#[utoipa::path(
get,
path = "/repo/{channel_id}/{repo_id}/git/commits/{sha}.{diff_type}",
tag = "repo",
responses((status = 200, description = "Get commit diff or patch", body = CommitDiffPayload)),
security(("bearer_auth" = []))
)]
pub(crate) async fn handler(
State(svc): State<RepoService>,
AuthUser { claims }: AuthUser,
Path((_, repo_id, sha_dot_type)): Path<(Uuid, Uuid, String)>,
) -> RepoResult<Response> {
let (sha, diff_type) = sha_dot_type
.rsplit_once('.')
.ok_or_else(|| crate::error::RepoError::BadRequest("expected '<sha>.diff|patch'".into()))?;
let payload = svc
.get_commit_diff_or_patch(claims.sub, repo_id, sha, diff_type)
.await?;
let resp = (
[(
header::CONTENT_TYPE,
HeaderValue::from_static("text/plain; charset=utf-8"),
)],
payload.content,
)
.into_response();
Ok(resp)
}