更改一下构建的一些细节

This commit is contained in:
shenjack-5600u 2024-07-28 00:18:00 +08:00
parent e338d31ef3
commit 19c5971483
Signed by: shenjack
GPG Key ID: FDF9864E11C7E79F

View File

@ -1,7 +1,6 @@
use reqwest::{Client, ClientBuilder}; use reqwest::{Client, ClientBuilder};
use core::time;
use std::time::Duration; use std::time::Duration;
use tracing::{event, Event, Level}; use tracing::{event, Level};
use crate::{model::sea_orm_active_enums::SaveType, SaveId}; use crate::{model::sea_orm_active_enums::SaveType, SaveId};
@ -69,8 +68,7 @@ impl From<&DownloadFile> for SaveType {
impl Downloader { impl Downloader {
pub fn new(timeout: Option<Duration>) -> Self { pub fn new(timeout: Option<Duration>) -> Self {
let ua = format!("sr_download/{}", env!("CARGO_PKG_VERSION")); let ua = format!("sr_download/{}", env!("CARGO_PKG_VERSION"));
let mut client = ClientBuilder::new() let mut client = ClientBuilder::new().user_agent(ua);
.user_agent(ua);
if let Some(timeout) = timeout { if let Some(timeout) = timeout {
client = client.timeout(timeout); client = client.timeout(timeout);
} }
@ -100,11 +98,7 @@ impl Downloader {
let _enter = span.enter(); let _enter = span.enter();
// 先尝试用 ship 的 API 下载 // 先尝试用 ship 的 API 下载
let ship_url = Self::as_ship_url(id); let ship_url = Self::as_ship_url(id);
let ship_try = self let ship_try = self.client.get(&ship_url).send().await;
.client
.get(&ship_url)
.send()
.await;
event!(Level::DEBUG, "trying to Download as ship {:?}", ship_try); event!(Level::DEBUG, "trying to Download as ship {:?}", ship_try);
if let Ok(ship_try) = ship_try { if let Ok(ship_try) = ship_try {
event!(Level::DEBUG, "Download as ship {:?}", ship_try.status()); event!(Level::DEBUG, "Download as ship {:?}", ship_try.status());
@ -121,11 +115,7 @@ impl Downloader {
} }
// 否则尝试用 save 的 API 下载 // 否则尝试用 save 的 API 下载
let save_url = Self::as_save_url(id); let save_url = Self::as_save_url(id);
let save_try = self let save_try = self.client.get(&save_url).send().await;
.client
.get(&save_url)
.send()
.await;
if let Ok(save_try) = save_try { if let Ok(save_try) = save_try {
if save_try.status().is_success() { if save_try.status().is_success() {
if let Ok(body) = save_try.text().await { if let Ok(body) = save_try.text().await {
@ -172,7 +162,6 @@ impl Downloader {
} }
None None
} }
} }
impl Default for Downloader { impl Default for Downloader {