fix: delete thumbnails when files are permanently deleted

- Inject ThumbnailService into TrashService and FileManagementService
- Call delete_thumbnails() after permanent file deletion in:
  - TrashService::delete_permanently (single item)
  - TrashService::empty_trash (bulk: collects file IDs first)
  - FileManagementService::delete_file
  - FileManagementService::delete_with_cleanup (fallback path)
- All thumbnail cleanup is best-effort (warn on failure, never blocks)
- Prevents orphaned thumbnail files from accumulating on disk
This commit is contained in:
Diocrafts
2026-03-07 19:15:36 +01:00
parent 2aeb97383c
commit 661c9cb688
3 changed files with 66 additions and 3 deletions
+4 -1
View File
@@ -261,6 +261,7 @@ impl AppServiceFactory {
repos.file_write_repository.clone(),
trash_service.clone(),
Some(repos.file_read_repository.clone()),
Some(core.thumbnail_service.clone()),
));
let file_use_case_factory = Arc::new(AppFileUseCaseFactory::new(
@@ -302,6 +303,7 @@ impl AppServiceFactory {
pub async fn create_trash_service(
&self,
repos: &RepositoryServices,
core: &CoreServices,
) -> Option<Arc<TrashService>> {
if !self.config.features.enable_trash {
tracing::info!("Trash service is disabled in configuration");
@@ -317,6 +319,7 @@ impl AppServiceFactory {
repos.file_write_repository.clone(),
repos.folder_repository.clone(),
self.config.storage.trash_retention_days,
Some(core.thumbnail_service.clone()),
));
// Initialize cleanup service (bulk-deletes expired items in 2 SQL queries)
@@ -457,7 +460,7 @@ impl AppServiceFactory {
let repos = self.create_repository_services(&core, &pool);
// 3. Trash service (needed before application services)
let trash_service = self.create_trash_service(&repos).await;
let trash_service = self.create_trash_service(&repos, &core).await;
// 4. Application services (with trash already wired)
let mut apps = self.create_application_services(&core, &repos, trash_service.clone());