diff --git a/src/app.rs b/src/app.rs index 7a739b2..77f23aa 100644 --- a/src/app.rs +++ b/src/app.rs @@ -41,59 +41,67 @@ async fn checkout_handler(State(state): State, Query(param): Query { - let rpath = repo_path.unwrap().clone(); - let repo = match Repository::open_bare(rpath) { - Ok(repo) => repo, - Err(_) => { - let error_log = "unable to open repo as bare"; - error!("{error_log}"); - response.insert("error".to_string(), json!(error_log)); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(response)) - ); - } - }; - let fpath = format!("master:{}", legit_path); - let obj = match repo.revparse_single(&fpath){ - Ok(obj) => obj, - Err(e) => { - let error_log = format!("unexpected revparse single: {err}", err = e.message()); - error!("{error_log}"); - response.insert("error".to_string(), json!(error_log.clone())); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(response)) - ); - } - }; + let legit_path = param.path.as_str(); - if let Some(blob) = obj.as_blob() { - let content = unsafe { - str::from_utf8_unchecked(blob.content()) - }; - response.insert("result".to_string(), json!(content.to_string())); - } else if let Some(tree) = obj.as_tree() { - let dir_list = tree.iter().map(|x| x.name().unwrap_or("").to_string()).collect::>(); - response.insert("result".to_string(), json!(dir_list)); - } else { - let error_log = "not obj nor tree"; - error!("{error_log}"); - response.insert("error".to_string(), json!(error_log)); - } - } - _ => { - let error_log = "requested path is unexpected"; + // match param.path.as_str() { + // legit_path if param.path.contains("/") || state.check_country_existed(param.path.as_str()) || param.path.is_empty() => { + + // } + // _ => { + // let error_log = "requested path is unexpected"; + // error!("{error_log}"); + // response.insert("error".to_string(), json!(error_log)); + // } + // } + let rpath = repo_path.unwrap().clone(); + let repo = match Repository::open_bare(rpath) { + Ok(repo) => repo, + Err(_) => { + let error_log = "unable to open repo as bare"; error!("{error_log}"); response.insert("error".to_string(), json!(error_log)); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!(response)) + ); } + }; + + let fpath = format!("master:{}", legit_path); + let obj = match repo.revparse_single(&fpath){ + Ok(obj) => obj, + Err(e) => { + let error_log = format!("unexpected revparse single: {err}", err = e.message()); + error!("{error_log}"); + response.insert("error".to_string(), json!(error_log.clone())); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!(response)) + ); + } + }; + + if let Some(blob) = obj.as_blob() { + let content = unsafe { + str::from_utf8_unchecked(blob.content()) + }; + response.insert("result".to_string(), json!(content.to_string())); + } else if let Some(tree) = obj.as_tree() { + let dir_list = tree.iter().map(|x| x.name().unwrap_or("").to_string()).collect::>(); + response.insert("result".to_string(), json!(dir_list)); + } else { + let error_log = "not obj nor tree"; + error!("{error_log}"); + response.insert("error".to_string(), json!(error_log)); + return ( + axum::http::StatusCode::BAD_REQUEST, + Json(json!(response)) + ) } ( - axum::http::StatusCode::BAD_REQUEST, + axum::http::StatusCode::OK, Json(json!(response)) ) }