3.5 KiB
3.5 KiB
14 - Trash Feature
Soft-delete for files and folders. Items go to a per-user trash bin instead of being permanently removed. Configurable retention period with automatic cleanup.
Architecture
Follows the hexagonal architecture:
-
Domain Layer (
/src/domain/):- Entities: TrashedItem representing files and folders in the trash
- Repository interfaces: TrashRepository defining trash management operations
-
Application Layer (
/src/application/):- DTOs: TrashedItemDto for data transfer between layers
- Ports: TrashUseCase defining available operations
- Services: TrashService implementing the trash use cases
-
Infrastructure Layer (
/src/infrastructure/):- Repositories: TrashFsRepository for filesystem-based trash storage
- Trash-related methods in existing repositories:
FileWriteRepository::move_to_trash(),FolderRepository::move_to_trash(), etc. - Services: TrashCleanupService for automatic cleanup of expired items
-
Interface Layer (
/src/interfaces/):- API handlers:
trash_handler.rswith HTTP endpoints for trash operations - Routes: updated
routes.rsto include trash endpoints
- API handlers:
Key Features
- Soft Deletion -- files and folders move to trash, not immediately deleted
- Per-User Trash -- each user has an isolated trash bin
- Retention Policy -- items auto-delete after a configurable period
- Restoration -- items can be restored to their original location
- Permanent Deletion -- items can be permanently deleted before retention expires
- Empty Trash -- wipe everything in the trash at once
API Endpoints
GET /api/trashorGET /api/trash/-- list all items in the user's trashDELETE /api/trash/files/:id-- move a file to trashDELETE /api/trash/folders/:id-- move a folder to trashPOST /api/trash/:id/restore-- restore an item to its original locationDELETE /api/trash/:id-- permanently delete an item from trashDELETE /api/trash/empty-- empty the entire trash bin
Testing
-
Unit Tests -- testing TrashService:
- Move files and folders to trash
- Restore items from trash
- Permanent deletion
- Empty trash operation
-
Integration Tests -- Python script hitting the API endpoints:
- End-to-end testing of all trash operations
- Verification of move, list, restore, and delete behavior
-
Shell Script -- for manual testing and demonstration
Configuration
- OXICLOUD_ENABLE_TRASH: enable/disable the trash feature via FeaturesConfig (default: true)
- OXICLOUD_TRASH_RETENTION_DAYS: days to keep items before automatic deletion (default: 30, via StorageConfig)
Implementation Details
- Physical File Storage -- when items are trashed, they physically move to a
.trashdirectory - Metadata Storage -- trashed item info stored in a separate database table or file
- User Isolation -- trash items are isolated by user ID
- Automatic Cleanup -- a background job runs periodically to clean up expired items
- Transaction Safety -- operations are atomic with proper error handling
Future Enhancements
- Trash Quotas -- limit trash storage per user
- Batch Operations -- trash, restore, or delete multiple items at once
- Storage Optimization -- deduplication for trashed items
- Version Control -- track file versions when moving to trash
- Scheduled Cleanup -- let users configure custom retention periods
- Trash Monitoring -- metrics and alerts for trash usage and cleanup