Skip to content
Clone
951a522
44 lines 1.2 KB Rust
use axum::extract::{Path, State};
use export::rest::AppResponseData;
use jwt::Session;
use crate::errors::{ApiError, GitApiError};
use crate::handler::resolve_reader;
use crate::service::GitService;
use crate::service::blobs::BlobContentDto;
#[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)]
pub struct BlobPath {
pub space_name: String,
pub repo_name: String,
pub oid: String,
}
#[utoipa::path(
get,
path = "/repos/{space_name}/{repo_name}/blobs/{oid}/content",
tag = "blobs",
description = "读取 Blob 原始内容,超过配置上限时截断并标记。",
params(BlobPath),
responses(
(status = 200, description = "blob content", body = AppResponseData<BlobContentDto>)
)
)]
pub async fn blob_content(
State(service): State<GitService>,
session: Session,
Path(path): Path<BlobPath>,
) -> Result<AppResponseData<BlobContentDto>, ApiError> {
let _ = resolve_reader(
&service,
&session,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let out = service
.blob_content(path.space_name, path.repo_name, path.oid)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}