reee 1.2.6
This commit is contained in:
parent
c8a1c252c3
commit
a468b7a832
@ -1,9 +1,9 @@
|
||||
use blake3::Hasher;
|
||||
use sea_orm::{
|
||||
ActiveModelTrait, ColumnTrait, ConnectionTrait, DatabaseConnection, EntityTrait,
|
||||
IntoActiveModel, ModelTrait, QueryFilter, QuerySelect, Statement, TransactionTrait,
|
||||
IntoActiveModel, ModelTrait, QueryFilter, QueryResult, QuerySelect, Statement,
|
||||
TransactionTrait,
|
||||
};
|
||||
use tracing::{event, Level};
|
||||
// use tracing::{event, Level};
|
||||
|
||||
use crate::model;
|
||||
@ -25,6 +25,7 @@ pub struct DbData {
|
||||
pub save_type: SaveType,
|
||||
pub len: i64,
|
||||
pub blake_hash: String,
|
||||
pub xml_tested: bool,
|
||||
}
|
||||
|
||||
impl From<model::main_data::Model> for DbData {
|
||||
@ -35,6 +36,7 @@ impl From<model::main_data::Model> for DbData {
|
||||
save_type: data.save_type,
|
||||
len: data.len,
|
||||
blake_hash: data.blake_hash,
|
||||
xml_tested: data.xml_tested.unwrap_or(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -47,6 +49,7 @@ impl From<(model::main_data::Model, model::long_data::Model)> for DbData {
|
||||
save_type: data.0.save_type,
|
||||
len: data.0.len,
|
||||
blake_hash: data.0.blake_hash,
|
||||
xml_tested: data.0.xml_tested.unwrap_or(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,12 +62,14 @@ impl DbData {
|
||||
let mut hasher = Hasher::new();
|
||||
hasher.update(data.as_bytes());
|
||||
let hash = hasher.finalize().to_hex().to_string();
|
||||
let xml_tested = utils::verify_xml(&data).is_ok();
|
||||
Self {
|
||||
text: Some(data),
|
||||
save_id,
|
||||
save_type,
|
||||
len,
|
||||
blake_hash: hash,
|
||||
xml_tested,
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,7 +92,20 @@ impl DbData {
|
||||
if self.text.is_none() {
|
||||
return false;
|
||||
}
|
||||
utils::verify_xml(self.text.as_ref().unwrap())
|
||||
utils::verify_xml(self.text.as_ref().unwrap()).is_ok()
|
||||
}
|
||||
|
||||
pub fn xml_status(&self) -> String {
|
||||
if self.xml_tested {
|
||||
return "ok".to_string();
|
||||
}
|
||||
if self.text.is_none() {
|
||||
return "no data".to_string();
|
||||
}
|
||||
if let Err(e) = utils::verify_xml(self.text.as_ref().unwrap()) {
|
||||
return format!("error: {}", e);
|
||||
}
|
||||
"ok".to_string()
|
||||
}
|
||||
|
||||
/// 直接从 full_data 里选即可
|
||||
@ -109,12 +127,14 @@ impl DbData {
|
||||
let save_type: SaveType = datas.try_get("", "save_type").ok()?;
|
||||
let len: i64 = datas.try_get("", "len").ok()?;
|
||||
let blake_hash: String = datas.try_get("", "blake_hash").ok()?;
|
||||
let xml_tested: Option<bool> = datas.try_get("", "xml_tested").ok()?;
|
||||
Some(Self {
|
||||
text,
|
||||
save_id: save_id as SaveId,
|
||||
save_type,
|
||||
len,
|
||||
blake_hash,
|
||||
xml_tested: xml_tested.unwrap_or(false),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -226,7 +246,7 @@ where
|
||||
exitst_data.delete(db).await?;
|
||||
}
|
||||
|
||||
let xml_tested = Some(utils::verify_xml(&data));
|
||||
let xml_tested = Some(utils::verify_xml(&data).is_ok());
|
||||
|
||||
if data_len > TEXT_DATA_MAX_LEN {
|
||||
// 过长, 需要把数据放到 long_data 里
|
||||
|
@ -156,15 +156,15 @@ pub trait FromDb {
|
||||
}
|
||||
|
||||
/// 校验一下是不是合法 xml
|
||||
pub fn verify_xml(data: &str) -> bool {
|
||||
pub fn verify_xml(data: &str) -> quick_xml::Result<()> {
|
||||
let mut reader = Reader::from_str(data);
|
||||
reader.config_mut().trim_text(true);
|
||||
loop {
|
||||
match reader.read_event() {
|
||||
Ok(Event::Eof) => break,
|
||||
Ok(_) => (),
|
||||
Err(_) => return false,
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
}
|
||||
true
|
||||
Ok(())
|
||||
}
|
||||
|
@ -30,21 +30,6 @@
|
||||
font-size: medium;
|
||||
}
|
||||
|
||||
.box:nth-child(1) {
|
||||
background-color: #FFE0B2;
|
||||
/* 淡橙色 */
|
||||
}
|
||||
|
||||
.box:nth-child(2) {
|
||||
background-color: #C8E6C9;
|
||||
/* 淡绿色 */
|
||||
}
|
||||
|
||||
.box2:nth-child(1) {
|
||||
background-color: #BBDEFB;
|
||||
/* 淡蓝色 */
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 30px;
|
||||
margin-bottom: 10px;
|
||||
@ -113,7 +98,7 @@
|
||||
<body>
|
||||
<div class="spacer"></div>
|
||||
<div class="container">
|
||||
<div class="box2">
|
||||
<div class="box2" style="background-color: #BBDEFB;">
|
||||
<div class="title">最新数据</div>
|
||||
<div>最大 id: |MAX_ID|</div>
|
||||
<div>类型: |MAX_SAVE_TYPE|</div>
|
||||
@ -124,14 +109,14 @@
|
||||
</div>
|
||||
<div class="spacer"></div>
|
||||
<div class="container">
|
||||
<div class="box">
|
||||
<div class="box" style="background-color: #FFE0B2;">
|
||||
<div class="title">最新飞船</div>
|
||||
<div>最大飞船 id: |MAX_SHIP_ID|</div>
|
||||
<div>长度: |MAX_SHIP_LEN|</div>
|
||||
<div>xml校验: |MAX_SHIP_XML|</div>
|
||||
<div>blake hash: <span class="monospace">|MAX_SHIP_HASH|</span></div>
|
||||
</div>
|
||||
<div class="box">
|
||||
<div class="box" style="background-color: #C8E6C9;">
|
||||
<div class="title">最新存档</div>
|
||||
<div>最大存档 id: |MAX_SAVE_ID|</div>
|
||||
<div>长度: |MAX_SAVE_LEN|</div>
|
||||
@ -140,6 +125,14 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="spacer"></div>
|
||||
<div class="container">
|
||||
<div class="box" style="background-color: cadetblue;">
|
||||
<div class="title">相关信息</div>
|
||||
<div>请求用时: |COST_TIME|</div>
|
||||
<div>sr-download 版本号: |VERSION|</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="spacer"></div>
|
||||
<div class="container">
|
||||
<div class="input-section">
|
||||
<input type="number" id="dataId" placeholder="输入ID">
|
||||
|
@ -200,20 +200,15 @@ async fn jump_to_dashboard_from_root() -> impl IntoResponse {
|
||||
/// 框上面分别是 "最新数据" "最新飞船" "最新存档" 的标题
|
||||
const INFO_PAGE: &str = include_str!("info.html");
|
||||
|
||||
fn xml_tested_to_str(tested: bool) -> &'static str {
|
||||
if tested {
|
||||
"通过了"
|
||||
} else {
|
||||
"未通过"
|
||||
}
|
||||
}
|
||||
|
||||
async fn dashboard_page(State(db): State<DatabaseConnection>) -> Html<String> {
|
||||
let start_time = std::time::Instant::now();
|
||||
let max_id = db_part::search::max_id(&db).await;
|
||||
let max_id_data = DbData::from_db(max_id, &db).await;
|
||||
let max_ship = db_part::search::max_ship(&db).await;
|
||||
let max_save = db_part::search::max_save(&db).await;
|
||||
|
||||
let elapsed = start_time.elapsed();
|
||||
|
||||
let mut page_content = INFO_PAGE.replace("|MAX_ID|", &max_id.to_string());
|
||||
|
||||
if let Some(max_id_data) = max_id_data {
|
||||
@ -225,7 +220,7 @@ async fn dashboard_page(State(db): State<DatabaseConnection>) -> Html<String> {
|
||||
)
|
||||
.replace("|MAX_LEN|", &max_id_data.len.to_string())
|
||||
.replace("|MAX_HASH|", &max_id_data.blake_hash)
|
||||
.replace("|MAX_XML|", xml_tested_to_str(max_id_data.verify_xml()));
|
||||
.replace("|MAX_XML|", &max_id_data.xml_status());
|
||||
} else {
|
||||
page_content = page_content
|
||||
.replace("|MAX_ID|", "not found")
|
||||
@ -239,7 +234,7 @@ async fn dashboard_page(State(db): State<DatabaseConnection>) -> Html<String> {
|
||||
.replace("|MAX_SHIP_ID|", &max_ship.save_id.to_string())
|
||||
.replace("|MAX_SHIP_LEN|", &max_ship.len.to_string())
|
||||
.replace("|MAX_SHIP_HASH|", &max_ship.blake_hash)
|
||||
.replace("|MAX_SHIP_XML|", xml_tested_to_str(max_ship.verify_xml()));
|
||||
.replace("|MAX_SHIP_XML|", &max_ship.xml_status());
|
||||
} else {
|
||||
page_content = page_content
|
||||
.replace("|MAX_SHIP_ID|", "not found")
|
||||
@ -252,7 +247,7 @@ async fn dashboard_page(State(db): State<DatabaseConnection>) -> Html<String> {
|
||||
.replace("|MAX_SAVE_ID|", &max_save.save_id.to_string())
|
||||
.replace("|MAX_SAVE_LEN|", &max_save.len.to_string())
|
||||
.replace("|MAX_SAVE_HASH|", &max_save.blake_hash)
|
||||
.replace("|MAX_SAVE_XML|", xml_tested_to_str(max_save.verify_xml()));
|
||||
.replace("|MAX_SAVE_XML|", &max_save.xml_status());
|
||||
} else {
|
||||
page_content = page_content
|
||||
.replace("|MAX_SAVE_ID|", "not found")
|
||||
@ -261,6 +256,10 @@ async fn dashboard_page(State(db): State<DatabaseConnection>) -> Html<String> {
|
||||
.replace("|MAX_SAVE_XML|", "not found");
|
||||
}
|
||||
|
||||
page_content = page_content
|
||||
.replace("|COST_TIME|", &format!("{:?}", elapsed))
|
||||
.replace("|VERSION|", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
Html(page_content)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user