Get and store steam username and display it on the homepage

This commit is contained in:
Lol3rrr
2024-09-10 17:48:06 +02:00
parent d3658be232
commit 9a033b7190
15 changed files with 528 additions and 103 deletions

View File

@@ -34,3 +34,35 @@ pub async fn get_demo_from_upload(name: &str, mut form: axum::extract::Multipart
}
pub mod api;
pub mod steam_api {
use serde::Deserialize;
pub struct Client {
http: reqwest::Client,
api_key: String,
}
#[derive(Debug, Deserialize)]
struct Response<T> {
response: T,
}
impl Client {
pub fn new<IS>(api_key: IS) -> Self where IS: Into<String> {
Self {
http: reqwest::Client::new(),
api_key: api_key.into(),
}
}
pub async fn get<T>(&self, path: &str, args: &[(&str, &str)]) -> Result<T, ()> where T: serde::de::DeserializeOwned {
let response = self.http.get(path).query(&[("key", &self.api_key)]).query(args).send().await.map_err(|e| ())?;
if !response.status().is_success() {
dbg!(&response);
return Err(());
}
response.json::<Response<T>>().await.map(|r| r.response).map_err(|e| ())
}
}
}