mirror of
https://github.com/ApfelTeeSaft/ia-get.git
synced 2026-08-26 19:23:36 +00:00
refactor: improve archive.org URL validation
- Improves archive.org URL validation to ensure the identifier after "/details/" is not empty. - Updates error message for invalid URLs to provide a more descriptive explanation of the expected format. - Streamlines error handling in the main function by directly displaying the error message from the validation function.
This commit is contained in:
committed by
Martin Wimpress
parent
d7211b3dab
commit
3bc46f8f9d
+1
-1
@@ -17,7 +17,7 @@ pub enum IaGetError {
|
||||
FileSystem(String),
|
||||
|
||||
/// URL format or parsing errors
|
||||
#[error("Invalid URL: {0}")]
|
||||
#[error("Invalid archive.org URL: {0}. Expected format: https://archive.org/details/<identifier>[/]")]
|
||||
UrlFormat(String),
|
||||
|
||||
/// MD5 hash verification failures
|
||||
|
||||
+1
-3
@@ -119,9 +119,7 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
// Validate URL format using consolidated function
|
||||
if let Err(e) = validate_archive_url(&cli.url) {
|
||||
spinner.finish_with_message(format!("❌ Invalid archive.org URL format: {}", cli.url));
|
||||
println!("├╼ Archive.org URL is not in the expected format");
|
||||
println!("╰╼ Expected format: https://archive.org/details/<identifier>[/]");
|
||||
spinner.finish_with_message(format!("❌ {}", e));
|
||||
return Err(e.into());
|
||||
}
|
||||
|
||||
|
||||
+8
-6
@@ -33,13 +33,15 @@ static URL_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
||||
/// ```
|
||||
pub fn validate_archive_url(url: &str) -> Result<()> {
|
||||
if URL_REGEX.is_match(url) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(IaGetError::UrlFormat(format!(
|
||||
"URL '{}' does not match expected format. Expected: https://archive.org/details/<identifier>[/]",
|
||||
url
|
||||
)))
|
||||
// Further check: ensure there's an identifier after "details/"
|
||||
// and that the identifier is not empty.
|
||||
if let Some(path_segment) = url.split("/details/").nth(1) {
|
||||
if !path_segment.trim_end_matches('/').is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(IaGetError::UrlFormat(url.to_string()))
|
||||
}
|
||||
|
||||
/// Create a progress bar with consistent styling
|
||||
|
||||
Reference in New Issue
Block a user