Automatic management
File watchers are automatically managed by the Studio service:- Auto-initialization - Watchers are created for all devices on service startup
- Periodic sync - Watchers sync with the device list every 5 minutes
- Graceful cleanup - Orphaned watchers are cleaned up when devices are deleted
- Error recovery - Watchers are automatically restarted if they encounter errors
Get watcher status
GET /api/watchers
Get status of all file watchers
Response
Array of watcher status objects
Device identifier
Whether the watcher is currently active
Path being monitored
ISO 8601 timestamp of last file detection
Example request
Check device watcher status
GET /api/watchers/:deviceId/status
Check if a specific device has an active watcher
Path parameters
Device identifier
Response
Whether the watcher is active for this device
Device identifier
Path being monitored (if active)
Example request
Add watcher
POST /api/watchers/:deviceId/add
Add a file watcher for a specific device
Path parameters
Device identifier
Response
Indicates if the watcher was added successfully
Device identifier
Example request
Remove watcher
DELETE /api/watchers/:deviceId
Remove the file watcher for a specific device
Path parameters
Device identifier
Response
Indicates if the watcher was removed successfully
Device identifier
Example request
Sync watchers
POST /api/watchers/sync
Synchronize watchers with the current device list
Description
This endpoint:- Adds watchers for devices that don’t have one
- Removes watchers for devices that no longer exist
- Ensures all active devices are being monitored
Response
Indicates if synchronization was successful
Number of watchers added
Number of watchers removed
Example request
Refresh watchers
POST /api/watchers/refresh
Restart all file watchers
Description
Useful after configuration changes or to recover from errors. This endpoint:- Stops all active watchers
- Restarts watchers for all devices
- Reloads configuration
Response
Indicates if refresh was successful
Number of watchers restarted
Example request
Clean up orphaned watchers
POST /api/watchers/cleanup-orphaned
Manually clean up watchers for deleted devices
Description
Removes watchers for devices that no longer exist in the database. This is automatically done during periodic sync, but can be triggered manually.Response
Indicates if cleanup was successful
Number of orphaned watchers removed
Example request
File watcher behavior
Detection
When a file watcher detects a new file in the incoming directory:- File detection - New file appears in incoming directory
- Metadata extraction - File size, type, and name are determined
- Gallery record creation - Database record is created
- Thumbnail processing - Checks for matching thumbnail file
- File movement - Moves file from incoming to processed directory
- Hook execution - Triggers
on_file_detectedhooks
Monitoring
File watchers monitor the incoming directory continuously and:- Detect new files immediately
- Handle multiple files concurrently
- Skip temporary and hidden files
- Process files atomically to avoid race conditions
Error handling
If a watcher encounters an error:- Error is logged with details
- Watcher attempts automatic recovery
on_errorhooks are triggered- Problematic files are quarantined