gitdataai/libs/service/git/init.rs
ZhenYi 14f6e1e500 feat(core): initialize project with access control and AI integration
- Add gitignore and prettier configuration files for project scaffolding
- Implement room access control service with project member verification
- Create user access key management with CRUD operations and activity logging
- Add accordion UI component for frontend expandable sections
- Implement room AI configuration with list, upsert, and delete operations
- Add AI event types for agent join/leave/status change tracking
- Create streaming AI processing services for mode and react patterns
- Build room AI service with model detection and idempotency handling
- Integrate chat service orchestration for AI message processing
- Add typing indicators and stream cancellation for AI interactions
- Implement mention parsing and context extraction for AI agents
2026-05-03 06:04:31 +08:00

70 lines
2.4 KiB
Rust

use crate::AppService;
use crate::error::AppError;
use serde::{Deserialize, Serialize};
use session::Session;
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct GitInitResponse {
pub path: String,
pub is_bare: bool,
}
#[derive(Debug, Clone, Deserialize, utoipa::ToSchema)]
pub struct GitInitRequest {
pub path: String,
#[serde(default)]
pub bare: bool,
#[serde(default)]
pub initial_branch: Option<String>,
}
impl AppService {
pub async fn git_init_bare(
&self,
request: GitInitRequest,
ctx: &Session,
) -> Result<GitInitResponse, AppError> {
let _user_uid = ctx.user().ok_or(AppError::Unauthorized)?;
let domain = git::GitDomain::init_bare(&request.path).map_err(AppError::from)?;
Ok(GitInitResponse {
path: domain.repo().path().to_string_lossy().to_string(),
is_bare: true,
})
}
pub async fn git_open(&self, path: String, ctx: &Session) -> Result<GitInitResponse, AppError> {
let _user_uid = ctx.user().ok_or(AppError::Unauthorized)?;
let domain = git::GitDomain::open(&path).map_err(AppError::from)?;
Ok(GitInitResponse {
path: domain.repo().path().to_string_lossy().to_string(),
is_bare: domain.repo().is_bare(),
})
}
pub async fn git_open_bare(&self, path: String, ctx: &Session) -> Result<GitInitResponse, AppError> {
let _user_uid = ctx.user().ok_or(AppError::Unauthorized)?;
let domain = git::GitDomain::open_bare(&path).map_err(AppError::from)?;
Ok(GitInitResponse {
path: domain.repo().path().to_string_lossy().to_string(),
is_bare: true,
})
}
pub async fn git_is_repo(&self, path: String, ctx: &Session) -> Result<bool, AppError> {
let _user_uid = ctx.user().ok_or(AppError::Unauthorized)?;
match git::GitDomain::open(&path) {
Ok(_) => Ok(true),
Err(git::GitError::NotFound(_)) => Ok(false),
Err(git::GitError::IoError(_)) => Ok(false),
Err(e) => Err(AppError::from(e)),
}
}
pub async fn git_repo_path(
&self,
namespace: String,
repo_name: String,
ctx: &Session,
) -> Result<String, AppError> {
let repo = self.utils_find_repo(namespace, repo_name, ctx).await?;
Ok(repo.storage_path)
}
}