Overview
UploadHistoryStore manages the upload history by persisting completed uploads to UserDefaults. It provides an observable list of upload items that automatically syncs to disk, allowing users to track their upload activity across app launches.
Located at:
Fiaxe/Services/UploadHistoryStore.swift:6Type Definition
Properties
items
The current list of upload history items.[UploadItem]
Array of completed uploads, sorted with newest first. Automatically persisted to UserDefaults.
Methods
add()
Adds a new upload item to the history.UploadItem
required
The upload item to add to history. Contains file name, size, R2 key, upload date, and public URL.
Implementation Details
- Inserts the new item at index 0 (beginning of array)
- Maintains reverse chronological order (newest first)
- Automatically persists to UserDefaults
remove()
Removes upload items at the specified indices.IndexSet
required
Indices of items to remove. Typically provided by SwiftUI’s
onDelete modifier.Implementation Details
clearAll()
Removes all items from the history.Implementation Details
Persistence Implementation
The store uses UserDefaults with JSON encoding:String
UserDefaults key:
"fiaxe.uploadHistory"Initialization
The store automatically loads saved history on initialization:Data Format
History is stored as JSON-encoded array ofUploadItem objects:
Usage Example
Adding Items After Upload
Automatic Persistence
Observable Behavior
The@Observable macro enables automatic SwiftUI updates:
- Items are added
- Items are removed
- All items are cleared
Integration with r2Vault
The upload history is integrated into the menu bar popover:- View recent uploads
- Copy public URLs
- Delete individual items
- Clear entire history
Data Retention
Unlimited HistoryThe current implementation stores all uploads indefinitely. For production use, consider:
- Limiting to the most recent N uploads
- Auto-deleting items older than X days
- Implementing search/filter functionality
- Adding pagination for large histories
Privacy Considerations
Error Handling
The store gracefully handles encoding/decoding errors:- Empty history on load failure
- No persistence on save failure
- No crashes or error messages
Testing Considerations
For testing, use a separate UserDefaults suite:Related Services
- UploadItem - Data model for upload history entries
- R2UploadService - Performs uploads that get recorded
- KeychainService - Also uses UserDefaults for persistence