feat: allow getting user profile via json api
This commit is contained in:
parent
5d9c016e8e
commit
82a81422d6
6 changed files with 21 additions and 8 deletions
|
|
@ -1 +1,2 @@
|
||||||
pub mod oauth;
|
pub mod oauth;
|
||||||
|
pub mod users;
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
pub mod generate_token;
|
pub mod generate_token;
|
||||||
|
|
||||||
|
|
|
||||||
1
src/json_api/users/mod.rs
Normal file
1
src/json_api/users/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
pub mod profile;
|
||||||
10
src/json_api/users/profile.rs
Normal file
10
src/json_api/users/profile.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
use rocket::serde::json::Json;
|
||||||
|
use rocket::{get, State};
|
||||||
|
use crate::account::account::Auth;
|
||||||
|
use crate::nnid::people::{build_profile, GetOwnProfileData};
|
||||||
|
use crate::Pool;
|
||||||
|
|
||||||
|
#[get("/api/v2/users/@me/profile")]
|
||||||
|
pub async fn get_own_profile(pool: &State<Pool>, auth: Auth<true>) -> Json<GetOwnProfileData> {
|
||||||
|
Json(build_profile(auth.into()))
|
||||||
|
}
|
||||||
|
|
@ -149,6 +149,7 @@ async fn launch() -> _ {
|
||||||
nnid::provider::get_service_token,
|
nnid::provider::get_service_token,
|
||||||
nnid::mapped_ids::mapped_ids,
|
nnid::mapped_ids::mapped_ids,
|
||||||
json_api::oauth::generate_token::generate_token,
|
json_api::oauth::generate_token::generate_token,
|
||||||
|
json_api::users::profile::get_own_profile,
|
||||||
papi::login::login,
|
papi::login::login,
|
||||||
papi::user::get_user,
|
papi::user::get_user,
|
||||||
// graphql::graphiql,
|
// graphql::graphiql,
|
||||||
|
|
|
||||||
|
|
@ -266,20 +266,20 @@ pub struct GetOwnProfileData{
|
||||||
|
|
||||||
#[get("/v1/api/people/@me/profile")]
|
#[get("/v1/api/people/@me/profile")]
|
||||||
pub fn get_own_profile(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
|
pub fn get_own_profile(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
|
||||||
build_own_profile(user.into())
|
Ds(Xml(build_profile(user.into())))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/v1/api/people/@me/devices/owner")]
|
#[get("/v1/api/people/@me/devices/owner")]
|
||||||
pub fn get_device_owner(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
|
pub fn get_device_owner(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
|
||||||
build_own_profile(user.into())
|
Ds(Xml(build_profile(user.into())))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/v1/api/people/@me/devices")]
|
#[post("/v1/api/people/@me/devices")]
|
||||||
pub fn get_own_device(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
|
pub fn get_own_device(user: Auth<false>) -> Ds<Xml<GetOwnProfileData>>{
|
||||||
build_own_profile(user.into())
|
Ds(Xml(build_profile(user.into())))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_own_profile(user: User) -> Ds<Xml<GetOwnProfileData>> {
|
pub fn build_profile(user: User) -> GetOwnProfileData {
|
||||||
let User {
|
let User {
|
||||||
username,
|
username,
|
||||||
pid,
|
pid,
|
||||||
|
|
@ -309,7 +309,7 @@ fn build_own_profile(user: User) -> Ds<Xml<GetOwnProfileData>> {
|
||||||
.replace("\r", "")
|
.replace("\r", "")
|
||||||
.replace(" ", "");
|
.replace(" ", "");
|
||||||
|
|
||||||
Ds(Xml(
|
|
||||||
GetOwnProfileData {
|
GetOwnProfileData {
|
||||||
active_flag: YesNoVal(true),
|
active_flag: YesNoVal(true),
|
||||||
pid,
|
pid,
|
||||||
|
|
@ -361,7 +361,6 @@ fn build_own_profile(user: User) -> Ds<Xml<GetOwnProfileData>> {
|
||||||
region,
|
region,
|
||||||
utc_offset: timezone_offset,
|
utc_offset: timezone_offset,
|
||||||
}
|
}
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/v1/api/people/@me/miis/@primary", data = "<data>")]
|
#[put("/v1/api/people/@me/miis/@primary", data = "<data>")]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue