diff options
| author | Fuwn <[email protected]> | 2022-01-13 18:15:02 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-01-13 18:15:02 -0800 |
| commit | 3f03668096f3265a6014843bfd39c0bdc11a9465 (patch) | |
| tree | e295b216ece83c9dc5a929e0effcd9a2df425998 | |
| parent | fix(rust): toolchain file wrong format again again (diff) | |
| download | api-worker-3f03668096f3265a6014843bfd39c0bdc11a9465.tar.xz api-worker-3f03668096f3265a6014843bfd39c0bdc11a9465.zip | |
fix(utils): user agent ban?
| -rw-r--r-- | src/constants.rs | 1 | ||||
| -rw-r--r-- | src/utils.rs | 10 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/constants.rs b/src/constants.rs index 67e69ab..8fd2f3b 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -5,4 +5,3 @@ pub const GITHUB_USER_CONTENT: &str = "https://raw.githubusercontent.com/laynH/Anime-Girls-Holding-Programming-Books/master/"; pub const GITHUB_API_ENDPOINT: &str = "https://api.github.com/repos/laynH/Anime-Girls-Holding-Progr\ amming-Books/git/trees/master?recursive=1"; -pub const USER_AGENT: &str = env!("CARGO_PKG_NAME"); diff --git a/src/utils.rs b/src/utils.rs index a55ddc6..09c8d49 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only use crate::{ - constants::{GITHUB_API_ENDPOINT, GITHUB_USER_CONTENT, USER_AGENT}, + constants::{GITHUB_API_ENDPOINT, GITHUB_USER_CONTENT}, structures::GitHubAPIResponse, }; @@ -11,7 +11,13 @@ use crate::{ pub async fn github_api() -> Result<GitHubAPIResponse, Box<dyn std::error::Error>> { let mut client = actix_web::client::Client::new() .get(GITHUB_API_ENDPOINT) - .header("User-Agent", USER_AGENT); + .header( + "User-Agent", + format!( + "senpy-api - {}", + (0..10).map(|_| rand::random::<char>()).collect::<String>() + ), + ); if std::env::var("GITHUB_TOKEN").is_ok() { client = client.header( |