ef0b83a
use ::session::Session;
use export::http::{Json, Path, State};
use export::rest::AppResponseData;
use crate::errors::{ApiError, GitApiError};
use crate::handler::{RepoPath, require_writer};
use crate::service::GitService;
use crate::service::content::WriteObjectResultDto;
#[derive(Debug, Clone, serde::Deserialize, utoipa::ToSchema)]
pub struct WriteBlobBody {
pub data: String,
}
#[utoipa::path(
post,
path = "/repos/{space_name}/{repo_name}/contents/blobs",
tag = "content",
description = "向 Git 对象库写入 Blob 并返回对象 ID,不移动引用。",
params(RepoPath),
request_body = WriteBlobBody,
responses(
(status = 200, description = "write blob object", body = AppResponseData<WriteObjectResultDto>)
)
)]
pub async fn write_blob(
State(service): State<GitService>,
session: Session,
Path(path): Path<RepoPath>,
Json(body): Json<WriteBlobBody>,
) -> Result<AppResponseData<WriteObjectResultDto>, ApiError> {
require_writer(
&service,
&session,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let out = service
.write_blob(path.space_name, path.repo_name, body.data.into_bytes())
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}