diff --git a/Cargo.lock b/Cargo.lock index d11b776..24c0043 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "mastodon-image-uploader-bot" -version = "0.3.0" +version = "0.3.1" dependencies = [ "async-std", "log", diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..5ceb8fd --- /dev/null +++ b/compose.yaml @@ -0,0 +1,39 @@ +version: "3" + +services: + mongodb: + image: mongo:bionic + container_name: mongodb + ports: + - "27017:27017" + environment: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: password + MONGO_INITDB_DATABASE: bot + volumes: + - mongodb_data:/data/db + + bot-api: + image: git.fai.st/fedi-image-bot/bot-api:v1.0.0 + container_name: bot-api + ports: + - "8080:8080" + depends_on: + - mongodb + environment: + MONGODB_URI: "mongodb://mongodb:27017/bot" + MONGODB_USER: "root" + MONGODB_PASS: "password" + JWTSECRET: "cooljwtsecret" + + bot: + image: rust + container_name: bot + working_dir: /app + depends_on: + - bot-api + volumes: + - ./:/app:rw + +volumes: + mongodb_data: \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 433851f..5eb458e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use std::io::{Cursor, Write}; use std::process::exit; use std::time::Duration; -#[derive(Debug, Serialize)] +#[derive(Serialize)] struct AccountUpdate { note: String, } @@ -16,28 +16,28 @@ const CONFIG_FILENAME: &str = "config.toml"; type DynResult = Result>; -#[derive(Deserialize)] +#[derive(Deserialize, Serialize, Default)] struct Config { bot: Bot, files: Files, errors: Errors, } -#[derive(Deserialize)] +#[derive(Deserialize, Serialize, Default)] struct Bot { name: String, instance: String, bio: String, } -#[derive(Deserialize)] +#[derive(Deserialize, Serialize, Default)] struct Files { posted: String, urls: String, tempfile: String, } -#[derive(Deserialize)] +#[derive(Deserialize, Serialize, Default)] struct Errors { maintainers: String, out_of_images: String, @@ -129,11 +129,26 @@ fn get_config() -> Config { Ok(config) => config, Err(err) => { log::error!("Config file parsing unsuccesful: {}", err); + generate_config().unwrap(); + log::info!("Please check the working directory to find a new config file"); exit(1); } } } +fn generate_config() -> DynResult<()> { + let config = Config::default(); + let config = toml::to_string(&config)?; + std::fs::write(CONFIG_FILENAME, &config)?; + Ok(()) +} + +/// Parses the given filename to a config struct +fn parse_config(filename: &str) -> DynResult { + let toml_file = std::fs::read_to_string(filename)?; //.expect("No config file, consider getting the original one and modifing it"); + Ok(toml::from_str(&toml_file)?) //("Malformed config file, check the original one for reference") +} + async fn get_account(config: &Config) -> Mastodon { if let Ok(data) = masto_toml::from_file("mastodon-data.toml") { Mastodon::from(data) @@ -148,11 +163,6 @@ async fn get_account(config: &Config) -> Mastodon { } } -/// Parses the given filename to a config struct -fn parse_config(filename: &str) -> DynResult { - let toml_file = std::fs::read_to_string(filename)?; //.expect("No config file, consider getting the original one and modifing it"); - Ok(toml::from_str(&toml_file)?) //("Malformed config file, check the original one for reference") -} fn get_next_url(config: &Config) -> DynResult> { let binding = std::fs::read_to_string(&config.files.posted)?; //.expect("Posted file not found");