allow retrieving match log for submitted bot

This commit is contained in:
Ilion Beyst 2022-01-27 19:22:48 +01:00
parent 4a7229b175
commit bfbcc173f8
2 changed files with 13 additions and 2 deletions

View file

@ -54,7 +54,11 @@ pub async fn api() -> Router {
get(routes::matches::list_matches).post(routes::matches::play_match), get(routes::matches::list_matches).post(routes::matches::play_match),
) )
.route("/matches/:match_id", get(routes::matches::get_match_log)) .route("/matches/:match_id", get(routes::matches::get_match_log))
.route("/submit-bot", post(routes::demo::submit_bot)) .route("/submit_bot", post(routes::demo::submit_bot))
.route(
"/submission_match_log/:match_id",
get(routes::demo::get_submission_match_log),
)
.layer(AddExtensionLayer::new(pool)); .layer(AddExtensionLayer::new(pool));
api api
} }

View file

@ -1,6 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
use axum::Json; use axum::{extract::Path, Json};
use hyper::StatusCode; use hyper::StatusCode;
use planetwars_matchrunner::{docker_runner::DockerBotSpec, run_match, MatchConfig, MatchPlayer}; use planetwars_matchrunner::{docker_runner::DockerBotSpec, run_match, MatchConfig, MatchPlayer};
use rand::{distributions::Alphanumeric, Rng}; use rand::{distributions::Alphanumeric, Rng};
@ -68,3 +68,10 @@ pub async fn submit_bot(
Ok(Json(SubmitBotResponse { match_id })) Ok(Json(SubmitBotResponse { match_id }))
} }
// TODO: unify this with existing match API
pub async fn get_submission_match_log(Path(match_id): Path<String>) -> Result<String, StatusCode> {
let log_path = PathBuf::from(MATCHES_DIR).join(format!("{}.log", match_id));
std::fs::read_to_string(&log_path).map_err(|_| StatusCode::NOT_FOUND)
}