feat: guard the mixed-port and external-controller

This commit is contained in:
GyDi committed 2022-11-22 15:45:17 +08:00
1 parent 89009aa1f8
commit c0d2994b8e
6 files changed
+169 -139

No files matched your search

+4 -14
View File
@@ -38,25 +38,15 @@ pub async fn patch_configs(config: &Mapping) -> Result<()> {
/// 根据clash info获取clash服务地址和请求头
fn clash_client_info() -> Result<(String, HeaderMap)> {
let info = { Config::clash().data().get_info()? };
let client = { Config::clash().data().get_client_info() };
if info.server.is_none() {
let status = &info.status;
if info.port.is_none() {
bail!("failed to parse config.yaml file with status {status}");
} else {
bail!("failed to parse the server with status {status}");
}
}
let server = info.server.unwrap();
let server = format!("http://{server}");
let server = format!("http://{}", client.server);
let mut headers = HeaderMap::new();
headers.insert("Content-Type", "application/json".parse()?);
if let Some(secret) = info.secret.as_ref() {
let secret = format!("Bearer {}", secret.clone()).parse()?;
if let Some(secret) = client.secret {
let secret = format!("Bearer {}", secret).parse()?;
headers.insert("Authorization", secret);
}