Partially implement /api/user/detail

This commit is contained in:
Ethan O'Brien 2024-04-08 15:57:57 -05:00
parent 299e60e4d5
commit e13c9133b4
4 changed files with 79 additions and 2 deletions

View file

@ -81,6 +81,9 @@ async fn story_read(req: HttpRequest, body: String) -> HttpResponse { router::st
#[post("/api/user/initialize")]
async fn user_initialize(req: HttpRequest, body: String) -> HttpResponse { router::user::initialize(req, body) }
#[post("/api/user/detail")]
async fn user_detail(req: HttpRequest, body: String) -> HttpResponse { router::user::detail(req, body) }
#[post("/api/deck")]
async fn user_deck(req: HttpRequest, body: String) -> HttpResponse { router::user::deck(req, body) }
@ -215,6 +218,7 @@ async fn main() -> std::io::Result<()> {
.service(user)
.service(user_post)
.service(user_deck)
.service(user_detail)
.service(dummy_login)
.service(getmigrationcode)
.service(registerpassword)

View file

@ -325,7 +325,7 @@ pub fn payment_ticket(req: HttpRequest) -> HttpResponse {
.insert_header(("Expires", "-1"))
.insert_header(("Pragma", "no-cache"))
.insert_header(("Cache-Control", "must-revalidate, no-cache, no-store, private"))
.insert_header(("Vary", "Authorization"))//AUAWGAPYYUGYYGA7
.insert_header(("Vary", "Authorization"))
.insert_header(("X-GREE-Authorization", gree_authorize(&req)))
.body(json::stringify(resp))
}

View file

@ -197,7 +197,6 @@ pub fn request_migration_code(_req: HttpRequest, body: String) -> HttpResponse {
pub fn migration(_req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
//UYWMGAMIMQQUPG67
let user = userdata::get_name_and_rank(body["user_id"].to_string().parse::<i64>().unwrap());
let resp = object!{
@ -208,6 +207,46 @@ pub fn migration(_req: HttpRequest, body: String) -> HttpResponse {
global::send(resp)
}
pub fn detail(_req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
let mut user_detail_list = array![];
for (_i, data) in body["user_ids"].members().enumerate() {
let uid = data.as_i64().unwrap();
let user = userdata::get_acc_from_uid(uid);
//to finish
let mut to_push = object!{
user: user["user"].clone(),
live_data_summary: {
clear_count_list:[0, 0, 0, 0],
full_combo_list: [0, 0, 0, 0],
all_perfect_list:[0, 0, 0, 0],
high_score_rate: {
rate: 0,
detail:[]
}
},
master_title_ids: user["master_title_ids"].clone()
};
to_push["user"].remove("sif_user_id");
to_push["user"].remove("ss_user_id");
to_push["user"].remove("birthday");
user_detail_list.push(to_push).unwrap();
}
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": {
user_detail_list: user_detail_list
}
};
global::send(resp)
//toadd
//[{"favorite_card":{"id":3034894,"master_card_id":40020012,"exp":1440761,"skill_exp":167600,"evolve":[{"type":2,"count":1}],"created_date_time":1702635055},"guest_smile_card":{"id":3804922,"master_card_id":40030012,"exp":1440761,"skill_exp":167600,"evolve":[{"type":2,"count":1}],"created_date_time":1709288297},"guest_cool_card":{"id":2803327,"master_card_id":20080014,"exp":1440761,"skill_exp":167600,"evolve":[{"type":2,"count":1}],"created_date_time":1697711812},"guest_pure_card":{"id":3034894,"master_card_id":40020012,"exp":1440761,"skill_exp":167600,"evolve":[{"type":2,"count":1}],"created_date_time":1702635055},"main_deck_detail":{"total_power":124202,"deck":{"slot":5,"leader_role":0,"main_card_ids":[2994288,3814592,3660086,3802270,3802268,3802269,3804922,2994287,2864405]},"card_list":[{"id":2864405,"master_card_id":10030016,"exp":1440761,"skill_exp":167600,"evolve":[{"type":2,"count":1}],"created_date_time":1697846611},{"id":2994287,"master_card_id":30060010,"exp":1440761,"skill_exp":167600,"evolve":[{"type":2,"count":1}],"created_date_time":1699711194},{"id":2994288,"master_card_id":30090011,"exp":1440761,"skill_exp":167600,"evolve":[{"type":2,"count":1}],"created_date_time":1699711244},{"id":3660086,"master_card_id":20010019,"exp":1440761,"skill_exp":167600,"evolve":[{"type":2,"count":1}],"created_date_time":1704448015},{"id":3802268,"master_card_id":10020018,"exp":1440761,"skill_exp":167600,"evolve":[{"type":2,"count":1}],"created_date_time":1708752744},{"id":3802269,"master_card_id":30010019,"exp":1440761,"skill_exp":167600,"evolve":[{"type":2,"count":1}],"created_date_time":1708752757},{"id":3802270,"master_card_id":20060017,"exp":1440761,"skill_exp":167600,"evolve":[{"type":2,"count":1}],"created_date_time":1708752771},{"id":3814592,"master_card_id":30030010,"exp":1440761,"skill_exp":167600,"evolve":[{"type":2,"count":1}],"created_date_time":1710039197},{"id":3804922,"master_card_id":40030012,"exp":1440761,"skill_exp":167600,"evolve":[{"type":2,"count":1}],"created_date_time":1709288297}]}}]
}
pub fn initialize(req: HttpRequest, body: String) -> HttpResponse {
let key = global::get_login(req.headers(), &body);

View file

@ -346,3 +346,37 @@ pub fn get_name_and_rank(uid: i64) -> JsonValue {
}
}
}
pub fn get_acc_from_uid(uid: i64) -> JsonValue {
loop {
match ENGINE.lock() {
Ok(mut result) => {
if result.is_none() {
init(&mut result);
}
let conn = result.as_ref().unwrap();
create_migration_store(conn);
let login_token = get_login_token(conn, uid);
if login_token == String::new() {
return object!{
user_name: "",
user_rank: 1
}
}
let uid = get_uid(conn, &login_token);
if uid == 0 || !acc_exists(conn, uid) {
return object!{"error": true}
}
let mut stmt = conn.prepare(&format!("SELECT jsondata FROM _{}_", uid)).unwrap();
let result: Result<String, rusqlite::Error> = stmt.query_row([], |row| row.get(0));
let data = json::parse(&result.unwrap()).unwrap();
return data["userdata"].clone();
}
Err(_) => {
std::thread::sleep(std::time::Duration::from_millis(15));
}
}
}
}