feat: implement media processing plugins and update repository structure

This commit is contained in:
2025-11-02 15:40:39 +01:00
parent a5a88c7f33
commit 4427428cf6
14 changed files with 232 additions and 291 deletions

View File

@@ -8,9 +8,11 @@ use libertas_infra::factory::{
use serde::Deserialize;
use uuid::Uuid;
use crate::config::load_config;
use crate::{config::load_config, plugin_manager::PluginManager};
pub mod config;
pub mod plugin_manager;
pub mod plugins;
#[derive(Deserialize)]
struct MediaJob {
@@ -30,14 +32,16 @@ async fn main() -> anyhow::Result<()> {
let album_repo = build_album_repository(&config.database, db_pool.clone()).await?;
let user_repo = build_user_repository(&config.database, db_pool.clone()).await?;
// 3. Create the abstracted PluginContext
let context = Arc::new(PluginContext {
media_repo,
album_repo,
user_repo,
media_library_path: config.media_library_path.clone(),
});
println!("Plugin context created.");
let plugin_manager = Arc::new(PluginManager::new());
let nats_client = async_nats::connect(&config.broker_url).await?;
println!("Connected to NATS server at {}", config.broker_url);
@@ -49,8 +53,9 @@ async fn main() -> anyhow::Result<()> {
while let Some(msg) = subscriber.next().await {
let context = context.clone();
let manager = plugin_manager.clone();
tokio::spawn(async move {
if let Err(e) = process_job(msg, context).await {
if let Err(e) = process_job(msg, context, manager).await {
eprintln!("Job failed: {}", e);
}
});
@@ -59,7 +64,11 @@ async fn main() -> anyhow::Result<()> {
Ok(())
}
async fn process_job(msg: async_nats::Message, context: Arc<PluginContext>) -> anyhow::Result<()> {
async fn process_job(
msg: async_nats::Message,
context: Arc<PluginContext>,
plugin_manager: Arc<PluginManager>,
) -> anyhow::Result<()> {
let job: MediaJob = serde_json::from_slice(&msg.payload)?;
let media = context
@@ -70,10 +79,8 @@ async fn process_job(msg: async_nats::Message, context: Arc<PluginContext>) -> a
println!("Processing media: {}", media.original_filename);
// 3. Pass to the (future) PluginManager
// plugin_manager.process(&media, &context).await?;
plugin_manager.process_media(&media, &context).await;
// For now, we'll just print a success message
println!("Successfully processed job for media_id: {}", media.id);
Ok(())