feat(scraper): getuser fetching done

This commit is contained in:
Maieul BOYER 2026-02-08 17:01:27 +01:00
parent 73fe9b85a3
commit e57bb34a35
Signed by: maix
SSH key fingerprint: SHA256:iqCzqFFF5KjRixmDExqbAltCIj9ndlBWIGJf3t9Ln9g
6 changed files with 131 additions and 2 deletions

View file

@ -135,4 +135,40 @@ impl State {
self.request(Method::POST, url.as_ref(), qs, Some(body))
.await
}
pub async fn getuser(&self, name: &str) -> Result<Option<crate::types::Profile>, GetUserError> {
let req = self.get(format!("/getuser/{name}"), None).await?;
let text = req.text().await?;
let json = serde_json::from_str::<crate::types::ProfileRaw>(&text)?;
Ok(Some(crate::types::Profile {
admin: json.admin,
campus: json.campus,
id: json.id,
userid: json.userid,
pool: json.pool.filter(|s| !s.contains("None")),
image: json.image,
image_medium: json.image_medium,
is_friend: match json.is_friend {
crate::types::IsFriend::U32(u) => u != 0,
crate::types::IsFriend::Bool(b) => b,
},
lang: json.lang,
name: json.name,
position: json.position,
active: json.active,
website: json.website.filter(|s| !s.is_empty()),
recit: json.recit.filter(|s| !s.is_empty()),
discord: json.discord.filter(|s| !s.is_empty()),
github: json.github.filter(|s| !s.is_empty()),
}))
}
}
#[derive(Debug, thiserror::Error)]
pub enum GetUserError {
#[error("RequestError: {0}")]
RequestError(#[from] reqwest::Error),
#[error("JsonError: {0}")]
JsonError(#[from] serde_json::Error),
}

View file

@ -61,3 +61,57 @@ pub struct Friend {
pub struct Friends {
pub friends: Vec<Friend>,
}
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
#[serde(untagged)]
pub(crate) enum IsFriend {
U32(u32),
Bool(bool),
}
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub(crate) struct ProfileRaw {
pub(crate) admin: bool,
pub(crate) active: Option<SmolStr>,
pub(crate) campus: u64,
pub(crate) id: u64,
pub(crate) userid: Option<u64>,
pub(crate) image: String,
pub(crate) image_medium: String,
pub(crate) is_friend: IsFriend,
pub(crate) lang: SmolStr,
pub(crate) name: SmolStr,
pub(crate) pool: Option<SmolStr>,
pub(crate) position: Option<SmolStr>,
pub(crate) recit: Option<String>,
pub(crate) website: Option<String>,
pub(crate) discord: Option<String>,
pub(crate) github: Option<String>,
}
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct Profile {
pub admin: bool,
pub campus: u64,
pub id: u64,
pub userid: Option<u64>,
pub pool: Option<SmolStr>,
pub image: String,
pub image_medium: String,
pub is_friend: bool,
pub lang: SmolStr,
pub name: SmolStr,
pub position: Option<SmolStr>,
pub active: Option<SmolStr>,
pub website: Option<String>,
pub recit: Option<String>,
pub discord: Option<String>,
pub github: Option<String>,
}