From ce412a450ead2eb2a20d6897ba8fa072a59fe1cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20=C4=8Carneck=C3=BD?= Date: Sun, 19 Apr 2026 22:34:08 +0200 Subject: [PATCH] Change type of input in CaptureRequest (#49) --- Cargo.lock | 2 ++ Cargo.toml | 4 ++-- src/v1.rs | 8 +++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8a244dc..64f4bd0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2062,6 +2062,7 @@ dependencies = [ "schemars_derive", "serde", "serde_json", + "url", "uuid", ] @@ -2875,6 +2876,7 @@ dependencies = [ "idna", "percent-encoding", "serde", + "serde_derive", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index adf29fa..2f42a55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,11 +11,11 @@ serde = "1.0.228" serde_json = "1.0.149" tracing = "0.1.44" tracing-subscriber = { version = "0.3.23", features = ["env-filter"] } -url = "2.5.8" +url = { version = "2.5.8", features = ["serde"] } futures = "0.3.32" base64 = "0.22.1" http = "1.4.0" -schemars = "0.8.22" +schemars = { version = "0.8.22", features = ["url"] } hex = "0.4.3" chromiumoxide_cdp = "0.9.1" tokio = { version = "1.52.0", features = ["full"] } diff --git a/src/v1.rs b/src/v1.rs index 878036f..5353aff 100644 --- a/src/v1.rs +++ b/src/v1.rs @@ -51,7 +51,7 @@ pub enum Target { #[derive(Deserialize, JsonSchema)] pub struct CaptureRequest { pub device: Device, - pub input: String, + pub input: Url, pub target: Target, } @@ -161,9 +161,7 @@ pub async fn capture( body: TypedBody, ) -> Result, HttpError> { let req = body.into_inner(); - let parsed_url = Url::parse(&req.input) - .map_err(|_| HttpError::for_bad_request(None, "Invalid URL".to_string()))?; - let hostname = parsed_url.host_str().unwrap_or(""); + let hostname = req.input.host_str().unwrap_or(""); let authorizer = authorizer!( r#" @@ -214,7 +212,7 @@ pub async fn capture( HttpError::for_internal_error("Failed to create event listener".to_string()) })?; - let res = page.goto(&req.input).await; + let res = page.goto(req.input.as_str()).await; if res.is_ok() { let wait_result = timeout(Duration::from_secs(10), async { -- 2.51.2