aboutsummaryrefslogtreecommitdiffstats
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/utilities.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/commands/utilities.rs b/src/commands/utilities.rs
index 7a2e65d..88829b2 100644
--- a/src/commands/utilities.rs
+++ b/src/commands/utilities.rs
@@ -18,6 +18,9 @@ type Context<'a> = poise::Context<'a, Data, Error>;
18// original and keeps replies snappy. 18// original and keeps replies snappy.
19const LARGE_FILE_THRESHOLD: usize = 10 * 1024 * 1024; 19const LARGE_FILE_THRESHOLD: usize = 10 * 1024 * 1024;
20 20
21/// Hard cap for a single `/download` result (before it is read into memory).
22const MAX_DOWNLOAD_BYTES: u64 = 512 * 1024 * 1024;
23
21#[derive(Clone, Copy, PartialEq, Eq)] 24#[derive(Clone, Copy, PartialEq, Eq)]
22pub(crate) enum FileType { 25pub(crate) enum FileType {
23 Video, 26 Video,
@@ -524,6 +527,8 @@ async fn run_download(
524 .arg("bestaudio/bestvideo+bestaudio") 527 .arg("bestaudio/bestvideo+bestaudio")
525 .arg("--merge-output-format") 528 .arg("--merge-output-format")
526 .arg("mp4") 529 .arg("mp4")
530 .arg("--max-filesize")
531 .arg("512M")
527 .arg("-o") 532 .arg("-o")
528 .arg(&out_template); 533 .arg(&out_template);
529 if is_audio { 534 if is_audio {
@@ -574,6 +579,16 @@ async fn run_download(
574 None => basename, 579 None => basename,
575 }; 580 };
576 581
582 match tokio::fs::metadata(&actual_path).await {
583 Ok(meta) if meta.len() > MAX_DOWNLOAD_BYTES => {
584 let _ = tokio::fs::remove_dir_all(&dl_dir).await;
585 ctx.say(lang::fmt_download_failed("file is larger than 512 MiB"))
586 .await?;
587 return Ok(());
588 }
589 _ => {}
590 }
591
577 let bytes = match tokio::fs::read(&actual_path).await { 592 let bytes = match tokio::fs::read(&actual_path).await {
578 Ok(b) => b, 593 Ok(b) => b,
579 Err(e) => { 594 Err(e) => {