fix: extern controler api secert with headers

This commit is contained in:
Tunglies 2025-03-05 07:59:16 +08:00
parent f771f4720f
commit b01630d31c
3 changed files with 12 additions and 11 deletions

View File

@ -2,22 +2,17 @@ use super::CmdResult;
use crate::core;
use mihomo_api;
#[tauri::command]
pub async fn get_proxies() -> CmdResult<serde_json::Value> {
let (mihomo_server, _) = core::clash_api::clash_client_info().unwrap();
let mihomo = mihomo_api::MihomoManager::new(mihomo_server);
Ok(mihomo
.refresh_proxies()
.await
.unwrap()
.get_proxies())
let (mihomo_server, headers) = core::clash_api::clash_client_info().unwrap();
let mihomo = mihomo_api::MihomoManager::new(mihomo_server, headers);
Ok(mihomo.refresh_proxies().await.unwrap().get_proxies())
}
#[tauri::command]
pub async fn get_providers_proxies() -> CmdResult<serde_json::Value> {
let (mihomo_server, _) = core::clash_api::clash_client_info().unwrap();
let mihomo = mihomo_api::MihomoManager::new(mihomo_server);
let (mihomo_server, headers) = core::clash_api::clash_client_info().unwrap();
let mihomo = mihomo_api::MihomoManager::new(mihomo_server, headers);
Ok(mihomo
.refresh_providers_proxies()
.await

View File

@ -1,3 +1,4 @@
use reqwest::header::HeaderMap;
use std::{
sync::{Arc, Mutex},
time::Duration,
@ -6,13 +7,14 @@ pub mod model;
pub use model::{MihomoData, MihomoManager};
impl MihomoManager {
pub fn new(mihomo_server: String) -> Self {
pub fn new(mihomo_server: String, headers: HeaderMap) -> Self {
Self {
mihomo_server,
data: Arc::new(Mutex::new(MihomoData {
proxies: serde_json::Value::Null,
providers_proxies: serde_json::Value::Null,
})),
headers: headers,
}
}
@ -39,6 +41,7 @@ impl MihomoManager {
pub async fn refresh_proxies(&self) -> Result<&Self, String> {
let url = format!("{}/proxies", self.mihomo_server);
let response = reqwest::ClientBuilder::new()
.default_headers(self.headers.clone())
.no_proxy()
.timeout(Duration::from_secs(3))
.build()
@ -58,6 +61,7 @@ impl MihomoManager {
pub async fn refresh_providers_proxies(&self) -> Result<&Self, String> {
let url = format!("{}/providers/proxies", self.mihomo_server);
let response = reqwest::ClientBuilder::new()
.default_headers(self.headers.clone())
.no_proxy()
.timeout(Duration::from_secs(3))
.build()

View File

@ -1,4 +1,5 @@
use std::sync::{Arc, Mutex};
use reqwest::header::HeaderMap;
pub struct MihomoData {
pub(crate) proxies: serde_json::Value,
@ -9,6 +10,7 @@ pub struct MihomoData {
pub struct MihomoManager {
pub(crate) mihomo_server: String,
pub(crate) data: Arc<Mutex<MihomoData>>,
pub(crate) headers: HeaderMap,
}
#[cfg(feature = "debug")]