@@ -17,7 +17,7 @@ use std::sync::LazyLock;
1717use std:: { io, result:: Result } ;
1818
1919use crate :: dbg_msg;
20- use crate :: oauth:: { force_refresh_token, token_daemon, Oauth } ;
20+ use crate :: oauth:: { force_refresh_token, token_daemon, Oauth , OauthBackendImpl } ;
2121use crate :: server:: RequestExt ;
2222use crate :: utils:: { format_url, Post } ;
2323
@@ -494,11 +494,17 @@ async fn self_check(sub: &str) -> Result<(), String> {
494494}
495495
496496pub async fn rate_limit_check ( ) -> Result < ( ) , String > {
497+ // First, test the Oauth client: we can perform a rate limit check if the OAuth backend is MobileSpoof; if GenericWeb, we skip the check.
498+ if matches ! ( OAUTH_CLIENT . load( ) . backend, OauthBackendImpl :: GenericWeb ( _) ) {
499+ warn ! ( "[⚠️] Cannot perform rate limit check, running as GenericWeb. Skipping check." ) ;
500+ return Ok ( ( ) ) ;
501+ }
502+
497503 // First, check a subreddit.
498504 self_check ( "reddit" ) . await ?;
499505 // This will reduce the rate limit to 99. Assert this check.
500506 if OAUTH_RATELIMIT_REMAINING . load ( Ordering :: SeqCst ) != 99 {
501- return Err ( format ! ( "Rate limit check failed: expected 99, got {}" , OAUTH_RATELIMIT_REMAINING . load( Ordering :: SeqCst ) ) ) ;
507+ return Err ( format ! ( "Rate limit check 1 failed: expected 99, got {}" , OAUTH_RATELIMIT_REMAINING . load( Ordering :: SeqCst ) ) ) ;
502508 }
503509 // Now, we switch out the OAuth client.
504510 // This checks for the IP rate limit association.
@@ -507,7 +513,7 @@ pub async fn rate_limit_check() -> Result<(), String> {
507513 self_check ( "rust" ) . await ?;
508514 // Again, assert the rate limit check.
509515 if OAUTH_RATELIMIT_REMAINING . load ( Ordering :: SeqCst ) != 99 {
510- return Err ( format ! ( "Rate limit check failed: expected 99, got {}" , OAUTH_RATELIMIT_REMAINING . load( Ordering :: SeqCst ) ) ) ;
516+ return Err ( format ! ( "Rate limit check 2 failed: expected 99, got {}" , OAUTH_RATELIMIT_REMAINING . load( Ordering :: SeqCst ) ) ) ;
511517 }
512518
513519 Ok ( ( ) )
0 commit comments