@@ -23,12 +23,20 @@ use crate::utils::cmd;
2323use crate :: utils:: files;
2424// Import the git module
2525use crate :: utils:: git;
26+ use crate :: utils:: git:: Repository ;
2627use crate :: utils:: markdown;
2728
2829mod compress;
2930mod utils;
3031
3132
33+ #[ derive( Serialize , Deserialize , Debug ) ]
34+ pub struct BasicInfo {
35+ readme : String ,
36+ repo_stats : Repository ,
37+ }
38+
39+
3240// basic_info handler
3341fn basic_info ( ctx : & mut RequestContext ) -> BoxFuture < ' _ , ( ) > {
3442 let parsed: std:: collections:: HashMap < String , String > = serde_urlencoded:: from_str ( ctx. req . uri ( ) . query ( ) . unwrap ( ) ) . unwrap ( ) ;
@@ -40,8 +48,18 @@ fn basic_info(ctx: &mut RequestContext) -> BoxFuture<'_, ()> {
4048 let repo_dir = check_repo_exist ( & repo) ;
4149
4250 if let Some ( body) = markdown:: get_readme_json ( Path :: new ( repo_dir. as_str ( ) ) ) {
43- * ctx. resp . body_mut ( ) = Body :: from ( body) ;
44- return ( async move { } ) . boxed ( ) ;
51+ let repo = repo. clone ( ) ;
52+ return ( async move {
53+ match git:: get_repo_stats ( repo. as_str ( ) ) . await {
54+ Ok ( repo) => {
55+ println ! ( "Successfully fetched repo stats" ) ;
56+ let mut basic_info = BasicInfo { readme : body, repo_stats : repo } ;
57+ let body = serde_json:: to_string_pretty ( & basic_info) . unwrap ( ) ;
58+ * ctx. resp . body_mut ( ) = Body :: from ( body) ;
59+ }
60+ Err ( e) => eprintln ! ( "Failed to fetch repo stats: {}" , e) ,
61+ } ;
62+ } ) . boxed ( ) ;
4563 }
4664
4765 * ctx. resp . body_mut ( ) = Body :: from ( "Not found README.md in this project." ) ;
0 commit comments