mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 02:09:06 +00:00
🐞 fix: hostname empty
This commit is contained in:
@@ -226,17 +226,22 @@ impl ConfigLoader for TomlConfigLoader {
|
|||||||
|
|
||||||
match hostname {
|
match hostname {
|
||||||
Some(hostname) => {
|
Some(hostname) => {
|
||||||
let re = regex::Regex::new(r"[^\u4E00-\u9FA5a-zA-Z0-9\-]*").unwrap();
|
if !hostname.is_empty() {
|
||||||
let mut name = re.replace_all(&hostname, "").to_string();
|
let re = regex::Regex::new(r"[^\u4E00-\u9FA5a-zA-Z0-9\-]*").unwrap();
|
||||||
|
let mut name = re.replace_all(&hostname, "").to_string();
|
||||||
|
|
||||||
if name.len() > 32 {
|
if name.len() > 32 {
|
||||||
name = name.chars().take(32).collect::<String>();
|
name = name.chars().take(32).collect::<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if hostname != name {
|
if hostname != name {
|
||||||
self.set_hostname(Some(name.clone()));
|
self.set_hostname(Some(name.clone()));
|
||||||
|
}
|
||||||
|
name
|
||||||
|
} else {
|
||||||
|
self.set_hostname(None);
|
||||||
|
gethostname::gethostname().to_string_lossy().to_string()
|
||||||
}
|
}
|
||||||
name
|
|
||||||
}
|
}
|
||||||
None => gethostname::gethostname().to_string_lossy().to_string(),
|
None => gethostname::gethostname().to_string_lossy().to_string(),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user