ebuggage transcodage audio en flac
This commit is contained in:
@@ -201,20 +201,3 @@ pub fn get_metadata(cache: &Cache, pk: &str) -> Result<crate::metadata::AudioMet
|
||||
Ok(metadata)
|
||||
}
|
||||
|
||||
/// Retourne la route relative pour accéder à une piste audio
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `pk` - Clé primaire de la piste
|
||||
/// * `param` - Paramètre optionnel (ex: "orig", "128k", etc.)
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Route relative (ex: "/audio/tracks/abc123" ou "/audio/tracks/abc123/orig")
|
||||
pub fn route_for(pk: &str, param: Option<&str>) -> String {
|
||||
if let Some(p) = param {
|
||||
format!("/audio/tracks/{}/{}", pk, p)
|
||||
} else {
|
||||
format!("/audio/tracks/{}", pk)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use anyhow::Result;
|
||||
use sha1::{Digest, Sha1};
|
||||
use std::{path::{Path, PathBuf}, sync::Arc};
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use crate::{CacheConfig, DB};
|
||||
|
||||
@@ -8,7 +11,6 @@ use crate::{CacheConfig, DB};
|
||||
///
|
||||
/// Définit l'interface commune pour tous les types de caches (images, audio, etc.)
|
||||
pub trait FileCache<C: CacheConfig>: Send + Sync {
|
||||
|
||||
fn get_cache_dir(&self) -> &Path;
|
||||
fn get_database(&self) -> Arc<DB>;
|
||||
|
||||
@@ -66,7 +68,26 @@ pub trait FileCache<C: CacheConfig>: Send + Sync {
|
||||
///
|
||||
/// Format: `{pk}.{qualificatif}.{extension}`
|
||||
fn file_path_with_qualifier(&self, pk: &str, qualifier: &str) -> PathBuf {
|
||||
self.get_cache_dir().join(format!("{}.{}.{}", pk, qualifier, C::file_extension()))
|
||||
self.get_cache_dir()
|
||||
.join(format!("{}.{}.{}", pk, qualifier, C::file_extension()))
|
||||
}
|
||||
|
||||
/// Retourne la route relative pour accéder à un item du cache
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `pk` - Clé primaire de la piste
|
||||
/// * `param` - Paramètre optionnel (ex: "orig", "128k", etc.)
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Route relative (ex: "/audio/flac/abc123" ou "/audio/tracks/abc123/orig")
|
||||
fn route_for(&self, pk: &str, param: Option<&str>) -> String {
|
||||
if let Some(p) = param {
|
||||
format!("/{}/{}/{}/{}", C::cache_name(), C::cache_type(), pk, p)
|
||||
} else {
|
||||
format!("/{}/{}/{}", C::cache_name(), C::cache_type(), pk)
|
||||
}
|
||||
}
|
||||
|
||||
/// Télécharge un fichier depuis une URL et l'ajoute au cache
|
||||
@@ -124,7 +145,6 @@ pub trait FileCache<C: CacheConfig>: Send + Sync {
|
||||
|
||||
/// Consolide le cache en supprimant les orphelins et en re-téléchargeant les fichiers manquants
|
||||
async fn consolidate(&self) -> Result<()>;
|
||||
|
||||
}
|
||||
|
||||
/// Génère une clé primaire à partir d'une URL
|
||||
|
||||
@@ -79,21 +79,3 @@ pub fn new_cache(dir: &str, limit: usize) -> Result<Cache> {
|
||||
let transformer_factory = Arc::new(|| create_webp_transformer());
|
||||
Cache::with_transformer(dir, limit, Some(transformer_factory))
|
||||
}
|
||||
|
||||
/// Retourne la route relative pour accéder à une couverture
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `pk` - Clé primaire de l'image
|
||||
/// * `size` - Taille optionnelle de l'image
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Route relative (ex: "/covers/images/abc123" ou "/covers/images/abc123/300")
|
||||
pub fn route_for(pk: &str, size: Option<usize>) -> String {
|
||||
if let Some(s) = size {
|
||||
format!("/covers/images/{}/{}", pk, s)
|
||||
} else {
|
||||
format!("/covers/images/{}", pk)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
//! Module de compatibilité pour l'ancien module db
|
||||
//!
|
||||
//! Ce module réexporte les types de `pmocache::db` pour maintenir
|
||||
//! la compatibilité avec l'API existante.
|
||||
|
||||
// Réexporter les types de pmocache
|
||||
pub use pmocache::db::{CacheEntry, DB};
|
||||
@@ -634,11 +634,11 @@ mod tests {
|
||||
std::fs::create_dir_all(&audio_dir).ok();
|
||||
|
||||
let cover_cache = Arc::new(
|
||||
pmocovers::Cache::new(cover_dir.to_str().unwrap(), 100, "http://localhost:8080")
|
||||
.await.unwrap()
|
||||
pmocovers::Cache::new(cover_dir.to_str().unwrap(), 100)
|
||||
.unwrap()
|
||||
);
|
||||
let audio_cache = Arc::new(
|
||||
pmoaudiocache::new_cache(audio_dir.to_str().unwrap(), 100, "http://localhost:8080")
|
||||
pmoaudiocache::new_cache(audio_dir.to_str().unwrap(), 100)
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
use once_cell::sync::Lazy;
|
||||
use pmocache::FileCache;
|
||||
use std::sync::RwLock;
|
||||
use pmocovers::Cache as CoverCache;
|
||||
use pmoaudiocache::Cache as AudioCache;
|
||||
@@ -82,7 +83,13 @@ impl CacheRegistry {
|
||||
let base_url = self.base_url
|
||||
.as_ref()
|
||||
.ok_or_else(|| anyhow::anyhow!("Base URL not set in CacheRegistry"))?;
|
||||
let route = pmocovers::cache::route_for(pk, size);
|
||||
let cache = get_cover_cache()
|
||||
.ok_or_else(|| anyhow::anyhow!("No registred cover cache"))?;
|
||||
let param= match size {
|
||||
Some(size_) => Some(size_.to_string()),
|
||||
None => None
|
||||
};
|
||||
let route = cache.route_for(pk, param.as_deref());
|
||||
Ok(format!("{}{}", base_url, route))
|
||||
}
|
||||
|
||||
@@ -100,7 +107,9 @@ impl CacheRegistry {
|
||||
let base_url = self.base_url
|
||||
.as_ref()
|
||||
.ok_or_else(|| anyhow::anyhow!("Base URL not set in CacheRegistry"))?;
|
||||
let route = pmoaudiocache::cache::route_for(pk, param);
|
||||
let cache = get_audio_cache()
|
||||
.ok_or_else(|| anyhow::anyhow!("No registred audio cache"))?;
|
||||
let route = cache.route_for(pk, param);
|
||||
Ok(format!("{}{}", base_url, route))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user