From 7267b44e9d32deb027d0822b6dd92e9c65614156 Mon Sep 17 00:00:00 2001 From: networkjanitor Date: Tue, 30 Jul 2024 23:53:53 +0200 Subject: feat: add dps.report upload url configuration --- src/config.rs | 7 +++++++ src/main.rs | 9 ++++----- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 1c44aea..ad2ee22 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,6 +9,9 @@ use serde_with::{serde_as, OneOrMany}; pub struct Config { /// Flag indicating whether logs should be uploaded or not. pub upload: bool, + /// Where to upload the logs. + #[serde(default = "default_dps_report_upload_url")] + pub dps_report_upload_url: String, /// Flag indicating whether logs with an unknown boss should be uploaded. #[serde(default)] pub upload_unknown: bool, @@ -62,3 +65,7 @@ pub fn load>(path: P) -> Result { fn default_zip() -> bool { true } + +fn default_dps_report_upload_url() -> String { + String::from("https://dps.report/uploadContent") +} diff --git a/src/main.rs b/src/main.rs index b86f281..6352bff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,6 @@ mod logbag; #[cfg(feature = "im-matrix")] mod matrix; -const DPS_REPORT_API: &str = "https://dps.report/uploadContent"; const WATCH_DELAY_SECONDS: u64 = 2; const RETRY_DELAY: Duration = Duration::from_secs(5); @@ -83,7 +82,7 @@ fn inner_main(opts: &Opts) -> Result<()> { match &opts.subcmd { SubCommand::Watch(w) => watch(w, &config)?, SubCommand::Upload(u) => { - let permalink = upload_log(&u.path)?; + let permalink = upload_log(&u.path, &config.dps_report_upload_url)?; println!("{}", permalink); let log = load_log(&u.path)?; @@ -181,7 +180,7 @@ fn handle_file(config: &Config, filename: &Path) -> Result<()> { let mut try_counter = 0; let permalink = loop { - let result = upload_log(filename); + let result = upload_log(filename, &config.dps_report_upload_url); if let Ok(link) = result { break link; } @@ -238,7 +237,7 @@ fn load_log(path: &Path) -> Result { evtclib::process_file(path, Compression::Zip).map_err(Into::into) } -fn upload_log(file: &Path) -> Result { +fn upload_log(file: &Path, url: &str) -> Result { #[derive(Debug, Deserialize)] struct ApiResponse { permalink: String, @@ -248,7 +247,7 @@ fn upload_log(file: &Path) -> Result { let form = reqwest::blocking::multipart::Form::new().file("file", file)?; let resp: ApiResponse = client - .post(DPS_REPORT_API) + .post(url) .query(&[("json", 1)]) .multipart(form) .send()? -- cgit v1.2.3