From c364343fe9c7451a0adad388bd41105ccfea219e Mon Sep 17 00:00:00 2001 From: jellywx Date: Thu, 27 Jan 2022 17:31:07 +0000 Subject: [PATCH] configure upload attachment size. remove bitrate compression. --- src/cmds/manage.rs | 4 ++-- src/consts.rs | 4 ++++ src/models/sound.rs | 6 ++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cmds/manage.rs b/src/cmds/manage.rs index 3eab28d..a50cbe4 100644 --- a/src/cmds/manage.rs +++ b/src/cmds/manage.rs @@ -5,7 +5,7 @@ use tokio::fs::File; use crate::{ cmds::autocomplete_sound, - consts::{MAX_SOUNDS, PATREON_GUILD, PATREON_ROLE}, + consts::{MAX_SOUNDS, PATREON_GUILD, PATREON_ROLE, UPLOAD_MAX_SIZE}, models::sound::{Sound, SoundCtx}, Context, Error, }; @@ -59,7 +59,7 @@ pub async fn upload_new_sound( if permit_upload { let attachment = { - ctx.say("Please now upload an audio file under 1MB in size (larger files will be automatically trimmed):").await?; + ctx.say(format!("Please now upload an audio file under {}MB in size (larger files will be automatically trimmed):", *UPLOAD_MAX_SIZE / (1024u64.pow(2)))).await?; let reply = ctx .channel_id() diff --git a/src/consts.rs b/src/consts.rs index 5b7e8fe..c98f149 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -3,6 +3,10 @@ use std::env; pub const THEME_COLOR: u32 = 0x00e0f3; lazy_static! { + pub static ref UPLOAD_MAX_SIZE: u64 = env::var("UPLOAD_MAX_SIZE") + .unwrap_or_else(|_| "2097152".to_string()) + .parse::() + .unwrap(); pub static ref MAX_SOUNDS: u32 = env::var("MAX_SOUNDS").unwrap().parse::().unwrap(); pub static ref PATREON_GUILD: u64 = env::var("PATREON_GUILD").unwrap().parse::().unwrap(); pub static ref PATREON_ROLE: u64 = env::var("PATREON_ROLE").unwrap().parse::().unwrap(); diff --git a/src/models/sound.rs b/src/models/sound.rs index 86784b6..45e2bce 100644 --- a/src/models/sound.rs +++ b/src/models/sound.rs @@ -5,7 +5,7 @@ use songbird::input::restartable::Restartable; use sqlx::{mysql::MySqlPool, Error}; use tokio::{fs::File, io::AsyncWriteExt, process::Command}; -use crate::{error::ErrorTypes, Data}; +use crate::{consts::UPLOAD_MAX_SIZE, error::ErrorTypes, Data}; #[derive(Clone)] pub struct Sound { @@ -361,12 +361,10 @@ DELETE .arg(src_url) .arg("-loglevel") .arg("error") - .arg("-b:a") - .arg("28000") .arg("-f") .arg("opus") .arg("-fs") - .arg("1048576") + .arg(UPLOAD_MAX_SIZE.to_string()) .arg("pipe:1") .output() .await;