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::archives::{ArchiveOptionsDto, ArchiveResultDto}; #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Deserialize, utoipa::ToSchema)] #[serde(rename_all = "snake_case")] pub enum ArchiveFormatDto { Tar, TarGz, TarBz2, Zip, } impl From for crate::rpcgit::archive::types::ArchiveFormat { fn from(v: ArchiveFormatDto) -> Self { match v { ArchiveFormatDto::Tar => crate::rpcgit::archive::types::ArchiveFormat::Tar, ArchiveFormatDto::TarGz => crate::rpcgit::archive::types::ArchiveFormat::TarGz, ArchiveFormatDto::TarBz2 => crate::rpcgit::archive::types::ArchiveFormat::TarBz2, ArchiveFormatDto::Zip => crate::rpcgit::archive::types::ArchiveFormat::Zip, } } } #[derive(Debug, Clone, serde::Deserialize, utoipa::ToSchema)] pub struct ArchiveCreateCmd { pub revision: String, pub format: ArchiveFormatDto, #[serde(default)] pub path_filter: Option, } #[utoipa::path( post, path = "/repos/{space_name}/{repo_name}/archives", tag = "archives", description = "为指定修订生成归档并上传存储,返回下载地址。", params(RepoPath), request_body = ArchiveCreateCmd, responses( (status = 200, description = "build archive and return download link", body = AppResponseData) ) )] pub async fn create_archive( State(service): State, session: Session, Path(path): Path, Json(cmd): Json, ) -> Result, ApiError> { require_writer( &service, &session, path.space_name.clone(), path.repo_name.clone(), ) .await?; let opts = ArchiveOptionsDto { format: cmd.format.into(), path_filter: cmd.path_filter, }; let out = service .archive_create(path.space_name, path.repo_name, cmd.revision, opts) .await .map_err(GitApiError::from)?; Ok(AppResponseData::ok(out)) }