2026-05-21 23:56:14 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2026-05-22 13:10:47 +02:00
|
|
|
use crate::application::ports::file_lifecycle::FileLifecycleHook;
|
2026-05-21 23:56:14 +02:00
|
|
|
|
|
|
|
|
/// Composite dispatcher for file lifecycle events.
|
|
|
|
|
///
|
2026-05-22 13:10:47 +02:00
|
|
|
/// Aggregates all [`FileLifecycleHook`] implementations and fans out each
|
|
|
|
|
/// event to every registered handler. Services hold a single
|
|
|
|
|
/// `Arc<FileLifecycleService>` — new handlers are added once, in DI, without
|
|
|
|
|
/// touching the services themselves.
|
2026-05-21 23:56:14 +02:00
|
|
|
pub struct FileLifecycleService {
|
2026-05-22 13:10:47 +02:00
|
|
|
hooks: Vec<Arc<dyn FileLifecycleHook>>,
|
2026-05-21 23:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for FileLifecycleService {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self::new()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FileLifecycleService {
|
|
|
|
|
pub fn new() -> Self {
|
2026-05-22 13:10:47 +02:00
|
|
|
Self { hooks: Vec::new() }
|
2026-05-21 23:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-22 13:10:47 +02:00
|
|
|
pub fn with_hook(mut self, hook: Arc<dyn FileLifecycleHook>) -> Self {
|
|
|
|
|
self.hooks.push(hook);
|
2026-05-21 23:56:14 +02:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-22 13:10:47 +02:00
|
|
|
impl FileLifecycleHook for FileLifecycleService {
|
|
|
|
|
fn on_file_created(
|
|
|
|
|
&self,
|
|
|
|
|
file_id: &str,
|
|
|
|
|
blob_hash: &str,
|
|
|
|
|
content_type: &str,
|
|
|
|
|
is_new_blob: bool,
|
|
|
|
|
) {
|
|
|
|
|
for hook in &self.hooks {
|
|
|
|
|
hook.on_file_created(file_id, blob_hash, content_type, is_new_blob);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn on_file_copied(
|
|
|
|
|
&self,
|
|
|
|
|
file_id: &str,
|
|
|
|
|
blob_hash: &str,
|
|
|
|
|
content_type: &str,
|
|
|
|
|
source_file_id: &str,
|
|
|
|
|
) {
|
|
|
|
|
for hook in &self.hooks {
|
|
|
|
|
hook.on_file_copied(file_id, blob_hash, content_type, source_file_id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn on_file_updated(&self, file_id: &str, blob_hash: &str, content_type: &str) {
|
|
|
|
|
for hook in &self.hooks {
|
|
|
|
|
hook.on_file_updated(file_id, blob_hash, content_type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn on_file_deleted(&self, file_id: &str) {
|
|
|
|
|
for hook in &self.hooks {
|
|
|
|
|
hook.on_file_deleted(file_id);
|
|
|
|
|
}
|
2026-05-21 23:56:14 +02:00
|
|
|
}
|
|
|
|
|
}
|