Commit Graph
8 Commits
Author SHA1 Message Date
john-okeefe e854492887 refactor: use ScannerHandler directly for library convenience routes
Previously, library routes used a generic NewHandler for convenience routes.
Now uses cfg.ScannerHandler directly for consistency with other scanner
endpoints and to ensure proper handler-specific middleware is applied.
2026-02-26 17:25:27 -05:00
john-okeefe 2af035d87f feat(backend): add server-side directory browsing API
- Add BrowseDirectories() to library service with path traversal protection
- Add BrowseDirectories handler with proper error handling
- Register GET /api/libraries/browse endpoint (admin-only)
- Returns current path, parent path, and list of subdirectories
- Security: blocks "..", validates path exists, checks is directory

Fixes: Issue 2 (backend)
2026-02-23 17:02:52 -05:00
john-okeefe 938e5eed53 feat(router): add system settings routes and handler wiring
Router configuration updates:
- Add SystemSettingsHandler to Config struct
- Register GET /api/libraries/scan-settings (admin-only)
- Register PUT /api/libraries/scan-settings (admin-only)
- Wire SystemSettingsHandler in main.go

These routes replace per-user scan settings endpoints with
system-wide admin-only endpoints.
2026-02-09 20:10:30 -05:00
john-okeefe 001647cbbe Fix goroutine leaks in sync queue processor and connection manager
Critical fixes to prevent goroutine leaks during application shutdown:

1. Sync Queue Processor:
   - Changed StartCleanupTask() to return context.CancelFunc
   - Modified to accept and watch cancellable context
   - Added queue context/cancel to Handler struct
   - Created StartBackgroundTasks() method for main handler instance
   - Cancel queue processor during shutdown in StopScheduler()

2. Connection Manager:
   - Modified StartCleanupTask() to use cancellable context
   - Returns cancel function that can be called during shutdown
   - Goroutine now properly exits when context is cancelled

3. Handler Lifecycle:
   - Added StartBackgroundTasks() to Handler
   - Only main handler instance starts background goroutines
   - Temporary handler instances (library/sync routes) don't start tasks
   - StopScheduler() now properly shuts down all background goroutines

4. Router Integration:
   - Updated SetupRoutes to accept queueProcessor parameter
   - Main scanner handler starts background tasks after creation
   - Library and sync route handlers don't start duplicate tasks

Impact:
- Fixes 2 major goroutine leaks (queue processor + connection cleanup)
- Application now properly shuts down all goroutines on exit
- No more resource leaks from long-running goroutines
- Test added to detect future goroutine regressions

Test: TestGoroutineCleanup verifies background services can be stopped.
2026-02-09 13:12:31 -05:00
john-okeefe adc7acbe0f refactor(api): rename ScanEbooks to ScanLibrary for clarity
- Rename ScanEbooks method to ScanLibrary to reflect generic media scanning

- Rename ScanEbooksRequest to ScanLibraryRequest

- Update route handlers in scanner.go and library.go

- Rename scan_ebooks.md to scan_library.md

- No breaking changes: API endpoint remains POST /api/scanner/scan
2026-02-08 13:33:04 -05:00
john-okeefe eb73e4a9f9 refactor(handlers): Phase 7 - cleanup ebook.go, remove duplicate methods
- Remove 24 duplicate media CRUD methods from ebook.go (884 lines removed)
- Keep 12 scanner/watch/scheduler methods on Handler
- Move request type declarations to media.go:
  * CreateMediaItemRequest
  * UpdateMediaItemRequest
  * CreateMediaNoteRequest
  * UpdateMediaNoteRequest
  * CreateMediaHighlightRequest
  * UpdateMediaHighlightRequest
- Remove unused imports from ebook.go (strconv, pgx)
- Fix library.go to use MediaHandler.ListMediaItems instead of Handler

ebook.go reduced from 1266 lines to 382 lines (70% reduction)
Handler now has focused responsibility: scanner and scheduler operations only

This completes Phase 7 of the ebook.go refactoring plan.

Result: Clean separation of concerns with no duplicate code
2026-02-07 19:56:52 -05:00
john-okeefe a75cd7e51a refactor: simplify router configuration and handler setup
- Move JWT middleware creation to shared function
- Simplify library route registration
- Add bulk-add-books endpoint to collections
- Clean up duplicate handler setup code
- Improve route organization and maintainability
2026-02-06 17:04:17 -05:00
john-okeefe 2dd0238ef2 refactor: add library and device route stubs to router package
Add stub implementations for:
- library.go: Library management routes (admin + user visibility)
- device.go: Device registration and management routes
- router.go: Updated to import jwt package

Router package structure is complete with all route groups defined.
Next step: Incrementally migrate routes from main.go by calling
router.RegisterRoutes() and removing duplicate definitions.

All verification checks pass (26/26).
2026-02-06 11:21:38 -05:00