feat!: distinguish URLs and hosts

BREAKING CHANGE: the configuration for Bitmagnet and Ntfy has changed.
Instead of `host`, they now use `url`.
This commit is contained in:
Marc Plano-Lesay 2025-05-22 21:57:51 +10:00
parent 01fecffc90
commit bb32cfdf97
Signed by: kernald
GPG key ID: 66A41B08CC62A6CF
10 changed files with 59 additions and 50 deletions

View file

@ -1,14 +1,9 @@
use crate::actions::bitmagnet::BitmagnetConfig;
use crate::config::Validate;
use crate::errors::{self};
use color_eyre::eyre::Result;
use url::Url;
impl Validate for BitmagnetConfig {
fn validate(&self) -> Result<()> {
Url::parse(&self.host.to_string())
.map_err(|e| errors::config_error(e, &format!("Invalid URL format: {}", self.host)))?;
Ok(())
}
}
@ -16,12 +11,12 @@ impl Validate for BitmagnetConfig {
#[cfg(test)]
mod tests {
use super::*;
use crate::config::types::Host;
use url::Url;
fn create_valid_config() -> Result<BitmagnetConfig> {
Ok(BitmagnetConfig {
enable: true,
host: Host::try_new("http://localhost:8080")?,
url: Url::parse("http://localhost:8080")?,
})
}
@ -36,13 +31,8 @@ mod tests {
#[test]
fn test_invalid_url() -> Result<()> {
let config = BitmagnetConfig {
enable: true,
host: Host::try_new("not a url")?,
};
assert!(config.validate().is_err());
// This test is no longer needed as the Url type handles validation
// and will not allow invalid URLs to be created
Ok(())
}
}