use crate::models::common::DEFAULT_REVISION; use actix_web::{HttpResponse, web}; use serde::Deserialize; use utoipa::IntoParams; use crate::api::response::ApiResponse; use crate::error::AppError; use crate::service::AppService; use crate::session::Session; #[derive(Debug, Deserialize, IntoParams)] pub struct PathParams { pub workspace_name: String, pub repo_name: String, } #[derive(Debug, Deserialize, IntoParams)] pub struct RawBlobQuery { pub revision: Option, pub path: String, } #[utoipa::path( get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/raw-blob", tag = "Git", operation_id = "gitRawBlob", params(PathParams, RawBlobQuery), responses((status = 200, content_type = "application/octet-stream")), security(("session_cookie" = [])) )] pub async fn git_raw_blob( service: web::Data, session: Session, path: web::Path, q: web::Query, ) -> Result { let r = service .repo .git_get_raw_blob( &session, &path.workspace_name, &path.repo_name, q.revision.as_deref().unwrap_or(DEFAULT_REVISION), &q.path, ) .await?; Ok(HttpResponse::Ok() .content_type("application/octet-stream") .body(r)) } #[derive(Debug, Deserialize, IntoParams)] pub struct FileMetaQuery { pub revision: Option, pub path: String, } #[utoipa::path( get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/file-metadata", tag = "Git", operation_id = "gitFileMetadata", params(PathParams, FileMetaQuery), responses(( status = 200, body = ApiResponse )), security(("session_cookie" = [])) )] pub async fn git_file_metadata( service: web::Data, session: Session, path: web::Path, q: web::Query, ) -> Result { let r = service .repo .git_get_file_metadata( &session, &path.workspace_name, &path.repo_name, q.revision.as_deref().unwrap_or(DEFAULT_REVISION), &q.path, ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(r))) } #[derive(Debug, Deserialize, IntoParams)] pub struct FindFilesQuery { pub revision: Option, pub pattern: String, } #[utoipa::path( get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/find-files", tag = "Git", operation_id = "gitFindFiles", params(PathParams, FindFilesQuery), responses(( status = 200, body = ApiResponse )), security(("session_cookie" = [])) )] pub async fn git_find_files( service: web::Data, session: Session, path: web::Path, q: web::Query, ) -> Result { let r = service .repo .git_find_files( &session, &path.workspace_name, &path.repo_name, q.revision.as_deref().unwrap_or(DEFAULT_REVISION), &q.pattern, ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(r))) } #[derive(Debug, Deserialize, IntoParams)] pub struct GetTreeQuery { pub revision: Option, pub path: Option, } #[utoipa::path( get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/get-tree", tag = "Git", operation_id = "gitGetTree", params(PathParams, GetTreeQuery), responses((status = 200, body = ApiResponse)), security(("session_cookie" = [])) )] pub async fn git_get_tree( service: web::Data, session: Session, path: web::Path, q: web::Query, ) -> Result { let r = service .repo .git_get_tree( &session, &path.workspace_name, &path.repo_name, q.revision.as_deref().unwrap_or(DEFAULT_REVISION), q.path.as_deref().unwrap_or(""), ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(r))) }