feat: set dns by service

This commit is contained in:
MystiPanda
2024-06-28 11:45:44 +08:00
parent b5f7c58276
commit 8f3801e3c2
4 changed files with 41 additions and 53 deletions

View File

@@ -312,3 +312,39 @@ pub(super) async fn stop_core_by_service() -> Result<()> {
Ok(())
}
/// set dns by service
pub fn set_dns_by_service() -> Result<()> {
let url = format!("{SERVICE_URL}/set_dns");
let res = reqwest::blocking::ClientBuilder::new()
.no_proxy()
.build()?
.post(url)
.send()?
.json::<JsonResponse>()
.context("failed to connect to the Clash Verge Service")?;
if res.code != 0 {
bail!(res.msg);
}
Ok(())
}
/// unset dns by service
pub fn unset_dns_by_service() -> Result<()> {
let url = format!("{SERVICE_URL}/unset_dns");
let res = reqwest::blocking::ClientBuilder::new()
.no_proxy()
.build()?
.post(url)
.send()?
.json::<JsonResponse>()
.context("failed to connect to the Clash Verge Service")?;
if res.code != 0 {
bail!(res.msg);
}
Ok(())
}