From 48f1b27d93799b79c59b4d41eea787b3589bf372 Mon Sep 17 00:00:00 2001 From: GyDi Date: Wed, 15 Dec 2021 22:36:13 +0800 Subject: [PATCH] feat: pus_clash_profile support `secret` field --- src-tauri/src/utils/clash.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/utils/clash.rs b/src-tauri/src/utils/clash.rs index d562e34..e216bc6 100644 --- a/src-tauri/src/utils/clash.rs +++ b/src-tauri/src/utils/clash.rs @@ -98,12 +98,19 @@ pub async fn put_clash_profile(payload: &ClashInfoPayload) -> Result<(), String> } fs::copy(file_path, temp_path.clone()).unwrap(); - let server = payload.controller.clone().unwrap().server.unwrap(); - let server = format!("http://{}/configs", server); + let ctrl = payload.controller.clone().unwrap(); + let server = format!("http://{}/configs", ctrl.server.unwrap()); let mut headers = HeaderMap::new(); headers.insert("Content-Type", "application/json".parse().unwrap()); + if let Some(secret) = ctrl.secret { + headers.insert( + "Authorization", + format!("Bearer {}", secret).parse().unwrap(), + ); + } + let mut data = HashMap::new(); data.insert("path", temp_path.as_os_str().to_str().unwrap());