feat(people): add the devices/owner route

This commit is contained in:
Andrea Toska 2025-04-26 18:16:34 +02:00
commit 9608823d06
No known key found for this signature in database
GPG key ID: 5B3C83807CCBE9A2

View file

@ -261,6 +261,15 @@ struct GetOwnProfileData{
#[get("/v1/api/people/@me/profile")]
pub fn get_own_profile(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
build_own_profile(user)
}
#[get("/v1/api/people/@me/devices/owner")]
pub fn get_device_owner(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
build_own_profile(user)
}
fn build_own_profile(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>> {
let User {
username,
pid,
@ -283,10 +292,6 @@ pub fn get_own_profile(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
let timezone_offset = (&*OFFSET_FROM_TIMEZONE).get(&timezone).unwrap().to_owned();
// whenever we need an id or hash we just take the gxhash of the data cause i dont want data clutter
// this both avoids the data we have to store as well as data clutter whilest keeping the ids
// always the same
let mii_data = mii_data
.replace("\n", "")
.replace("\t", "")
@ -319,13 +324,12 @@ pub fn get_own_profile(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
},
mii: MiiDataOwnProfileData {
id: gxhash32(mii_data.as_bytes(), 0),
// the bitmask here is to avoid causing an too big number as we dont know if the
// wii u uses a 64 bit int here
mii_hash: hex::encode(bytemuck::bytes_of(
&(gxhash64(mii_data.as_bytes(), 1) & !(0x1000000000000000))
)),
name: mii::MiiData::read(&mii_data)
.map(|v| v.name).unwrap_or("INVALID".to_string()),
.map(|v| v.name)
.unwrap_or_else(|| "INVALID".to_string()),
primary: YesNoVal(true),
data: mii_data,
status: "COMPLETED".to_string(),
@ -342,7 +346,6 @@ pub fn get_own_profile(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
}
}
},
off_device_flag: YesNoVal(off_device_allowed),
region,
utc_offset: timezone_offset,
@ -350,6 +353,7 @@ pub fn get_own_profile(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
))
}
#[put("/v1/api/people/@me/miis/@primary")]
pub fn change_mii() {
// stubbed(tecnically requires auth but this doesnt do anything so theres no harm in not doing auth here rn)