ew/src/router/user.rs
2024-02-26 01:10:34 -06:00

47 lines
1.7 KiB
Rust

use json;
use json::object;
use crate::router::global;
use crate::encryption;
use actix_web::{HttpResponse, HttpRequest, http::header::HeaderValue};
use crate::router::userdata;
pub fn user(req: HttpRequest) -> HttpResponse {
let blank_header = HeaderValue::from_static("");
let key = req.headers().get("a6573cbe").unwrap_or(&blank_header).to_str().unwrap_or("");
let uid = req.headers().get("aoharu-user-id").unwrap_or(&blank_header).to_str().unwrap_or("");
let user = userdata::get_acc(key, uid);
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": user
};
global::send(resp)
}
pub fn initialize(req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
let blank_header = HeaderValue::from_static("");
let key = req.headers().get("a6573cbe").unwrap_or(&blank_header).to_str().unwrap_or("");
let uid = req.headers().get("aoharu-user-id").unwrap_or(&blank_header).to_str().unwrap_or("");
let mut user = userdata::get_acc(key, uid);
let id = (body["master_character_id"].as_i32().unwrap() * 10000) + 7; //todo - is this alwasy the case?
user["user"]["favorite_master_card_id"] = id.into();
user["user"]["guest_smile_master_card_id"] = id.into();
user["user"]["guest_cool_master_card_id"] = id.into();
user["user"]["guest_pure_master_card_id"] = id.into();
user["user"]["master_title_ids"][0] = id.into();
userdata::save_acc(key, uid, user.clone());
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": user["user"].clone()
};
global::send(resp)
}