Skip to content

Commit 9a63d8a

Browse files
authored
fix(confirm): fix confirmations not working because of changes to /mobileconf/multiajaxop endpoint (#439)
fixes #438
1 parent d864e1d commit 9a63d8a

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

src/commands/confirm.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ where
7474
let mut any_failed = false;
7575

7676
fn submit_loop(
77-
f: impl Fn() -> Result<(), ConfirmerError>,
77+
submit: impl Fn() -> Result<(), ConfirmerError>,
7878
fail_fast: bool,
7979
) -> Result<(), ConfirmerError> {
8080
let mut attempts = 0;
8181
loop {
82-
match f() {
82+
match submit() {
8383
Ok(_) => break,
8484
Err(ConfirmerError::InvalidTokens) => {
8585
error!("Invalid tokens, but they should be valid already. This is weird, stopping.");
@@ -116,7 +116,7 @@ where
116116
if self.accept_all {
117117
info!("accepting all confirmations");
118118
match submit_loop(
119-
|| confirmer.accept_confirmations(&confirmations),
119+
|| confirmer.accept_confirmations_bulk(&confirmations),
120120
self.fail_fast,
121121
) {
122122
Ok(_) => {}
@@ -130,7 +130,10 @@ where
130130
}
131131
} else if std::io::stdout().is_tty() {
132132
let (accept, deny) = tui::prompt_confirmation_menu(confirmations)?;
133-
match submit_loop(|| confirmer.accept_confirmations(&accept), self.fail_fast) {
133+
match submit_loop(
134+
|| confirmer.accept_confirmations_bulk(&accept),
135+
self.fail_fast,
136+
) {
134137
Ok(_) => {}
135138
Err(err) => {
136139
warn!("accept confirmation result: {}", err);
@@ -140,7 +143,7 @@ where
140143
any_failed = true;
141144
}
142145
}
143-
match submit_loop(|| confirmer.deny_confirmations(&deny), self.fail_fast) {
146+
match submit_loop(|| confirmer.deny_confirmations_bulk(&deny), self.fail_fast) {
144147
Ok(_) => {}
145148
Err(err) => {
146149
warn!("deny confirmation result: {}", err);

steamguard/src/confirmation.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ where
147147
)
148148
.header(USER_AGENT, "steamguard-cli")
149149
.header(COOKIE, cookies.cookies(&STEAM_COOKIE_URL).unwrap())
150+
.header("Origin", "https://steamcommunity.com")
150151
.query(&query_params)
151152
.send()?;
152153

@@ -226,6 +227,7 @@ where
226227
CONTENT_TYPE,
227228
"application/x-www-form-urlencoded; charset=UTF-8",
228229
)
230+
.header("Origin", "https://steamcommunity.com")
229231
.body(query_params)
230232
.send()?;
231233

@@ -255,11 +257,39 @@ where
255257
Ok(())
256258
}
257259

260+
/// Bulk accept confirmations.
261+
///
262+
/// Sends one request per confirmation.
258263
pub fn accept_confirmations(&self, confs: &[Confirmation]) -> Result<(), ConfirmerError> {
259-
self.send_multi_confirmation_ajax(confs, ConfirmationAction::Accept)
264+
for conf in confs {
265+
self.accept_confirmation(conf)?;
266+
}
267+
268+
Ok(())
260269
}
261270

271+
/// Bulk deny confirmations.
272+
///
273+
/// Sends one request per confirmation.
262274
pub fn deny_confirmations(&self, confs: &[Confirmation]) -> Result<(), ConfirmerError> {
275+
for conf in confs {
276+
self.deny_confirmation(conf)?;
277+
}
278+
279+
Ok(())
280+
}
281+
282+
/// Bulk accept confirmations.
283+
///
284+
/// Uses a different endpoint than `accept_confirmation()` to submit multiple confirmations in one request.
285+
pub fn accept_confirmations_bulk(&self, confs: &[Confirmation]) -> Result<(), ConfirmerError> {
286+
self.send_multi_confirmation_ajax(confs, ConfirmationAction::Accept)
287+
}
288+
289+
/// Bulk deny confirmations.
290+
///
291+
/// Uses a different endpoint than `deny_confirmation()` to submit multiple confirmations in one request.
292+
pub fn deny_confirmations_bulk(&self, confs: &[Confirmation]) -> Result<(), ConfirmerError> {
263293
self.send_multi_confirmation_ajax(confs, ConfirmationAction::Deny)
264294
}
265295

0 commit comments

Comments
 (0)