Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions aries/src/service/api/nostr_router.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};
use std::collections::{HashMap, HashSet};

use axum::{
extract::{Query, State},
Expand Down Expand Up @@ -118,7 +115,7 @@ async fn recieve(
}

async fn transfer_event_to_subscribed_nodes(
storage: Arc<ZTMStorage>,
storage: ZTMStorage,
nostr_event: NostrEvent,
ztm_agent_port: u16,
) {
Expand Down
81 changes: 15 additions & 66 deletions ceres/src/api_service/import_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use std::path::PathBuf;

use axum::async_trait;

use callisto::raw_blob;
use common::errors::MegaError;
use jupiter::context::Context;
use mercury::errors::GitError;
use mercury::internal::object::commit::Commit;
Expand All @@ -26,19 +24,16 @@ pub struct ImportApiService {

#[async_trait]
impl ApiHandler for ImportApiService {
fn get_context(&self) -> Context {
self.context.clone()
}

async fn create_monorepo_file(&self, _: CreateFileInfo) -> Result<(), GitError> {
return Err(GitError::CustomError(
"import dir does not support create file".to_string(),
));
}

async fn get_raw_blob_by_hash(&self, hash: &str) -> Result<Option<raw_blob::Model>, MegaError> {
self.context
.services
.mono_storage
.get_raw_blob_by_hash(hash)
.await
}

fn strip_relative(&self, path: &Path) -> Result<PathBuf, GitError> {
if let Ok(relative_path) = path.strip_prefix(self.repo.repo_path.clone()) {
Expand All @@ -49,9 +44,14 @@ impl ApiHandler for ImportApiService {
))
}
}

async fn get_root_commit(&self) -> Commit {
let storage = self.context.services.git_db_storage.clone();
let refs = storage.get_default_ref(self.repo.repo_id).await.unwrap().unwrap();
let refs = storage
.get_default_ref(self.repo.repo_id)
.await
.unwrap()
.unwrap();
storage
.get_commit_by_hash(self.repo.repo_id, &refs.ref_git_id)
.await
Expand All @@ -62,7 +62,11 @@ impl ApiHandler for ImportApiService {

async fn get_root_tree(&self) -> Tree {
let storage = self.context.services.git_db_storage.clone();
let refs = storage.get_default_ref(self.repo.repo_id).await.unwrap().unwrap();
let refs = storage
.get_default_ref(self.repo.repo_id)
.await
.unwrap()
.unwrap();

let root_commit = storage
.get_commit_by_hash(self.repo.repo_id, &refs.ref_git_id)
Expand Down Expand Up @@ -179,58 +183,3 @@ impl ApiHandler for ImportApiService {
target_commit
}
}

impl ImportApiService {
// pub async fn get_objects_data(
// &self,
// object_id: &str,
// repo_path: &str,
// ) -> Result<Response, (StatusCode, String)> {
// let node = match self.storage.get_node_by_hash(object_id, repo_path).await {
// Ok(Some(node)) => node,
// _ => return Err((StatusCode::NOT_FOUND, "Blob not found".to_string())),
// };
// let raw_data = match self.storage.get_obj_data_by_id(object_id).await {
// Ok(Some(model)) => model,
// _ => return Err((StatusCode::NOT_FOUND, "Blob not found".to_string())),
// };
// let file_name = format!("inline; filename=\"{}\"", node.name.unwrap());
// let res = Response::builder()
// .header("Content-Type", "application/octet-stream")
// .header("Content-Disposition", file_name)
// .body(raw_data.data.into())
// .unwrap();
// Ok(res)
// }

// pub async fn count_object_num(
// &self,
// repo_path: &str,
// ) -> Result<Json<GitTypeCounter>, (StatusCode, String)> {
// let query_res = self.storage.count_obj_from_node(repo_path).await.unwrap();
// let tree = query_res
// .iter()
// .find(|x| x.node_type == "tree")
// .map(|x| x.count)
// .unwrap_or_default()
// .try_into()
// .unwrap();
// let blob = query_res
// .iter()
// .find(|x| x.node_type == "blob")
// .map(|x| x.count)
// .unwrap_or_default()
// .try_into()
// .unwrap();
// let commit = self.storage.count_obj_from_commit(repo_path).await.unwrap().try_into().unwrap();
// let counter = GitTypeCounter {
// commit,
// tree,
// blob,
// tag: 0,
// ofs_delta: 0,
// ref_delta: 0,
// };
// Ok(Json(counter))
// }
}
22 changes: 20 additions & 2 deletions ceres/src/api_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ use axum::async_trait;

use callisto::raw_blob;
use common::errors::MegaError;
use jupiter::utils::converter::generate_git_keep_with_timestamp;
use jupiter::{context::Context, utils::converter::generate_git_keep_with_timestamp};
use mercury::{
errors::GitError,
internal::object::{
commit::Commit,
tree::{Tree, TreeItem, TreeItemMode},
ObjectTrait,
},
};

Expand All @@ -26,16 +27,33 @@ pub mod mono_api_service;

#[async_trait]
pub trait ApiHandler: Send + Sync {
fn get_context(&self) -> Context;

async fn create_monorepo_file(&self, file_info: CreateFileInfo) -> Result<(), GitError>;

async fn get_raw_blob_by_hash(&self, hash: &str) -> Result<Option<raw_blob::Model>, MegaError>;
async fn get_raw_blob_by_hash(&self, hash: &str) -> Result<Option<raw_blob::Model>, MegaError> {
let context = self.get_context();
context
.services
.raw_db_storage
.get_raw_blob_by_hash(hash)
.await
}

fn strip_relative(&self, path: &Path) -> Result<PathBuf, GitError>;

async fn get_root_commit(&self) -> Commit;

async fn get_root_tree(&self) -> Tree;

async fn get_tree_as_data(&self, path: &Path) -> Result<Vec<u8>, GitError> {
let res = self.search_tree_by_path(path).await.unwrap();
if let Some(tree) = res {
return tree.to_data();
}
Ok(vec![])
}

async fn get_tree_by_hash(&self, hash: &str) -> Tree;

async fn get_tree_relate_commit(&self, t_hash: &str) -> Commit;
Expand Down
11 changes: 4 additions & 7 deletions ceres/src/api_service/mono_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ pub struct MonoApiService {

#[async_trait]
impl ApiHandler for MonoApiService {
fn get_context(&self) -> Context {
self.context.clone()
}

/// Creates a new file or directory in the monorepo based on the provided file information.
///
/// # Arguments
Expand Down Expand Up @@ -113,13 +117,6 @@ impl ApiHandler for MonoApiService {
Ok(())
}

async fn get_raw_blob_by_hash(&self, hash: &str) -> Result<Option<raw_blob::Model>, MegaError> {
self.context
.services
.mono_storage
.get_raw_blob_by_hash(hash)
.await
}

fn strip_relative(&self, path: &Path) -> Result<PathBuf, GitError> {
Ok(path.to_path_buf())
Expand Down
Loading