refactor: Refactor json loading mechanism & more
- Move json loading into separate crate `common` - Add new http route for handling SRTools API - Listen to `freesr-data.json` file change, and sync with client immediately - Move json loading into `PlayerSession`, instead of load it everytime - Implement global buff for Castorice - Implement `GetBigDataAllRecommendCsReq`
This commit is contained in:
@@ -7,6 +7,7 @@ edition = "2024"
|
||||
anyhow.workspace = true
|
||||
env_logger.workspace = true
|
||||
|
||||
tower-http = { workspace = true, features = ["cors"]}
|
||||
axum.workspace = true
|
||||
axum-server.workspace = true
|
||||
|
||||
@@ -28,3 +29,4 @@ ansi_term.workspace = true
|
||||
prost.workspace = true
|
||||
rbase64.workspace = true
|
||||
proto.workspace = true
|
||||
common.workspace = true
|
||||
|
||||
+15
-2
@@ -1,8 +1,11 @@
|
||||
use anyhow::Result;
|
||||
use axum::routing::{get, post};
|
||||
use axum::Router;
|
||||
use axum::http::Method;
|
||||
use axum::http::header::CONTENT_TYPE;
|
||||
use axum::routing::{get, post};
|
||||
use logging::init_tracing;
|
||||
use services::{auth, dispatch, errors};
|
||||
use services::{auth, dispatch, errors, sr_tools};
|
||||
use tower_http::cors::{Any, CorsLayer};
|
||||
use tracing::Level;
|
||||
|
||||
mod config;
|
||||
@@ -40,6 +43,16 @@ async fn main() -> Result<()> {
|
||||
auth::GRANTER_LOGIN_VERIFICATION_ENDPOINT,
|
||||
post(auth::granter_login_verification),
|
||||
)
|
||||
.route(
|
||||
sr_tools::SRTOOLS_UPLOAD_ENDPOINT,
|
||||
post(sr_tools::sr_tool_save),
|
||||
)
|
||||
.layer(
|
||||
CorsLayer::new()
|
||||
.allow_origin(Any)
|
||||
.allow_methods([Method::GET, Method::POST, Method::PATCH, Method::DELETE])
|
||||
.allow_headers([CONTENT_TYPE]),
|
||||
)
|
||||
.fallback(errors::not_found);
|
||||
|
||||
let addr = format!("0.0.0.0:{PORT}");
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod auth;
|
||||
pub mod dispatch;
|
||||
pub mod errors;
|
||||
pub mod sr_tools;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
use axum::Json;
|
||||
use common::sr_tools::FreesrData;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::fs;
|
||||
|
||||
pub const SRTOOLS_UPLOAD_ENDPOINT: &str = "/srtools";
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct SrToolDataReq {
|
||||
#[allow(dead_code)]
|
||||
pub data: Option<FreesrData>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct SrToolDataRsp {
|
||||
pub message: String,
|
||||
pub status: u32,
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn sr_tool_save(Json(json): Json<SrToolDataReq>) -> Json<SrToolDataRsp> {
|
||||
let Some(json) = json.data else {
|
||||
return Json(SrToolDataRsp {
|
||||
message: String::from("OK"),
|
||||
status: 200,
|
||||
});
|
||||
};
|
||||
|
||||
let json = match serde_json::to_string_pretty(&json) {
|
||||
Ok(json) => json,
|
||||
Err(err) => {
|
||||
return Json(SrToolDataRsp {
|
||||
message: format!("malformed json: {}", err),
|
||||
status: 200,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(err) = fs::write("freesr-data.json", json).await {
|
||||
return Json(SrToolDataRsp {
|
||||
message: format!("failed to write freesr-data.json: {}", err),
|
||||
status: 200,
|
||||
});
|
||||
};
|
||||
|
||||
Json(SrToolDataRsp {
|
||||
message: String::from("OK"),
|
||||
status: 200,
|
||||
})
|
||||
}
|
||||
+5
-17
@@ -1,20 +1,8 @@
|
||||
{
|
||||
"CNBETAWin3.0.51": {
|
||||
"asset_bundle_url": "https://autopatchcn.bhsr.com/asb/BetaLive/output_9191572_33717c67eee7",
|
||||
"ex_resource_url": "https://autopatchcn.bhsr.com/design_data/BetaLive/output_9201681_3b7fa40d696e",
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_9188077_6eddb96c0602",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_0_40d2ce0253"
|
||||
},
|
||||
"OSBETAWin3.0.51": {
|
||||
"asset_bundle_url": "https://autopatchcn.bhsr.com/asb/BetaLive/output_9191572_33717c67eee7",
|
||||
"ex_resource_url": "https://autopatchcn.bhsr.com/design_data/BetaLive/output_9194543_a2c963cc027a",
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_9188077_6eddb96c0602",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_0_40d2ce0253"
|
||||
},
|
||||
"CNBETAWin3.0.53": {
|
||||
"asset_bundle_url": "https://autopatchcn.bhsr.com/asb/BetaLive/output_9327839_3a7f8c61dd4e",
|
||||
"ex_resource_url": "https://autopatchcn.bhsr.com/design_data/BetaLive/output_9330527_430d02ffd64d",
|
||||
"lua_url": "https://autopatchcn.bhsr.com/lua/BetaLive/output_9327980_89d683a0d346",
|
||||
"ifix_url": "https://autopatchcn.bhsr.com/ifix/BetaLive/output_0_40d2ce0253"
|
||||
"OSBETAWin3.1.51": {
|
||||
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_9573347_b03981f01966",
|
||||
"ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_9589567_9c50629b0369",
|
||||
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_9567078_0e2b6acf6a2f",
|
||||
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_0_40d2ce0253"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user