修改了一些细节

This commit is contained in:
shenjack-5600u 2024-07-27 01:24:09 +08:00
parent d70e3c72f6
commit 6a615783c1
Signed by: shenjack
GPG Key ID: FDF9864E11C7E79F
6 changed files with 86 additions and 82 deletions

80
Cargo.lock generated
View File

@ -79,9 +79,9 @@ dependencies = [
[[package]]
name = "anstream"
version = "0.6.14"
version = "0.6.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b"
checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
dependencies = [
"anstyle",
"anstyle-parse",
@ -94,33 +94,33 @@ dependencies = [
[[package]]
name = "anstyle"
version = "1.0.7"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b"
checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
[[package]]
name = "anstyle-parse"
version = "0.2.4"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4"
checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.0"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391"
checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a"
dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.3"
version = "3.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19"
checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"
dependencies = [
"anstyle",
"windows-sys 0.52.0",
@ -391,9 +391,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.5.10"
version = "4.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f6b81fb3c84f5563d509c59b5a48d935f689e993afa90fe39047f05adef9142"
checksum = "35723e6a11662c2afb578bcf0b88bf6ea8e21282a953428f240574fcc3a2b5b3"
dependencies = [
"clap_builder",
"clap_derive",
@ -401,9 +401,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.5.10"
version = "4.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca6706fd5224857d9ac5eb9355f6683563cc0541c7cd9d014043b57cbec78ac"
checksum = "49eb96cbfa7cfa35017b7cd548c75b14c3118c98b423041d70562665e07fb0fa"
dependencies = [
"anstream",
"anstyle",
@ -413,9 +413,9 @@ dependencies = [
[[package]]
name = "clap_derive"
version = "4.5.8"
version = "4.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085"
checksum = "5d029b67f89d30bbb547c89fd5161293c0aec155fc691d7924b64550662db93e"
dependencies = [
"heck 0.5.0",
"proc-macro2",
@ -425,15 +425,15 @@ dependencies = [
[[package]]
name = "clap_lex"
version = "0.7.1"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70"
checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
[[package]]
name = "colorchoice"
version = "1.0.1"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
[[package]]
name = "colored"
@ -1085,9 +1085,9 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.0"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itoa"
@ -1335,9 +1335,9 @@ dependencies = [
[[package]]
name = "object"
version = "0.36.1"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce"
checksum = "3f203fa8daa7bb185f760ae12bd8e097f63d17041dcdcaf675ac54cdf863170e"
dependencies = [
"memchr",
]
@ -2188,9 +2188,9 @@ dependencies = [
[[package]]
name = "serde_spanned"
version = "0.6.6"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0"
checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d"
dependencies = [
"serde",
]
@ -2745,9 +2745,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.39.0"
version = "1.39.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c3318c4fc7126c339a40fbc025927d0328ca32259f68bfe4321660644c1f626"
checksum = "d040ac2b29ab03b09d4129c2f5bbd012a3ac2f79d38ff506a4bf8dd34b0eac8a"
dependencies = [
"backtrace",
"bytes",
@ -2819,21 +2819,21 @@ dependencies = [
[[package]]
name = "toml"
version = "0.8.15"
version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac2caab0bf757388c6c0ae23b3293fdb463fee59434529014f85e3263b995c28"
checksum = "81967dd0dd2c1ab0bc3468bd7caecc32b8a4aa47d0c8c695d8c2b2108168d62c"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit 0.22.16",
"toml_edit 0.22.17",
]
[[package]]
name = "toml_datetime"
version = "0.6.6"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf"
checksum = "f8fb9f64314842840f1d940ac544da178732128f1c78c21772e876579e0da1db"
dependencies = [
"serde",
]
@ -2851,15 +2851,15 @@ dependencies = [
[[package]]
name = "toml_edit"
version = "0.22.16"
version = "0.22.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "278f3d518e152219c994ce877758516bca5e118eaed6996192a774fb9fbf0788"
checksum = "8d9f8729f5aea9562aac1cc0441f5d6de3cff1ee0c5d67293eeca5eb36ee7c16"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"winnow 0.6.15",
"winnow 0.6.16",
]
[[package]]
@ -3055,9 +3055,9 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "version_check"
version = "0.9.4"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "want"
@ -3353,9 +3353,9 @@ dependencies = [
[[package]]
name = "winnow"
version = "0.6.15"
version = "0.6.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "557404e450152cd6795bb558bca69e43c585055f4606e3bcae5894fc6dac9ba0"
checksum = "b480ae9340fc261e6be3e95a1ba86d54ae3f9171132a73ce8d4bbaf68339507c"
dependencies = [
"memchr",
]

View File

@ -7,10 +7,9 @@ sqlx_logging = false
[sync]
max_timeout = 1.0
serve_wait_time = 10.0
start_id = 76859
[sync.fast]
start_id = 76859
end_id = 1321469
end_id = 1321698
worker_count = 10
worker_size = 10

View File

@ -10,7 +10,7 @@ path = "./src/get-save.rs"
[dependencies]
reqwest = "0.12.5"
tokio = { version = "1.38.1", features = ["full"] }
tokio = { version = "1.38", features = ["full"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["local-time"] }
anyhow = { version = "1.0.86", features = ["backtrace"] }
@ -23,7 +23,7 @@ sea-orm = { version = "0.12.15", features = [
migration = { path = "../migration" }
serde = { version = "1.0.204", features = ["serde_derive"] }
toml = "0.8.15"
toml = "0.8"
blake3 = "1.5.3"
futures = "0.3.30"
colored = "2.1.0"

View File

@ -38,7 +38,7 @@ impl Default for FastSyncConfig {
fn default() -> Self {
Self {
start_id: 76859,
end_id: 1321469,
end_id: 1321698,
worker_count: 10,
worker_size: 10,
}
@ -90,9 +90,11 @@ impl ConfigFile {
std::time::Duration::from_secs_f32(self.sync.max_timeout)
}
pub fn read_or_panic() -> Self {
/// 自动帮你骂用户了
/// 你直接 ? 就行
pub fn try_read() -> anyhow::Result<Self> {
match Self::read_from_file(Path::new("config.toml")) {
Ok(conf) => conf,
Ok(conf) => Ok(conf),
Err(e) => {
let _ = tracing_subscriber::fmt::try_init();
event!(Level::ERROR, "{}", "Please Fix the config.toml file".red());
@ -104,9 +106,15 @@ impl ConfigFile {
"template file like this: {}",
toml::to_string(&Self::default()).unwrap()
);
};
panic!("Please Fix the config.toml file");
}
Err(e)
}
}
}
/// 同理, 也帮你骂好了
/// 甚至不需要你 ?
pub fn read_or_panic() -> Self {
Self::try_read().expect("Please Fix the config.toml file")
}
}

View File

@ -77,7 +77,7 @@ async fn big_worker(
}
async fn serve_mode(mut stop_receiver: Receiver<()>) -> anyhow::Result<()> {
let conf = config::ConfigFile::read_or_panic();
let conf = config::ConfigFile::try_read()?;
let db_connect = db_part::connect(&conf).await?;
db_part::migrate(&db_connect).await?;
@ -166,7 +166,7 @@ async fn serve_mode(mut stop_receiver: Receiver<()>) -> anyhow::Result<()> {
}
async fn fast_mode(mut stop_receiver: Receiver<()>) -> anyhow::Result<()> {
let conf = config::ConfigFile::read_or_panic();
let conf = config::ConfigFile::try_read()?;
let db_connect = db_part::connect(&conf).await?;
db_part::migrate(&db_connect).await?;
@ -236,36 +236,30 @@ async fn main() -> anyhow::Result<()> {
// 判断是否有 -f / -s 参数
let args: Vec<String> = std::env::args().collect();
let (stop_sender, stop_receiver) = tokio::sync::oneshot::channel::<()>();
let stop_waiter = tokio::spawn(async move {
tokio::signal::ctrl_c()
.await
.expect("Failed to listen for Ctrl+C event");
event!(Level::INFO, "{}", "Ctrl-C received".red());
stop_sender.send(()).unwrap();
});
let job_waiter;
if args.contains(&"-s".to_string()) {
let job_waiter = tokio::spawn(serve_mode(stop_receiver));
// serve 模式的任务不会结束, 所以需要等待 ctrl-c
tokio::signal::ctrl_c().await?;
let _ = stop_sender.send(()); // 反正不需要管, 发过去了就行
job_waiter.await??;
event!(Level::INFO, "{}", "ctrl-c 收到啦! 停止下载".green());
return Ok(());
job_waiter = tokio::spawn(serve_mode(stop_receiver));
} else if args.contains(&"-f".to_string()) {
let stop_waiter = tokio::spawn(async move {
tokio::signal::ctrl_c()
.await
.expect("Failed to listen for Ctrl+C event");
event!(Level::INFO, "{}", "Ctrl-C received".red());
stop_sender.send(()).unwrap();
});
let job_waiter = tokio::spawn(fast_mode(stop_receiver));
// fast 模式的任务会结束, 所以需要等待任务结束
job_waiter.await??;
let _ = stop_waiter.await;
job_waiter = tokio::spawn(fast_mode(stop_receiver));
} else {
event!(
Level::ERROR,
"{}",
"Please use -s or -f to start the program".red()
);
event!(Level::ERROR, "{}", "Use -s to start serve mode".red());
event!(Level::ERROR, "{}", "Use -f to start fast mode".red());
return Ok(());
}
event!(
Level::ERROR,
"{}",
"Please use -s or -f to start the program".red()
);
event!(Level::ERROR, "{}", "Use -s to start serve mode".red());
event!(Level::ERROR, "{}", "Use -f to start fast mode".red());
job_waiter.await??;
let _ = stop_waiter.await;
Ok(())
}

View File

@ -1,4 +1,4 @@
use reqwest::Client;
use reqwest::{Client, ClientBuilder};
use std::time::Duration;
use crate::{model::sea_orm_active_enums::SaveType, SaveId};
@ -67,10 +67,13 @@ impl From<&DownloadFile> for SaveType {
impl Downloader {
pub fn new(timeout: Duration) -> Self {
Self {
client: Client::new(),
timeout,
}
let ua = format!("sr_download/{}", env!("CARGO_PKG_VERSION"));
let client = ClientBuilder::new()
.timeout(timeout)
.user_agent(ua)
.build()
.unwrap();
Self { client, timeout }
}
pub fn as_ship_url(id: SaveId) -> String {