aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/modules/bots.rs
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-07-18 21:03:34 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-07-18 21:03:34 +0200
commit7daf8f643798ce76733006f8469890bf1a3fd05e (patch)
treed755c4f0979f56792684b109d263624aef4baaad /planetwars-server/src/modules/bots.rs
parent608d05bc167c57d190d3c06f250b5e4a5662e77e (diff)
parentd092f5d89c0fda5cc67349d5489b4ef1b294e053 (diff)
downloadplanetwars.dev-7daf8f643798ce76733006f8469890bf1a3fd05e.tar.xz
planetwars.dev-7daf8f643798ce76733006f8469890bf1a3fd05e.zip
Merge branch 'next'
Diffstat (limited to 'planetwars-server/src/modules/bots.rs')
-rw-r--r--planetwars-server/src/modules/bots.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/planetwars-server/src/modules/bots.rs b/planetwars-server/src/modules/bots.rs
index 843e48d..5513539 100644
--- a/planetwars-server/src/modules/bots.rs
+++ b/planetwars-server/src/modules/bots.rs
@@ -2,22 +2,25 @@ use std::path::PathBuf;
use diesel::{PgConnection, QueryResult};
-use crate::{db, util::gen_alphanumeric, BOTS_DIR};
+use crate::{db, util::gen_alphanumeric, GlobalConfig};
-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<i32>,
conn: &PgConnection,
-) -> QueryResult<db::bots::CodeBundle> {
+ config: &GlobalConfig,
+) -> QueryResult<db::bots::BotVersion> {
let bundle_name = gen_alphanumeric(16);
- let code_bundle_dir = PathBuf::from(BOTS_DIR).join(&bundle_name);
+ let code_bundle_dir = PathBuf::from(&config.bots_directory).join(&bundle_name);
std::fs::create_dir(&code_bundle_dir).unwrap();
std::fs::write(code_bundle_dir.join("bot.py"), bot_code).unwrap();
- let new_code_bundle = db::bots::NewCodeBundle {
+ let new_code_bundle = db::bots::NewBotVersion {
bot_id,
- path: &bundle_name,
+ code_bundle_path: Some(&bundle_name),
+ container_digest: None,
};
- db::bots::create_code_bundle(&new_code_bundle, conn)
+ db::bots::create_bot_version(&new_code_bundle, conn)
}