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:
amizing25
2025-03-03 08:02:51 +07:00
parent 50a05a5cc2
commit de22105514
28 changed files with 7113 additions and 12024 deletions
+50
View File
@@ -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,
})
}