URL host fix
This commit is contained in:
parent
dbd4886a4f
commit
f16983540a
@ -1,12 +1,12 @@
|
|||||||
use crate::{handlers, types::ServerInfo};
|
use crate::{handlers, types::ServerInfo};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{fs::File, path::Path};
|
use std::{fs::File, path::Path};
|
||||||
use url::Url;
|
use url::Host;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct ConfigEntry {
|
pub struct ConfigEntry {
|
||||||
handler_type: String,
|
handler_type: String,
|
||||||
address: Url,
|
address: Host,
|
||||||
token: String,
|
token: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use url::Url;
|
use url::{Host, Url};
|
||||||
|
|
||||||
use crate::types::{ServerInfo, ServerOnlineResponse, ServerResponse};
|
use crate::types::{ServerInfo, ServerOnlineResponse, ServerResponse};
|
||||||
|
|
||||||
@ -49,16 +49,16 @@ pub struct OnlineResponse {
|
|||||||
pub struct Server {
|
pub struct Server {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
token: String,
|
token: String,
|
||||||
addr: Url,
|
addr: Host,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServerInfo for Server {
|
impl ServerInfo for Server {
|
||||||
fn new(token: String, addr: Url) -> Self {
|
fn new(token: String, addr: Host) -> Self {
|
||||||
Server { token, addr }
|
Server { token, addr }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn addressable_name(&self) -> String {
|
fn addressable_name(&self) -> String {
|
||||||
self.addr.clone().into()
|
self.addr.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn app_token(&self) -> String {
|
fn app_token(&self) -> String {
|
||||||
@ -66,7 +66,7 @@ impl ServerInfo for Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn api_address(&self) -> Url {
|
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()
|
Url::parse(&url_string).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ impl ServerInfo for Server {
|
|||||||
let players = parsed_data.players.unwrap();
|
let players = parsed_data.players.unwrap();
|
||||||
let motd = parsed_data.motd.as_ref().unwrap();
|
let motd = parsed_data.motd.as_ref().unwrap();
|
||||||
self::ServerResponse::Online(ServerOnlineResponse {
|
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(),
|
readable_name: motd.clean.first().unwrap().into(),
|
||||||
reported_name: motd.clean.first().unwrap().into(),
|
reported_name: motd.clean.first().unwrap().into(),
|
||||||
clean_name: motd.clean.first().unwrap().into(),
|
clean_name: motd.clean.first().unwrap().into(),
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use url::Url;
|
use url::{Host, Url};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ServerResponse {
|
pub enum ServerResponse {
|
||||||
@ -21,7 +21,7 @@ pub struct ServerOnlineResponse {
|
|||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub trait ServerInfo: Send + Sync {
|
pub trait ServerInfo: Send + Sync {
|
||||||
fn new(token: String, addr: Url) -> Self
|
fn new(token: String, addr: Host) -> Self
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user