use crate::{ApiResponse, error::ApiError}; use actix_web::{HttpResponse, Result, web}; use service::AppService; use service::git::archive::{ ArchiveCachedResponse, ArchiveInvalidateAllResponse, ArchiveInvalidateResponse, ArchiveListResponse, ArchiveQuery, ArchiveResponse, ArchiveSummaryResponse, }; use session::Session; #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/archive", params( ("namespace" = String, Path), ("repo" = String, Path), ("commit_oid" = String, Query), ("format" = String, Query), ("prefix" = Option, Query), ("max_depth" = Option, Query), ("path_filter" = Option, Query), ), responses( (status = 200, description = "Get archive", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_archive( service: web::Data, session: Session, path: web::Path<(String, String)>, query: web::Query, ) -> Result { let (namespace, repo_name) = path.into_inner(); let resp = service .git_archive(namespace, repo_name, query.into_inner(), &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/archive/list", params( ("namespace" = String, Path), ("repo" = String, Path), ("commit_oid" = String, Query), ("format" = String, Query), ("prefix" = Option, Query), ("max_depth" = Option, Query), ("path_filter" = Option, Query), ), responses( (status = 200, description = "List archive entries", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_archive_list( service: web::Data, session: Session, path: web::Path<(String, String)>, query: web::Query, ) -> Result { let (namespace, repo_name) = path.into_inner(); let resp = service .git_archive_list(namespace, repo_name, query.into_inner(), &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/archive/summary", params( ("namespace" = String, Path), ("repo" = String, Path), ("commit_oid" = String, Query), ("format" = String, Query), ("prefix" = Option, Query), ("max_depth" = Option, Query), ("path_filter" = Option, Query), ), responses( (status = 200, description = "Get archive summary", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_archive_summary( service: web::Data, session: Session, path: web::Path<(String, String)>, query: web::Query, ) -> Result { let (namespace, repo_name) = path.into_inner(); let resp = service .git_archive_summary(namespace, repo_name, query.into_inner(), &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/archive/cached", params( ("namespace" = String, Path), ("repo" = String, Path), ("commit_oid" = String, Query), ("format" = String, Query), ("prefix" = Option, Query), ("max_depth" = Option, Query), ("path_filter" = Option, Query), ), responses( (status = 200, description = "Check if archive is cached", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_archive_cached( service: web::Data, session: Session, path: web::Path<(String, String)>, query: web::Query, ) -> Result { let (namespace, repo_name) = path.into_inner(); let resp = service .git_archive_cached(namespace, repo_name, query.into_inner(), &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/archive/invalidate", params( ("namespace" = String, Path), ("repo" = String, Path), ("commit_oid" = String, Query), ("format" = String, Query), ("prefix" = Option, Query), ("max_depth" = Option, Query), ("path_filter" = Option, Query), ), responses( (status = 200, description = "Invalidate archive cache", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_archive_invalidate( service: web::Data, session: Session, path: web::Path<(String, String)>, query: web::Query, ) -> Result { let (namespace, repo_name) = path.into_inner(); let resp = service .git_archive_invalidate(namespace, repo_name, query.into_inner(), &session) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/repos/{namespace}/{repo}/git/archive/invalidate/{commit_oid}", params( ("namespace" = String, Path), ("repo" = String, Path), ("commit_oid" = String, Path), ), responses( (status = 200, description = "Invalidate all archive caches for commit", body = ApiResponse), (status = 401, description = "Unauthorized", body = ApiResponse), (status = 404, description = "Not found", body = ApiResponse), ), tag = "Git" )] pub async fn git_archive_invalidate_all( service: web::Data, session: Session, path: web::Path<(String, String, String)>, ) -> Result { let (namespace, repo_name, commit_oid) = path.into_inner(); let resp = service .git_archive_invalidate_all(namespace, repo_name, commit_oid, &session) .await?; Ok(ApiResponse::ok(resp).to_response()) }