reee 1.2.6

This commit is contained in:
shenjack 2024-09-08 17:13:31 +08:00
parent c8a1c252c3
commit a468b7a832
Signed by: shenjack
GPG Key ID: 7B1134A979775551
5 changed files with 60 additions and 36 deletions

View File

@ -1,9 +1,9 @@
use blake3::Hasher; use blake3::Hasher;
use sea_orm::{ use sea_orm::{
ActiveModelTrait, ColumnTrait, ConnectionTrait, DatabaseConnection, EntityTrait, 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 tracing::{event, Level};
use crate::model; use crate::model;
@ -25,6 +25,7 @@ pub struct DbData {
pub save_type: SaveType, pub save_type: SaveType,
pub len: i64, pub len: i64,
pub blake_hash: String, pub blake_hash: String,
pub xml_tested: bool,
} }
impl From<model::main_data::Model> for DbData { 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, save_type: data.save_type,
len: data.len, len: data.len,
blake_hash: data.blake_hash, 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, save_type: data.0.save_type,
len: data.0.len, len: data.0.len,
blake_hash: data.0.blake_hash, 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(); let mut hasher = Hasher::new();
hasher.update(data.as_bytes()); hasher.update(data.as_bytes());
let hash = hasher.finalize().to_hex().to_string(); let hash = hasher.finalize().to_hex().to_string();
let xml_tested = utils::verify_xml(&data).is_ok();
Self { Self {
text: Some(data), text: Some(data),
save_id, save_id,
save_type, save_type,
len, len,
blake_hash: hash, blake_hash: hash,
xml_tested,
} }
} }
@ -87,7 +92,20 @@ impl DbData {
if self.text.is_none() { if self.text.is_none() {
return false; 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 里选即可 /// 直接从 full_data 里选即可
@ -109,12 +127,14 @@ impl DbData {
let save_type: SaveType = datas.try_get("", "save_type").ok()?; let save_type: SaveType = datas.try_get("", "save_type").ok()?;
let len: i64 = datas.try_get("", "len").ok()?; let len: i64 = datas.try_get("", "len").ok()?;
let blake_hash: String = datas.try_get("", "blake_hash").ok()?; let blake_hash: String = datas.try_get("", "blake_hash").ok()?;
let xml_tested: Option<bool> = datas.try_get("", "xml_tested").ok()?;
Some(Self { Some(Self {
text, text,
save_id: save_id as SaveId, save_id: save_id as SaveId,
save_type, save_type,
len, len,
blake_hash, blake_hash,
xml_tested: xml_tested.unwrap_or(false),
}) })
} }
} }
@ -226,7 +246,7 @@ where
exitst_data.delete(db).await?; 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 { if data_len > TEXT_DATA_MAX_LEN {
// 过长, 需要把数据放到 long_data 里 // 过长, 需要把数据放到 long_data 里

View File

@ -156,15 +156,15 @@ pub trait FromDb {
} }
/// 校验一下是不是合法 xml /// 校验一下是不是合法 xml
pub fn verify_xml(data: &str) -> bool { pub fn verify_xml(data: &str) -> quick_xml::Result<()> {
let mut reader = Reader::from_str(data); let mut reader = Reader::from_str(data);
reader.config_mut().trim_text(true); reader.config_mut().trim_text(true);
loop { loop {
match reader.read_event() { match reader.read_event() {
Ok(Event::Eof) => break, Ok(Event::Eof) => break,
Ok(_) => (), Ok(_) => (),
Err(_) => return false, Err(e) => return Err(e),
} }
} }
true Ok(())
} }

View File

@ -30,21 +30,6 @@
font-size: medium; 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 { .title {
font-size: 30px; font-size: 30px;
margin-bottom: 10px; margin-bottom: 10px;
@ -113,7 +98,7 @@
<body> <body>
<div class="spacer"></div> <div class="spacer"></div>
<div class="container"> <div class="container">
<div class="box2"> <div class="box2" style="background-color: #BBDEFB;">
<div class="title">最新数据</div> <div class="title">最新数据</div>
<div>最大 id: |MAX_ID|</div> <div>最大 id: |MAX_ID|</div>
<div>类型: |MAX_SAVE_TYPE|</div> <div>类型: |MAX_SAVE_TYPE|</div>
@ -124,14 +109,14 @@
</div> </div>
<div class="spacer"></div> <div class="spacer"></div>
<div class="container"> <div class="container">
<div class="box"> <div class="box" style="background-color: #FFE0B2;">
<div class="title">最新飞船</div> <div class="title">最新飞船</div>
<div>最大飞船 id: |MAX_SHIP_ID|</div> <div>最大飞船 id: |MAX_SHIP_ID|</div>
<div>长度: |MAX_SHIP_LEN|</div> <div>长度: |MAX_SHIP_LEN|</div>
<div>xml校验: |MAX_SHIP_XML|</div> <div>xml校验: |MAX_SHIP_XML|</div>
<div>blake hash: <span class="monospace">|MAX_SHIP_HASH|</span></div> <div>blake hash: <span class="monospace">|MAX_SHIP_HASH|</span></div>
</div> </div>
<div class="box"> <div class="box" style="background-color: #C8E6C9;">
<div class="title">最新存档</div> <div class="title">最新存档</div>
<div>最大存档 id: |MAX_SAVE_ID|</div> <div>最大存档 id: |MAX_SAVE_ID|</div>
<div>长度: |MAX_SAVE_LEN|</div> <div>长度: |MAX_SAVE_LEN|</div>
@ -140,6 +125,14 @@
</div> </div>
</div> </div>
<div class="spacer"></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="container">
<div class="input-section"> <div class="input-section">
<input type="number" id="dataId" placeholder="输入ID"> <input type="number" id="dataId" placeholder="输入ID">

View File

@ -200,20 +200,15 @@ async fn jump_to_dashboard_from_root() -> impl IntoResponse {
/// 框上面分别是 "最新数据" "最新飞船" "最新存档" 的标题 /// 框上面分别是 "最新数据" "最新飞船" "最新存档" 的标题
const INFO_PAGE: &str = include_str!("info.html"); 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> { 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 = db_part::search::max_id(&db).await;
let max_id_data = DbData::from_db(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_ship = db_part::search::max_ship(&db).await;
let max_save = db_part::search::max_save(&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()); let mut page_content = INFO_PAGE.replace("|MAX_ID|", &max_id.to_string());
if let Some(max_id_data) = max_id_data { 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_LEN|", &max_id_data.len.to_string())
.replace("|MAX_HASH|", &max_id_data.blake_hash) .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 { } else {
page_content = page_content page_content = page_content
.replace("|MAX_ID|", "not found") .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_ID|", &max_ship.save_id.to_string())
.replace("|MAX_SHIP_LEN|", &max_ship.len.to_string()) .replace("|MAX_SHIP_LEN|", &max_ship.len.to_string())
.replace("|MAX_SHIP_HASH|", &max_ship.blake_hash) .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 { } else {
page_content = page_content page_content = page_content
.replace("|MAX_SHIP_ID|", "not found") .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_ID|", &max_save.save_id.to_string())
.replace("|MAX_SAVE_LEN|", &max_save.len.to_string()) .replace("|MAX_SAVE_LEN|", &max_save.len.to_string())
.replace("|MAX_SAVE_HASH|", &max_save.blake_hash) .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 { } else {
page_content = page_content page_content = page_content
.replace("|MAX_SAVE_ID|", "not found") .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"); .replace("|MAX_SAVE_XML|", "not found");
} }
page_content = page_content
.replace("|COST_TIME|", &format!("{:?}", elapsed))
.replace("|VERSION|", env!("CARGO_PKG_VERSION"));
Html(page_content) Html(page_content)
} }

View File

@ -1,5 +1,17 @@
# v1.0 # v1.0
## 1.2.6
1.3 会迁移到自己写的脚本的
不过现在还是用 sea orm 的
数据库表里添加了 time 字段
用来记录时间
添加了新的检查数据库内数据有效性的 api
现在会检测了
去掉了 `get-save`
在网页 api 里添加了是否通过 xml 检测的选项
也在 dashboard 上添加了用时显示
## 1.2.5 ## 1.2.5
额, 准备迁移到自己写的迁移脚本 额, 准备迁移到自己写的迁移脚本