Skip to content
Clone
ba6fe0f
41 lines 1.2 KB Rust
use export::http::{Path, State};
use export::rest::AppResponseData;
use token::Session;
use crate::errors::{ApiError, GitApiError};
use crate::handler::{RepoPath, require_writer};
use crate::service::GitService;
#[derive(Debug, Clone, serde::Serialize, utoipa::ToSchema)]
pub struct LfsCleanupResponse {
pub removed: i64,
}
#[utoipa::path(
post,
path = "/repos/{space_name}/{repo_name}/lfs/cleanup",
tag = "lfs",
description = "清理 LFS 数据库中失引用记录与存储中的未引用对象。",
params(RepoPath),
responses(
(status = 200, description = "cleanup unreferenced lfs objects", body = AppResponseData<LfsCleanupResponse>)
)
)]
pub async fn cleanup_unreferenced(
State(service): State<GitService>,
session: Session,
Path(path): Path<RepoPath>,
) -> Result<AppResponseData<LfsCleanupResponse>, ApiError> {
require_writer(
&service,
&session,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let removed = service
.lfs_cleanup_unreferenced(path.space_name, path.repo_name)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(LfsCleanupResponse { removed }))
}