Skip to content

Commit

Permalink
chore(build): fix agent name
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Jun 2, 2024
1 parent 01dc37e commit 430e59b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions ua_generator/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,32 @@ use ureq::get;
#[derive(Deserialize, Serialize, Debug, Default)]
pub struct ApiResult {
/// user agent string id
ua: String,
agent: String,
}

/// get the agent type for version os
pub fn get_agent(url: &str, token: &String) -> String {
let agent: ApiResult = get(&url)
.set("apikey", token)
.call()
.unwrap()
.into_json()
.expect("Authorization not granted! Make sure to set a valid API key.");
match get(&url).set("apikey", token).call() {
Ok(req) => {
let req: ApiResult = req
.into_json()
.expect("Authorization not granted! Make sure to set a valid API key.");

agent.ua
req.agent
}
Err(e) => {
panic!("{:?}", e)
}
}
}

/// build entry for setting required agents
fn main() -> Result<(), Box<dyn std::error::Error>> {
let build_enabled = env::var("BUILD_ENABLED").map(|v| v == "1").unwrap_or(false);

if build_enabled {
let base_api = env::var("API_URL").unwrap_or("https://api.spider.cloud/data/user_agents".into());
let base_api =
env::var("API_URL").unwrap_or("https://api.spider.cloud/data/user_agents".into());

// fetch the latest ua and parse to files.
let token: String = match env::var("APILAYER_KEY") {
Expand Down
2 changes: 1 addition & 1 deletion ua_generator/src/ua_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub const STATIC_AGENTS: &'static [&'static str; 9] = &[
"Mozilla/5.0 (Android 12; Tablet; rv:110.0) Gecko/110.0 Firefox/110.0",
"Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
];
];

/// user agent list
pub fn agents() -> [&'static str; 9] {
Expand Down

0 comments on commit 430e59b

Please sign in to comment.