Auto-delete Feature for Trash (Backend + Frontend + Tests) (Solving ISSUE: #1658) #2079
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
✨ Auto-delete Feature for Trash (Backend + Frontend + Tests)
This PR introduces a complete Auto-delete system for the Trash, integrating both backend logic and frontend behavior while preserving Puter’s existing UX patterns.
Solved the [Feature Request] Auto-delete files from the recycle bin #1658
Backend: Periodic Auto-Delete Service
Added a new
TrashAutoDeleteServicerunning every 30 minutes.For each user, the service:
Reads their auto_delete_days preference from kv.
Finds files in the user’s Trash folder.
Determines which entries are expired based on the configured time window.
Emits a trash.auto_delete socket event for each expired file.
No files are deleted directly in the backend — it only emits events.
The frontend handles deletion using the same existing UX flow as manual deletes.
🖥️ Frontend: Context Menu Integration + Trash Updates
Context Menu Integration
Auto-delete settings are now accessible from three key places:
Trash window context menu
Trash desktop icon context menu
Trash taskbar icon context menu
Users can choose:
Disabled
24 hours
7 days
30 days
The selection is stored using Puter’s kv system, allowing the backend service to access user preferences.
Trash UI Reaction
When the backend emits a trash.auto_delete event:
The frontend seamlessly removes the entry from the Trash UI.
This uses the same code path as normal Trash deletions, ensuring consistent behavior.
🧪 Test Coverage
Backend (Vitest)
Added a full unit test suite covering:
Single expired item deletion
Multiple expired items
Disabled preference (0)
Missing or malformed timestamps
Multiple users with independent Trash folders
DB failure logging behavior
Periodic scheduling logic
These tests avoid requiring a full Kernel environment by fully mocking DB, helpers, and socket services.
Frontend (Playwright)
Added a Playwright test to verify that the frontend correctly handles socket-emitted auto-delete events.
📁 Summary
This PR adds a complete, fully tested Auto-delete system that:
Respects per-user preferences
Uses Puter’s existing architecture (KV, services, socket events)
Integrates smoothly into the frontend with minimal changes
Maintains UX consistency with existing Trash operations
Let me know if you'd like the PR broken into smaller commits or if any part should be refactored!