From f16983540a1512340b21d76a49af4c12405445f1 Mon Sep 17 00:00:00 2001 From: August Date: Wed, 6 May 2026 19:35:00 -0400 Subject: [PATCH] URL host fix --- src/config_parser.rs | 4 ++-- src/handlers/minecraft.rs | 12 ++++++------ src/types.rs | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/config_parser.rs b/src/config_parser.rs index c3d3c2d..66c376a 100644 --- a/src/config_parser.rs +++ b/src/config_parser.rs @@ -1,12 +1,12 @@ use crate::{handlers, types::ServerInfo}; use serde::Deserialize; use std::{fs::File, path::Path}; -use url::Url; +use url::Host; #[derive(Deserialize)] pub struct ConfigEntry { handler_type: String, - address: Url, + address: Host, token: String, } diff --git a/src/handlers/minecraft.rs b/src/handlers/minecraft.rs index f490073..ea3af66 100644 --- a/src/handlers/minecraft.rs +++ b/src/handlers/minecraft.rs @@ -1,6 +1,6 @@ use serde::Deserialize; use serde_json; -use url::Url; +use url::{Host, Url}; use crate::types::{ServerInfo, ServerOnlineResponse, ServerResponse}; @@ -49,16 +49,16 @@ pub struct OnlineResponse { pub struct Server { #[allow(dead_code)] token: String, - addr: Url, + addr: Host, } impl ServerInfo for Server { - fn new(token: String, addr: Url) -> Self { + fn new(token: String, addr: Host) -> Self { Server { token, addr } } fn addressable_name(&self) -> String { - self.addr.clone().into() + self.addr.to_string() } fn app_token(&self) -> String { @@ -66,7 +66,7 @@ impl ServerInfo for Server { } fn api_address(&self) -> Url { - let url_string = format!("https://api.mcsrvstat.us/3/{}", self.addr.host().unwrap()); + let url_string = format!("https://api.mcsrvstat.us/3/{}", self.addr); Url::parse(&url_string).unwrap() } @@ -77,7 +77,7 @@ impl ServerInfo for Server { let players = parsed_data.players.unwrap(); let motd = parsed_data.motd.as_ref().unwrap(); self::ServerResponse::Online(ServerOnlineResponse { - searchable_name: self.addr.host().unwrap().to_string(), + searchable_name: self.addr.to_string(), readable_name: motd.clean.first().unwrap().into(), reported_name: motd.clean.first().unwrap().into(), clean_name: motd.clean.first().unwrap().into(), diff --git a/src/types.rs b/src/types.rs index 949a185..8484758 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,4 +1,4 @@ -use url::Url; +use url::{Host, Url}; #[derive(Debug)] pub enum ServerResponse { @@ -21,7 +21,7 @@ pub struct ServerOnlineResponse { #[allow(dead_code)] pub trait ServerInfo: Send + Sync { - fn new(token: String, addr: Url) -> Self + fn new(token: String, addr: Host) -> Self where Self: Sized;