Skip to content

Commit

Permalink
refactor: download files through net module
Browse files Browse the repository at this point in the history
  • Loading branch information
itsusinn committed Nov 15, 2021
1 parent e0d3d9f commit 9ba253b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
9 changes: 4 additions & 5 deletions src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(())
}
Expand Down

0 comments on commit 9ba253b

Please sign in to comment.