URL host fix

This commit is contained in:
August 2026-05-06 19:35:00 -04:00
parent dbd4886a4f
commit f16983540a
Signed by: shibedrill
SSH Key Fingerprint: SHA256:M0m3JW1s38BgO2t0fG146Yxd9OJ2IOqkvCAsuRHQ6Pw
3 changed files with 10 additions and 10 deletions

View File

@ -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,
}

View File

@ -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(),

View File

@ -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;