11use std:: arch:: asm;
2+ use std:: cell:: RefCell ;
23use std:: net:: SocketAddr ;
34// Import necessary types from the standard library
45use std:: path:: { Path , PathBuf } ;
56use std:: ptr:: addr_of_mut;
6- use std:: sync:: Arc ;
7+ use std:: rc:: Rc ;
8+ use std:: sync:: { Arc , Mutex } ;
79
810use futures:: future:: BoxFuture ;
911use futures:: FutureExt ;
@@ -17,6 +19,7 @@ use tokio::runtime::Runtime;
1719// use crate::llm::llm;
1820use utils:: llm:: count_tokens_rough;
1921
22+ use crate :: compress:: compress:: Identity ;
2023use crate :: compress:: golang;
2124use crate :: compress:: parser:: LanguageParser ;
2225use crate :: utils:: cmd;
@@ -130,6 +133,27 @@ fn code_analyze(ctx: &mut RequestContext) -> BoxFuture<'_, ()> {
130133 } ) . boxed ( )
131134}
132135
136+ // repo_compress handler
137+ fn repo_compress ( ctx : & mut RequestContext ) -> BoxFuture < ' _ , ( ) > {
138+ let parsed: std:: collections:: HashMap < String , String > = serde_urlencoded:: from_str ( ctx. req . uri ( ) . query ( ) . unwrap ( ) ) . unwrap ( ) ;
139+ let repo = parsed. get ( "repo" ) . unwrap ( ) . clone ( ) ;
140+ ( async move {
141+ let repo_dir = check_repo_exist ( & repo) ;
142+
143+ if let Ok ( output) = cmd:: run_command ( "./go_ast" , vec ! [ repo_dir. as_str( ) ] ) {
144+ let mut repo = compress:: compress:: from_json ( output. as_str ( ) ) . unwrap ( ) ;
145+ compress:: compress:: compress_all ( & mut repo) . await ;
146+ let compress = serde_json:: to_string ( & repo) . unwrap ( ) ;
147+ println ! ( "compressed repo:\n {}" , compress) ;
148+
149+ * ctx. resp . body_mut ( ) = Body :: from ( compress) ;
150+ return ;
151+ }
152+
153+ * ctx. resp . body_mut ( ) = Body :: from ( "analyze failed." ) ;
154+ } ) . boxed ( )
155+ }
156+
133157// issue_trace handler
134158fn issue_trace ( ctx : & mut RequestContext ) -> BoxFuture < ' _ , ( ) > {
135159 let parsed: std:: collections:: HashMap < String , String > = serde_urlencoded:: from_str ( ctx. req . uri ( ) . query ( ) . unwrap ( ) ) . unwrap ( ) ;
@@ -182,6 +206,8 @@ async fn main() {
182206 h. get ( "/repo_structure" , Arc :: new ( tree_structure) ) . await ;
183207 h. get ( "/code_analyze" , Arc :: new ( code_analyze) ) . await ;
184208
209+ h. get ( "/repo_compress" , Arc :: new ( repo_compress) ) . await ;
210+
185211
186212 h. spin ( SocketAddr :: from ( ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , 8888 ) ) ) . await . expect ( "TODO: panic message" ) ;
187213
0 commit comments