Remove file-based audio streaming
This commit is contained in:
+3
-25
@@ -1,9 +1,7 @@
|
||||
use std::{env, path::Path};
|
||||
|
||||
use poise::serenity_prelude::async_trait;
|
||||
use songbird::input::Input;
|
||||
use sqlx::Executor;
|
||||
use tokio::{fs::File, io::AsyncWriteExt, process::Command};
|
||||
use tokio::process::Command;
|
||||
|
||||
use crate::{consts::UPLOAD_MAX_SIZE, error::ErrorTypes, Data, Database};
|
||||
|
||||
@@ -399,7 +397,7 @@ impl SoundCtx for Data {
|
||||
}
|
||||
|
||||
impl Sound {
|
||||
async fn src(&self, db_pool: impl Executor<'_, Database = Database>) -> Vec<u8> {
|
||||
pub(crate) async fn src(&self, db_pool: impl Executor<'_, Database = Database>) -> Vec<u8> {
|
||||
struct Src {
|
||||
src: Vec<u8>,
|
||||
}
|
||||
@@ -420,31 +418,11 @@ impl Sound {
|
||||
record.src
|
||||
}
|
||||
|
||||
pub async fn store_sound_source(
|
||||
&self,
|
||||
db_pool: impl Executor<'_, Database = Database>,
|
||||
) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let caching_location = env::var("CACHING_LOCATION").unwrap_or(String::from("/tmp"));
|
||||
|
||||
let path_name = format!("{}/sound-{}.opus", caching_location, self.id);
|
||||
let path = Path::new(&path_name);
|
||||
|
||||
if !path.exists() {
|
||||
let mut file = File::create(&path).await?;
|
||||
|
||||
file.write_all(&self.src(db_pool).await).await?;
|
||||
}
|
||||
|
||||
Ok(path_name)
|
||||
}
|
||||
|
||||
pub async fn playable(
|
||||
&self,
|
||||
db_pool: impl Executor<'_, Database = Database>,
|
||||
) -> Result<Input, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let path_name = self.store_sound_source(db_pool).await?;
|
||||
|
||||
Ok(Input::from(path_name))
|
||||
Ok(Input::from(self.src(db_pool).await))
|
||||
}
|
||||
|
||||
pub async fn count_user_sounds<U: Into<u64>>(
|
||||
|
||||
Reference in New Issue
Block a user