Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
fix(utils): user agent ban?
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuwn committed Jan 14, 2022
1 parent 6b568a3 commit fd98a4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
10 changes: 8 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -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(
Expand Down

0 comments on commit fd98a4e

Please sign in to comment.