From 9ba253b6f398c9f6dc3a5545b026fb85adc7fbbe Mon Sep 17 00:00:00 2001 From: itsusinn Date: Mon, 15 Nov 2021 16:24:34 +0800 Subject: [PATCH] refactor: download files through net module --- Cargo.toml | 2 +- src/bot.rs | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cbbd7dd..1023111 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,7 +58,7 @@ sled = "0.34.7" # mesagisto nats = "0.16.0" -mesagisto-client = { git = "https://github.com/MeowCat-Studio/mesagisto-client-rs.git", rev = "8d74323" } +mesagisto-client = { git = "https://github.com/MeowCat-Studio/mesagisto-client-rs.git", rev = "cfe7a4" } # mesagisto-client = { path = "../../mesagisto-client/rust" } automatic-config = { git = "https://github.com/Itsusinn/automatic-config-rs.git" } singleton = { git = "https://github.com/Itsusinn/singleton-rs.git", rev = "bee321c" } diff --git a/src/bot.rs b/src/bot.rs index 14dcda9..dd87a3e 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -2,8 +2,8 @@ use std::{ops::Deref, sync::Arc}; use crate::config::CONFIG; use arcstr::ArcStr; -use mesagisto_client::{cache::CACHE, res::RES, LateInit}; -use teloxide::{adaptors::AutoSend, net::Download, prelude::Requester, types::File as TgFile, Bot}; +use mesagisto_client::{LateInit, cache::CACHE, net::NET, res::RES}; +use teloxide::{adaptors::AutoSend, prelude::Requester, types::File as TgFile, Bot}; #[derive(Singleton, Default)] pub struct TgBot { @@ -21,9 +21,8 @@ impl TgBot { .await .expect("failed to get file"); let tmp_path = RES.tmp_path(&id_str); - let mut file = tokio::fs::File::create(&tmp_path).await?; - // mention: this is stream - self.inner.download_file(&file_path, &mut file).await?; + let url = self.get_url_by_path(file_path); + NET.download(&url, &tmp_path).await?; CACHE.put_file(uid, &tmp_path).await?; Ok(()) }