From 19c5971483825cf73734ba01cea77147ef32461a Mon Sep 17 00:00:00 2001 From: shenjack-5600u <3695888@qq.com> Date: Sun, 28 Jul 2024 00:18:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=B8=80=E4=B8=8B=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E7=9A=84=E4=B8=80=E4=BA=9B=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sr_download/src/net.rs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/sr_download/src/net.rs b/sr_download/src/net.rs index ad77531..eba38a1 100644 --- a/sr_download/src/net.rs +++ b/sr_download/src/net.rs @@ -1,7 +1,6 @@ use reqwest::{Client, ClientBuilder}; -use core::time; use std::time::Duration; -use tracing::{event, Event, Level}; +use tracing::{event, Level}; use crate::{model::sea_orm_active_enums::SaveType, SaveId}; @@ -69,8 +68,7 @@ impl From<&DownloadFile> for SaveType { impl Downloader { pub fn new(timeout: Option) -> Self { let ua = format!("sr_download/{}", env!("CARGO_PKG_VERSION")); - let mut client = ClientBuilder::new() - .user_agent(ua); + let mut client = ClientBuilder::new().user_agent(ua); if let Some(timeout) = timeout { client = client.timeout(timeout); } @@ -100,11 +98,7 @@ impl Downloader { let _enter = span.enter(); // 先尝试用 ship 的 API 下载 let ship_url = Self::as_ship_url(id); - let ship_try = self - .client - .get(&ship_url) - .send() - .await; + let ship_try = self.client.get(&ship_url).send().await; event!(Level::DEBUG, "trying to Download as ship {:?}", ship_try); if let Ok(ship_try) = ship_try { event!(Level::DEBUG, "Download as ship {:?}", ship_try.status()); @@ -121,11 +115,7 @@ impl Downloader { } // 否则尝试用 save 的 API 下载 let save_url = Self::as_save_url(id); - let save_try = self - .client - .get(&save_url) - .send() - .await; + let save_try = self.client.get(&save_url).send().await; if let Ok(save_try) = save_try { if save_try.status().is_success() { if let Ok(body) = save_try.text().await { @@ -172,7 +162,6 @@ impl Downloader { } None } - } impl Default for Downloader {