From 6d01fe61122fc3903d02c541de17d9f240521c29 Mon Sep 17 00:00:00 2001 From: MedzikUser Date: Thu, 27 Jan 2022 16:49:47 +0100 Subject: [PATCH] cli: add url validate --- CHANGELOG.md | 6 +++--- Cargo.toml | 1 + src/cli/upload_image.rs | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58adb20..7411ae5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] -- SimpleLogger init error handling - ### CLI +- SimpleLogger init error handling - better panic - panic instead of send log error +- add url validate ### Library - The returned error in the Result is from now on anyhow::Error and not String. @@ -31,7 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - move api request to fn send_api_request ### Fixed -* api rate limit (error decoding response body: invalid value: integer \`200\`, expected i8 at line 1 column 140) +- api rate limit (error decoding response body: invalid value: integer \`200\`, expected i8 at line 1 column 140) ## [0.1.0] - 2022-01-23 ### CLI diff --git a/Cargo.toml b/Cargo.toml index c78f58e..bc020e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ notify-rust = "4.5.5" clap_complete = "3.0.5" anyhow = "1.0.53" better-panic = "0.3.0" +validator = "0.14.0" [dependencies.clap] version = "3.0.13" diff --git a/src/cli/upload_image.rs b/src/cli/upload_image.rs index bd5de71..3751ee2 100644 --- a/src/cli/upload_image.rs +++ b/src/cli/upload_image.rs @@ -13,6 +13,8 @@ pub async fn upload_image(client: ImgurClient, path: &str) { .map_err(|err| err.to_string()) .expect("read file"); image = base64_encode(bytes); + } else if !validator::validate_url(path) { + panic!("{path} is not a url") } let i = upload_img(client, &image).await.expect("send api request");