♻️ refactor
Some checks failed
ci/woodpecker/push/deploy Pipeline failed

This commit is contained in:
JMARyA 2025-03-04 21:52:37 +01:00
parent 555c874291
commit f1faef552c
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
5 changed files with 57 additions and 92 deletions

View file

@ -222,7 +222,7 @@ impl Track {
///
/// # Returns
///
/// A `String` representing the path to the transceded audio file, or `None` if the transcoding failed.
/// A `String` representing the path to the transcoded audio file, or `None` if the transcoding failed.
pub fn get_opus(&self, bitrate: u32) -> Option<String> {
self.transcode("libopus", bitrate, "opus")
}

View file

@ -40,23 +40,15 @@ pub async fn album_cover_route(
lib: &State<Libary>,
cache: &State<RouteCache>,
) -> Option<DataResponse> {
let mut buf = Vec::new();
tokio::fs::File::open(
cache
.get_option("album_cover_route", album_id, || async {
let album = lib.get_album_by_id(&to_uuid(album_id).unwrap()).await?;
album.get_cover().await
})
.await?,
)
.await
.ok()?
.read(&mut buf)
.await
.ok()?;
let path = cache
.get_option("album_cover_route", album_id, || async {
let album = lib.get_album_by_id(&to_uuid(album_id).unwrap()).await?;
album.get_cover().await
})
.await?;
Some(DataResponse::new(
buf,
Some(DataResponse::new_file(
&path,
"image/png".to_string(),
Some(60 * 60 * 24 * 5),
))

View file

@ -22,16 +22,8 @@ pub async fn artist_image_route(id: &str, cache: &State<RouteCache>) -> Option<D
})
.await?;
let mut buf = Vec::new();
tokio::fs::File::open(image)
.await
.ok()?
.read(&mut buf)
.await
.ok()?;
Some(DataResponse::new(
buf,
Some(DataResponse::new_file(
&image,
"image/png".to_string(),
Some(60 * 60 * 24 * 5),
))

View file

@ -43,16 +43,8 @@ pub async fn track_reload_meta_route(
pub async fn track_audio_route(track_id: &str, lib: &State<Libary>) -> Option<DataResponse> {
let track = lib.get_track_by_id(&to_uuid(track_id).ok()?).await?;
let mut buf = Vec::new();
tokio::fs::File::open(track.path)
.await
.ok()?
.read(&mut buf)
.await
.ok()?;
Some(DataResponse::new(
buf,
Some(DataResponse::new_file(
&track.path,
"audio/ogg".to_string(),
Some(60 * 60 * 24 * 5),
))
@ -65,16 +57,10 @@ pub async fn track_audio_opus128_route(
) -> Option<DataResponse> {
let track = lib.get_track_by_id(&to_uuid(track_id).ok()?).await?;
let mut buf = Vec::new();
tokio::fs::File::open(track.get_opus(128)?)
.await
.ok()?
.read(&mut buf)
.await
.ok()?;
let path = track.get_opus(128)?;
Some(DataResponse::new(
buf,
Some(DataResponse::new_file(
&path,
"audio/opus".to_string(),
Some(60 * 60 * 24 * 5),
))
@ -84,16 +70,10 @@ pub async fn track_audio_opus128_route(
pub async fn track_audio_aac128_route(track_id: &str, lib: &State<Libary>) -> Option<DataResponse> {
let track = lib.get_track_by_id(&to_uuid(track_id).ok()?).await?;
let mut buf = Vec::new();
tokio::fs::File::open(track.get_aac(128)?)
.await
.ok()?
.read(&mut buf)
.await
.ok()?;
let path = track.get_aac(128)?;
Some(DataResponse::new(
buf,
Some(DataResponse::new_file(
&path,
"audio/aac".to_string(),
Some(60 * 60 * 24 * 5),
))