Implement /api/start/assetHash
This commit is contained in:
24
src/router/global.rs
Normal file
24
src/router/global.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use json::JsonValue;
|
||||
use crate::encryption;
|
||||
use actix_web::{
|
||||
HttpResponse
|
||||
};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
//likely different between ios and android?
|
||||
pub const ASSET_VERSION: &str = "4a802a747076a91e5e62707f6358bc2d";
|
||||
pub const ASSET_HASH: &str = "183931205c9dbc39788ef7b361988cf4";
|
||||
|
||||
pub fn timestamp() -> u64 {
|
||||
let now = SystemTime::now();
|
||||
|
||||
let unix_timestamp = now.duration_since(UNIX_EPOCH).unwrap();
|
||||
return unix_timestamp.as_secs();
|
||||
}
|
||||
|
||||
pub fn send(data: JsonValue) -> HttpResponse {
|
||||
let encrypted = encryption::encrypt_packet(&json::stringify(data)).unwrap();
|
||||
let resp = encrypted.into_bytes();
|
||||
|
||||
HttpResponse::Ok().body(resp)
|
||||
}
|
20
src/router/start.rs
Normal file
20
src/router/start.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use json;
|
||||
use json::object;
|
||||
use crate::router::global;
|
||||
use crate::encryption;
|
||||
use actix_web::{HttpResponse, HttpRequest};
|
||||
|
||||
pub fn asset_hash(_req: HttpRequest, body: String) -> HttpResponse {
|
||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||
if body["asset_version"].to_string() != global::ASSET_VERSION {
|
||||
println!("Warning! Asset version is not what was expected. (Did the app update?)");
|
||||
}
|
||||
let resp = object!{
|
||||
"code": 0,
|
||||
"server_time": global::timestamp(),
|
||||
"data": {
|
||||
"asset_hash": global::ASSET_HASH
|
||||
}
|
||||
};
|
||||
global::send(resp)
|
||||
}
|
Reference in New Issue
Block a user