From 0f14dee499f48b11fc329164c30cd475400a9f4d Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Thu, 7 Jul 2022 19:13:55 +0200 Subject: [PATCH] refactor: rename save_code_bundle to save_code_string --- planetwars-server/src/lib.rs | 2 +- planetwars-server/src/modules/bots.rs | 3 ++- planetwars-server/src/routes/bots.rs | 4 ++-- planetwars-server/src/routes/demo.rs | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/planetwars-server/src/lib.rs b/planetwars-server/src/lib.rs index 7076604..fdaf800 100644 --- a/planetwars-server/src/lib.rs +++ b/planetwars-server/src/lib.rs @@ -51,7 +51,7 @@ pub async fn seed_simplebot(pool: &ConnectionPool) { let simplebot_code = std::fs::read_to_string(SIMPLEBOT_PATH).expect("could not read simplebot code"); - modules::bots::save_code_bundle(&simplebot_code, Some(simplebot.id), &conn)?; + modules::bots::save_code_string(&simplebot_code, Some(simplebot.id), &conn)?; println!("initialized simplebot"); diff --git a/planetwars-server/src/modules/bots.rs b/planetwars-server/src/modules/bots.rs index 629ecf6..b82ad41 100644 --- a/planetwars-server/src/modules/bots.rs +++ b/planetwars-server/src/modules/bots.rs @@ -4,7 +4,8 @@ use diesel::{PgConnection, QueryResult}; use crate::{db, util::gen_alphanumeric, BOTS_DIR}; -pub fn save_code_bundle( +/// Save a string containing bot code as a code bundle. +pub fn save_code_string( bot_code: &str, bot_id: Option, conn: &PgConnection, diff --git a/planetwars-server/src/routes/bots.rs b/planetwars-server/src/routes/bots.rs index 54c0d36..edb68ae 100644 --- a/planetwars-server/src/routes/bots.rs +++ b/planetwars-server/src/routes/bots.rs @@ -14,7 +14,7 @@ use thiserror; use crate::db::bots::{self, BotVersion}; use crate::db::ratings::{self, RankedBot}; use crate::db::users::User; -use crate::modules::bots::save_code_bundle; +use crate::modules::bots::save_code_string; use crate::{DatabaseConnection, BOTS_DIR}; use bots::Bot; @@ -120,7 +120,7 @@ pub async fn save_bot( } }; let _code_bundle = - save_code_bundle(¶ms.code, Some(bot.id), &conn).expect("failed to save code bundle"); + save_code_string(¶ms.code, Some(bot.id), &conn).expect("failed to save code bundle"); Ok(Json(bot)) } diff --git a/planetwars-server/src/routes/demo.rs b/planetwars-server/src/routes/demo.rs index 1747bfe..4f83de0 100644 --- a/planetwars-server/src/routes/demo.rs +++ b/planetwars-server/src/routes/demo.rs @@ -1,6 +1,6 @@ use crate::db; use crate::db::matches::{FullMatchData, FullMatchPlayerData}; -use crate::modules::bots::save_code_bundle; +use crate::modules::bots::save_code_string; use crate::modules::matches::{MatchPlayer, RunMatch}; use crate::ConnectionPool; use axum::extract::Extension; @@ -42,7 +42,7 @@ pub async fn submit_bot( let opponent_bot_version = db::bots::active_bot_version(opponent.id, &conn).map_err(|_| StatusCode::BAD_REQUEST)?; - let player_bot_version = save_code_bundle(¶ms.code, None, &conn) + let player_bot_version = save_code_string(¶ms.code, None, &conn) // TODO: can we recover from this? .expect("could not save bot code");