mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Implement /api/home/preset
This commit is contained in:
parent
fcaf7f449a
commit
faab8c12e6
2 changed files with 45 additions and 0 deletions
|
@ -81,6 +81,12 @@ async fn mission(req: HttpRequest) -> HttpResponse { router::mission::mission(re
|
|||
#[get("/api/home")]
|
||||
async fn home(req: HttpRequest) -> HttpResponse { router::home::home(req) }
|
||||
|
||||
#[get("/api/home/preset")]
|
||||
async fn preset_get(req: HttpRequest) -> HttpResponse { router::home::preset_get(req) }
|
||||
|
||||
#[post("/api/home/preset")]
|
||||
async fn preset(req: HttpRequest, body: String) -> HttpResponse { router::home::preset(req, body) }
|
||||
|
||||
#[post("/api/lottery/get_tutorial")]
|
||||
async fn lottery_tutorial(req: HttpRequest, body: String) -> HttpResponse { router::lottery::tutorial(req, body) }
|
||||
|
||||
|
@ -125,6 +131,8 @@ async fn main() -> std::io::Result<()> {
|
|||
println!("Request: {}", req.path());
|
||||
srv.call(req)
|
||||
})
|
||||
.service(preset)
|
||||
.service(preset_get)
|
||||
.service(gree_init)
|
||||
.service(debug_error)
|
||||
.service(login_bonus)
|
||||
|
|
|
@ -1,9 +1,46 @@
|
|||
use json;
|
||||
use json::object;
|
||||
use crate::router::global;
|
||||
use crate::encryption;
|
||||
use actix_web::{HttpResponse, HttpRequest};
|
||||
use crate::router::userdata;
|
||||
|
||||
pub fn preset(req: HttpRequest, body: String) -> HttpResponse {
|
||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||
let key = global::get_login(req.headers());
|
||||
let mut user = userdata::get_acc_home(&key);
|
||||
|
||||
for (_i, data) in user["home"]["preset_setting"].members_mut().enumerate() {
|
||||
if data["slot"].to_string() == body["slot"].to_string() {
|
||||
*data = body.clone();
|
||||
}
|
||||
}
|
||||
userdata::save_acc_home(&key, user);
|
||||
|
||||
let resp = object!{
|
||||
"code": 0,
|
||||
"server_time": global::timestamp(),
|
||||
"data": []
|
||||
};
|
||||
global::send(resp)
|
||||
}
|
||||
|
||||
pub fn preset_get(req: HttpRequest) -> HttpResponse {
|
||||
let key = global::get_login(req.headers());
|
||||
let user = userdata::get_acc(&key);
|
||||
|
||||
let resp = object!{
|
||||
"code": 0,
|
||||
"server_time": global::timestamp(),
|
||||
"data": {
|
||||
"master_preset_background_ids": [1,2,3,4,5],
|
||||
"master_preset_foreground_ids": [1,2,3],
|
||||
"card_list": user["card_list"].clone()
|
||||
}
|
||||
};
|
||||
global::send(resp)
|
||||
}
|
||||
|
||||
pub fn home(req: HttpRequest) -> HttpResponse {
|
||||
let key = global::get_login(req.headers());
|
||||
let user = userdata::get_acc_home(&key);
|
||||
|
|
Loading…
Add table
Reference in a new issue