mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Properly implement story read endpoint
This commit is contained in:
parent
dcaf65f860
commit
81c0727fa3
3 changed files with 48 additions and 11 deletions
|
@ -4,6 +4,14 @@ use lazy_static::lazy_static;
|
|||
use crate::include_file;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref STORY: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = json::parse(&include_file!("src/router/databases/json/story_part.json")).unwrap();
|
||||
for data in items.members() {
|
||||
info[data["id"].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
};
|
||||
pub static ref LOGIN_REWARDS: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = json::parse(&include_file!("src/router/databases/json/login_bonus_reward.json")).unwrap();
|
||||
|
|
|
@ -1,7 +1,40 @@
|
|||
use json::{object, JsonValue};
|
||||
use actix_web::{HttpRequest};
|
||||
|
||||
use crate::encryption;
|
||||
use crate::router::{global, userdata, databases};
|
||||
|
||||
pub fn read(_req: HttpRequest, _body: String) -> Option<JsonValue> {
|
||||
Some(object!{"gift_list":[],"updated_value_list":{"master_chat_room_ids":[3001001,3101001],"master_chat_chapter_ids":[300100101,310100101]},"reward_list":[{"type":16,"value":3001001,"level":0,"amount":1},{"type":16,"value":3101001,"level":0,"amount":1},{"type":17,"value":300100101,"level":0,"amount":1},{"type":17,"value":310100101,"level":0,"amount":1}],"clear_mission_ids":[]})
|
||||
pub fn read(req: HttpRequest, body: String) -> Option<JsonValue> {
|
||||
let key = global::get_login(req.headers(), &body);
|
||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||
let mut user = userdata::get_acc(&key);
|
||||
let part = body["master_story_part_id"].as_i64().unwrap();
|
||||
let master_id = databases::STORY[part.to_string()]["masterStoryId"].as_i64().unwrap();
|
||||
|
||||
let index = user["story_list"].members().position(|r| r["master_story_id"] == master_id);
|
||||
|
||||
if index.is_none() {
|
||||
user["story_list"].push(object!{
|
||||
master_story_id: master_id,
|
||||
master_story_part_ids: []
|
||||
}).unwrap();
|
||||
}
|
||||
|
||||
for story in user["story_list"].members_mut() {
|
||||
if story["master_story_id"] == master_id && !story["master_story_part_ids"].contains(part) {
|
||||
story["master_story_part_ids"].push(part).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
userdata::save_acc(&key, user.clone());
|
||||
|
||||
|
||||
Some(object!{
|
||||
"gift_list":[],
|
||||
"updated_value_list":{
|
||||
"story_list": user["story_list"].clone()
|
||||
},
|
||||
"reward_list":[],
|
||||
"clear_mission_ids":[]
|
||||
})
|
||||
}
|
||||
|
|
|
@ -68,6 +68,11 @@ fn setup_tables(conn: &SQLite) {
|
|||
user_id BIGINT NOT NULL PRIMARY KEY,
|
||||
server_data TEXT NOT NULL
|
||||
)");
|
||||
conn.create_store_v2("CREATE TABLE IF NOT EXISTS webui (
|
||||
user_id BIGINT NOT NULL PRIMARY KEY,
|
||||
token TEXT NOT NULL,
|
||||
last_login BIGINT NOT NULL
|
||||
)");
|
||||
}
|
||||
|
||||
fn acc_exists(uid: i64) -> bool {
|
||||
|
@ -461,14 +466,6 @@ pub fn get_random_uids(count: i32) -> JsonValue {
|
|||
DATABASE.lock_and_select_all(&format!("SELECT user_id FROM userdata WHERE friend_request_disabled=?1 ORDER BY RANDOM() LIMIT {}", count), params!(0)).unwrap()
|
||||
}
|
||||
|
||||
fn create_webui_store() {
|
||||
DATABASE.create_store_v2("CREATE TABLE IF NOT EXISTS webui (
|
||||
user_id BIGINT NOT NULL PRIMARY KEY,
|
||||
token TEXT NOT NULL,
|
||||
last_login BIGINT NOT NULL
|
||||
)");
|
||||
}
|
||||
|
||||
fn create_webui_token() -> String {
|
||||
let token = global::create_token();
|
||||
if DATABASE.lock_and_select("SELECT user_id FROM webui WHERE token=?1", params!(token)).is_ok() {
|
||||
|
@ -478,7 +475,6 @@ fn create_webui_token() -> String {
|
|||
}
|
||||
|
||||
pub fn webui_login(uid: i64, password: &str) -> Result<String, String> {
|
||||
create_webui_store();
|
||||
let pass = DATABASE.lock_and_select("SELECT password FROM migration WHERE token=?1", params!(crate::router::user::uid_to_code(uid.to_string()))).unwrap_or_default();
|
||||
if !verify_password(password, &pass) {
|
||||
if acc_exists(uid) && pass.is_empty() {
|
||||
|
|
Loading…
Add table
Reference in a new issue