能行了?

This commit is contained in:
shenjack 2024-07-20 23:47:24 +08:00
parent 6c1a914b6a
commit bbf744fa16
Signed by: shenjack
GPG Key ID: 7B1134A979775551
5 changed files with 39 additions and 9 deletions

11
Cargo.lock generated
View File

@ -435,6 +435,16 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
[[package]]
name = "colored"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8"
dependencies = [
"lazy_static",
"windows-sys 0.48.0",
]
[[package]]
name = "const-oid"
version = "0.9.6"
@ -2538,6 +2548,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"blake3",
"colored",
"futures",
"migration",
"reqwest",

View File

@ -21,3 +21,4 @@ serde = { version = "1.0.204", features = ["serde_derive"] }
toml = "0.8.15"
blake3 = "1.5.3"
futures = "0.3.30"
colored = "2.1.0"

View File

@ -1,7 +1,7 @@
use blake3::Hasher;
use sea_orm::{
ActiveModelTrait, ConnectOptions, Database, DatabaseConnection, EntityTrait, IntoActiveModel,
ModelTrait, QueryOrder, QuerySelect, TransactionTrait,
ActiveModelTrait, ColumnTrait, ConnectOptions, Database, DatabaseConnection, EntityTrait,
IntoActiveModel, ModelTrait, QueryFilter, QueryOrder, QuerySelect, TransactionTrait,
};
use tracing::{event, Level};
@ -75,12 +75,11 @@ where
let cover_strategy = cover_strategy.unwrap_or_default();
let save_type: SaveType = save_type.into();
let exitst_data: Option<model::main_data::Model> = {
model::main_data::Entity::find_by_id(save_id as i32)
.select_only()
.column(model::main_data::Column::BlakeHash)
.column(model::main_data::Column::Len)
model::main_data::Entity::find()
.filter(model::main_data::Column::SaveId.eq(save_id as i32))
.one(db)
.await?
.await
.unwrap_or(None)
};
if exitst_data.is_some() {
match cover_strategy {

View File

@ -1,3 +1,4 @@
use colored::Colorize;
use futures::future::select_all;
use std::{ops::Range, path::Path};
use tracing::{event, Level};
@ -17,14 +18,26 @@ async fn big_worker(db: sea_orm::DatabaseConnection, work_range: Range<SaveId>)
for work_id in work_range {
match match client.try_download_as_any(work_id).await {
Some(file) => {
event!(
Level::INFO,
"{}",
format!("Download {} with data len: {}", work_id, file.len()).green()
);
let save_type = (&file).into();
db_part::save_data_to_db(work_id, save_type, file.take_data(), None, &db)
}
None => db_part::save_data_to_db(work_id, SaveType::None, "".to_string(), None, &db),
None => {
event!(
Level::INFO,
"{}",
format!("Download {} with no data", work_id).yellow()
);
db_part::save_data_to_db(work_id, SaveType::None, "".to_string(), None, &db)
}
}
.await
{
Ok(_) => event!(Level::INFO, "Save data {} success", work_id),
Ok(_) => (),
Err(e) => event!(Level::WARN, "Save data {} failed: {:?}", work_id, e),
}
}

View File

@ -41,6 +41,12 @@ impl DownloadFile {
DownloadFile::Save(s) => s,
}
}
pub fn len(&self) -> usize {
match self {
DownloadFile::Ship(s) => s.len(),
DownloadFile::Save(s) => s.len(),
}
}
}
impl From<&DownloadFile> for SaveType {