From bfbcc173f88c67bc8e6b3a8079204739f72e7ebc Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Thu, 27 Jan 2022 19:22:48 +0100 Subject: allow retrieving match log for submitted bot --- planetwars-server/src/routes/demo.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'planetwars-server/src/routes') diff --git a/planetwars-server/src/routes/demo.rs b/planetwars-server/src/routes/demo.rs index 16ec8f1..ea57079 100644 --- a/planetwars-server/src/routes/demo.rs +++ b/planetwars-server/src/routes/demo.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use axum::Json; +use axum::{extract::Path, Json}; use hyper::StatusCode; use planetwars_matchrunner::{docker_runner::DockerBotSpec, run_match, MatchConfig, MatchPlayer}; use rand::{distributions::Alphanumeric, Rng}; @@ -68,3 +68,10 @@ pub async fn submit_bot( Ok(Json(SubmitBotResponse { match_id })) } + +// TODO: unify this with existing match API +pub async fn get_submission_match_log(Path(match_id): Path) -> Result { + let log_path = PathBuf::from(MATCHES_DIR).join(format!("{}.log", match_id)); + + std::fs::read_to_string(&log_path).map_err(|_| StatusCode::NOT_FOUND) +} -- cgit v1.2.3