Skip to content
Clone
5f84089
46 lines 1.3 KB Rust
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::lfs::LfsLock;
#[derive(Debug, Clone, serde::Deserialize, utoipa::ToSchema)]
pub struct LfsLockBody {
pub path: String,
#[serde(default)]
pub oid: Option<String>,
}
#[utoipa::path(
post,
path = "/repos/{space_name}/{repo_name}/lfs/locks",
tag = "lfs",
description = "为启用 LFS 的仓库路径创建文件锁。",
params(RepoPath),
request_body = LfsLockBody,
responses(
(status = 200, description = "lock lfs path", body = AppResponseData<LfsLock>)
)
)]
pub async fn lock(
State(service): State<GitService>,
session: Session,
Path(path): Path<RepoPath>,
Json(body): Json<LfsLockBody>,
) -> Result<AppResponseData<LfsLock>, ApiError> {
let (_ctx, uid) = require_writer(
&service,
&session,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let out = service
.lfs_lock(path.space_name, path.repo_name, uid, body.path, body.oid)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}