aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-01-27 19:22:48 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2022-01-27 19:22:48 +0100
commitbfbcc173f88c67bc8e6b3a8079204739f72e7ebc (patch)
tree826b5120970e994985ef25612d057b46950758de
parent4a7229b175abfe782696d29cfe664e092c3d970e (diff)
downloadplanetwars.dev-bfbcc173f88c67bc8e6b3a8079204739f72e7ebc.tar.xz
planetwars.dev-bfbcc173f88c67bc8e6b3a8079204739f72e7ebc.zip
allow retrieving match log for submitted bot
-rw-r--r--planetwars-server/src/lib.rs6
-rw-r--r--planetwars-server/src/routes/demo.rs9
2 files changed, 13 insertions, 2 deletions
diff --git a/planetwars-server/src/lib.rs b/planetwars-server/src/lib.rs
index ea03fc3..90e0b44 100644
--- a/planetwars-server/src/lib.rs
+++ b/planetwars-server/src/lib.rs
@@ -54,7 +54,11 @@ pub async fn api() -> Router {
get(routes::matches::list_matches).post(routes::matches::play_match),
)
.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));
api
}
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<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)
+}