ew/src/router/start.rs

85 lines
2.8 KiB
Rust
Raw Normal View History

2024-02-23 15:59:55 +00:00
use json;
use json::object;
use crate::router::global;
use crate::encryption;
2024-03-29 00:37:06 +00:00
use actix_web::{HttpResponse, HttpRequest, http::header::HeaderValue};
use crate::router::userdata;
2024-02-23 15:59:55 +00:00
2024-03-29 00:37:06 +00:00
pub fn asset_hash(req: HttpRequest, body: String) -> HttpResponse {
2024-02-23 15:59:55 +00:00
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
2024-03-28 16:12:10 +00:00
if body["asset_version"].to_string() != global::ASSET_VERSION && body["asset_version"].to_string() != global::ASSET_VERSION_JP {
2024-02-23 15:59:55 +00:00
println!("Warning! Asset version is not what was expected. (Did the app update?)");
}
2024-03-29 00:37:06 +00:00
let blank_header = HeaderValue::from_static("");
2024-04-09 01:30:58 +00:00
let platform = req.headers().get("aoharu-platform").unwrap_or(&blank_header).to_str().unwrap_or("");
let android = !platform.to_lowercase().contains("iphone");
2024-03-29 00:37:06 +00:00
2024-03-28 16:12:10 +00:00
let hash = if body["asset_version"].to_string() == global::ASSET_VERSION_JP {
2024-03-29 00:37:06 +00:00
if android {
global::ASSET_HASH_ANDROID_JP
} else {
global::ASSET_HASH_IOS_JP
}
2024-03-28 16:12:10 +00:00
} else {
2024-04-02 17:35:00 +00:00
if android {
global::ASSET_HASH_ANDROID
} else {
global::ASSET_HASH_IOS
}
2024-03-28 16:12:10 +00:00
};
2024-02-23 15:59:55 +00:00
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": {
2024-03-28 16:12:10 +00:00
"asset_hash": hash
2024-02-23 15:59:55 +00:00
}
};
global::send(resp)
}
pub fn start(req: HttpRequest, body: String) -> HttpResponse {
let key = global::get_login(req.headers(), &body);
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
2024-03-28 16:12:10 +00:00
if body["asset_version"].to_string() != global::ASSET_VERSION && body["asset_version"].to_string() != global::ASSET_VERSION_JP {
println!("Warning! Asset version is not what was expected. (Did the app update?)");
}
2024-03-28 16:12:10 +00:00
let mut user = userdata::get_acc(&key);
2024-04-09 00:18:24 +00:00
println!("Signin from uid: {}", user["user"]["id"].clone());
user["user"]["last_login_time"] = global::timestamp().into();
user["stamina"]["last_updated_time"] = global::timestamp().into();
2024-03-29 00:37:06 +00:00
let blank_header = HeaderValue::from_static("");
2024-04-09 01:30:58 +00:00
let platform = req.headers().get("aoharu-platform").unwrap_or(&blank_header).to_str().unwrap_or("");
let android = !platform.to_lowercase().contains("iphone");
2024-03-29 00:37:06 +00:00
2024-03-28 16:12:10 +00:00
let hash = if body["asset_version"].to_string() == global::ASSET_VERSION_JP {
2024-03-29 00:37:06 +00:00
if android {
global::ASSET_HASH_ANDROID_JP
} else {
global::ASSET_HASH_IOS_JP
}
2024-03-28 16:12:10 +00:00
} else {
2024-04-02 17:35:00 +00:00
if android {
global::ASSET_HASH_ANDROID
} else {
global::ASSET_HASH_IOS
}
2024-03-28 16:12:10 +00:00
};
userdata::save_acc(&key, user);
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
"data": {
2024-03-28 16:12:10 +00:00
"asset_hash": hash,
"token": hex::encode("Hello") //what is this?
}
};
global::send(resp)
}