refactor(lifecycle hooks): simplify integration of new services

* make more coherent lifecycles
  * remove specific implementation on different handlers (they do not need to know existence of ThumbnailSerice nor AudioMetadataService)
  * reduce risk of orphean objects
  * ensure additional services are correctly wired (ex: Thumbnail generation was not covering all upload cases)
  * more details on docs/architecture/file-and-blob-lifecycle.md :

```rust
// application/ports/file_lifecycle.rs
pub trait FileLifecycleHook {

    fn on_file_created(file_id, blob_hash, content_type, is_new_blob);
    fn on_file_updated(file_id, blob_hash, content_type);
    fn on_file_copied(file_id, blob_hash, content_type, source_id)
    fn on_file_deleted(file_id);
}

// application/ports/blob_lifecycle.rs
pub trait BlobLifecycleHook {

    fn on_blob_created(blob_hash, content_type);
    fn on_blob_deleted(blob_hash);
}
```
This commit is contained in:
Edouard Vanbelle
2026-05-22 13:10:47 +02:00
parent 9206669ee6
commit 73f0b0fa47
19 changed files with 842 additions and 403 deletions
+7 -7
View File
@@ -7,7 +7,7 @@ use crate::application::dtos::display_helpers::{
};
use crate::application::dtos::trash_dto::TrashedItemDto;
use crate::application::ports::authorization_ports::AuthorizationEngine;
use crate::application::ports::file_lifecycle::FileDeletedHook;
use crate::application::ports::file_lifecycle::FileLifecycleHook;
use crate::application::ports::storage_ports::{FileReadPort, FileWritePort};
use crate::application::ports::trash_ports::TrashUseCase;
use crate::common::errors::{DomainError, ErrorKind, Result};
@@ -53,8 +53,8 @@ pub struct TrashService {
/// orphaned blob files and thumbnails that the PG trigger cannot reach.
dedup_service: Arc<DedupService>,
/// Hook fired after a file is permanently deleted (typically the FileLifecycleService composite).
file_deleted_hook: Option<Arc<dyn FileDeletedHook>>,
/// Lifecycle hook dispatcher — fired on file permanently deleted.
file_deleted_hook: Option<Arc<dyn FileLifecycleHook>>,
/// Content cache — invalidated when files are permanently deleted from trash.
content_cache: Option<Arc<FileContentCache>>,
@@ -91,8 +91,8 @@ impl TrashService {
}
}
/// Sets the lifecycle hook fired after a file is permanently deleted.
pub fn with_file_deleted_hook(mut self, hook: Arc<dyn FileDeletedHook>) -> Self {
/// Sets the lifecycle hook dispatcher (thumbnails, audio metadata, …).
pub fn with_file_deleted_hook(mut self, hook: Arc<dyn FileLifecycleHook>) -> Self {
self.file_deleted_hook = Some(hook);
self
}
@@ -583,7 +583,7 @@ impl TrashUseCase for TrashService {
}
if let Some(hook) = &self.file_deleted_hook {
hook.on_file_deleted(&file_id).await;
hook.on_file_deleted(&file_id);
}
}
TrashedItemType::Folder => {
@@ -723,7 +723,7 @@ impl TrashUseCase for TrashService {
if let Some(hook) = &self.file_deleted_hook {
for file_id in &trashed_file_ids {
hook.on_file_deleted(file_id).await;
hook.on_file_deleted(file_id);
}
}