Skip to content

Commit 4eb0bfa

Browse files
committed
cleanup
1 parent 0e1c4d2 commit 4eb0bfa

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

apps/desktop/src-tauri/src/web_api.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,35 @@ impl From<String> for AuthedApiError {
3939
}
4040
}
4141

42+
fn apply_env_headers(req: reqwest::RequestBuilder) -> reqwest::RequestBuilder {
43+
let mut req = req.header("X-Cap-Desktop-Version", env!("CARGO_PKG_VERSION"));
44+
45+
if let Ok(s) = std::env::var("VITE_VERCEL_AUTOMATION_BYPASS_SECRET") {
46+
req = req.header("x-vercel-protection-bypass", s);
47+
}
48+
49+
req
50+
}
51+
4252
async fn do_authed_request(
4353
auth: &AuthStore,
4454
build: impl FnOnce(reqwest::Client, String) -> reqwest::RequestBuilder,
4555
url: String,
4656
) -> Result<reqwest::Response, reqwest::Error> {
4757
let client = reqwest::Client::new();
4858

49-
let mut req = build(client, url)
50-
.header(
51-
"Authorization",
52-
format!(
53-
"Bearer {}",
54-
match &auth.secret {
55-
AuthSecret::ApiKey { api_key } => api_key,
56-
AuthSecret::Session { token, .. } => token,
57-
}
58-
),
59-
)
60-
.header("X-Cap-Desktop-Version", env!("CARGO_PKG_VERSION"));
61-
62-
if let Ok(s) = std::env::var("VITE_VERCEL_AUTOMATION_BYPASS_SECRET") {
63-
req = req.header("x-vercel-protection-bypass", s);
64-
}
65-
66-
req.send().await
59+
let req = build(client, url).header(
60+
"Authorization",
61+
format!(
62+
"Bearer {}",
63+
match &auth.secret {
64+
AuthSecret::ApiKey { api_key } => api_key,
65+
AuthSecret::Session { token, .. } => token,
66+
}
67+
),
68+
);
69+
70+
apply_env_headers(req).send().await
6771
}
6872

6973
pub trait ManagerExt<R: Runtime>: Manager<R> {
@@ -113,13 +117,7 @@ impl<T: Manager<R> + Emitter<R>, R: Runtime> ManagerExt<R> for T {
113117
let url = self.make_app_url(path.into()).await;
114118
let client = reqwest::Client::new();
115119

116-
let mut req = build(client, url).header("X-Cap-Desktop-Version", env!("CARGO_PKG_VERSION"));
117-
118-
if let Ok(s) = std::env::var("VITE_VERCEL_AUTOMATION_BYPASS_SECRET") {
119-
req = req.header("x-vercel-protection-bypass", s);
120-
}
121-
122-
req.send().await
120+
apply_env_headers(build(client, url)).send().await
123121
}
124122

125123
async fn make_app_url(&self, pathname: impl AsRef<str>) -> String {

0 commit comments

Comments
 (0)