Skip to content

Commit

Permalink
chore: only create buf when downloading is required
Browse files Browse the repository at this point in the history
  • Loading branch information
nanpuyue committed Mar 22, 2024
1 parent 80b96f9 commit 6c7462f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ impl Command {
.or_else(|| file_id!(message, video));

let image = if let Some((file_id, file_type)) = file_id {
let mut buf = Vec::new();
let file = bot.get_file(file_id).await?;

let tgs_to_png;
let mut download = true;
let mut file_to_png: Option<&(dyn Fn(_) -> _ + Sync)> = None;
Expand All @@ -112,6 +109,8 @@ impl Command {
};

if download {
let mut buf = Vec::new();
let file = bot.get_file(file_id).await?;
bot.download_file(&file.path, &mut buf).await?;
if let Some(file_to_png) = file_to_png {
buf = file_to_png(buf)?;
Expand Down

0 comments on commit 6c7462f

Please sign in to comment.