Commit Graph
37 Commits
Author SHA1 Message Date
john-okeefe a89d5c599d feat: implement Hybrid SSR for bookshelf page
- Add LibraryData type to templates/types.go
- Update bookshelf template to accept libraries parameter
- Render libraries server-side for faster initial page load
- Libraries now populated from server data instead of AJAX fetch
- JavaScript still uses API for dynamic content (bookshelf items)
- Update /bookshelf route to fetch libraries server-side before render
- Properly handle UUID and pgtype.Text conversions
- Maintain API endpoint compatibility for JavaScript calls

This improves initial page load performance while preserving
dynamic functionality via API calls.
2026-02-02 16:46:45 -05:00
john-okeefe 542fbaf116 docs: add Lunr.js search with fuzzy matching and highlighting
Phase 4 part 1: Add search infrastructure
- Add SearchDoc struct and GenerateSearchIndex to docs handler
- Add stripHTML helper for plain text extraction
- Add ServeSearchIndex endpoint to http handler
- Add /docs/search-index.json route in main.go
- Search index includes all documentation files with ID, title, content, URL
2026-02-02 09:08:37 -05:00
john-okeefe 5c7137feb8 docs: add interactive documentation system with Go+HTMX
- Add internal/docs package with markdown renderer (goldmark)
- Create docs layout template with sidebar navigation
- Implement hierarchical navigation auto-generated from docs folder
- Add table of contents generator (extract ## headings)
- Add syntax highlighting for code blocks (highlight.js)
- Add mobile responsive design
- Add /docs routes to main.go

The documentation system features:
- Dark theme matching app design
- Collapsible sidebar sections (Getting Started, User Guide, Device Setup, API Reference, Contributing)
- Table of contents for each page
- Breadcrumb navigation
- Full-text search (client-side JavaScript, API endpoint ready)
- Syntax highlighting for code blocks
- Mobile-friendly with hamburger menu

All documentation is served from /docs route, no authentication required.
Markdown files are rendered using goldmark with GFM extensions and syntax highlighting.
2026-02-01 18:33:55 -05:00
john-okeefe 655ed9225f Update code references and tests: Bookmann → Bookhoard
Code changes:
- main.go: Update cache directory path
- sidecar.go: Update file extension (.bookmann.json → .bookhoard.json)
- security.go: Update CORS example URLs
- queue_test.go: Update test database name
- feed_test.go: Update test assertions
- phase1_integration_test.go: Update test email addresses
- TEST_COVERAGE.md: Update project references

Part of project rename to Bookhoard.
2026-02-01 16:21:10 -05:00
john-okeefe 00a083b60b Rename backend code references: Bookmann → Bookhoard
Backend changes:
- Update import paths: bookmann/internal → bookhoard/internal
- Rename struct fields: BookmannUUID → BookhoardUUID
- Update handler function names: mapContentIdToBookmannUUID → mapContentIdToBookhoardUUID
- Update HTTP response headers: X-Bookmann-* → X-Bookhoard-*
- Update service and middleware references
- Update main.go imports and references

This is part 2 of the project rename to Bookhoard.
2026-02-01 16:11:54 -05:00
john-okeefe c5f327b991 refactor(routes): add new bulk and analytics endpoints, clean up SSR
New endpoints:
- Analytics: /analytics, /analytics/reading-stats, /analytics/device-usage, /analytics/popular-books
- Sync bulk: /sync/bulk-link-books, /sync/auto-link-books, /sync/unlinked-books/:id/suggestions
- Collections bulk: /collections/bulk-add-books
- Books bulk: /books/bulk-delete, /books/bulk-update
- Conflicts bulk: /conflicts/bulk-resolve, /conflicts/bulk-dismiss
- OPDS: /opds/devices/:deviceId/* (catalog, search, nav, download, cover, formats)

Removed:
- Redundant SSR template routes (consolidated into handler methods)
- Manual JWT parsing in routes (use middleware)
- Legacy dashboard and bookshelf routes

Created conversion service instance for OPDS integration
2026-02-01 12:15:52 -05:00
john-okeefe 40c732481a feat(collections): add real-time updates via WebSocket (Limitation #4)
Implement real-time collection updates when books are added/removed:

Backend Changes:
- Added connManager to CollectionHandler struct
- Updated constructor to accept ConnectionManager
- Updated all NewCollectionHandler() calls in ebook.go and main.go
- Added WebSocket broadcasts in AddBooks() handler
- Added WebSocket broadcasts in BulkRemoveBooks() handler
- Broadcasts collection_updated events with:
  - collection_id: Which collection changed
  - action: books_added or books_removed
  - book_ids: Array of affected book IDs
  - count: Number of books changed

Frontend Changes:
- Added WebSocket connection in collections UI
- connectWebSocket() establishes connection to /ws/sync
- Listens for collection_updated events
- Shows toast notification on collection change
- Auto-reloads page after 1 second to show updated book list
- Auto-reconnect on disconnect (5s delay)
- Error handling for WebSocket failures

WebSocket Event Format:
{
  "type": "collection_updated",
  "timestamp": "2026-02-01T12:00:00Z",
  "data": {
    "collection_id": "uuid",
    "action": "books_added",
    "book_ids": ["uuid1", "uuid2"],
    "count": 2
  }
}

User Experience:
- When another user adds books to a collection, all connected clients see:
  1. Toast notification: "Collection updated: books_added (2 books)"
  2. Page auto-refreshes after 1 second
  3. Updated book list displays
- Same for book removal
- Works across multiple browser tabs/devices
- No manual refresh needed

Technical Notes:
- Broadcasts to ALL connected WebSocket clients
- Client-side filtering by collection_id
- Existing progress/conflict broadcasts continue to work
- Connection manager handles broadcast distribution

Resolves Limitation #4: Real-time Collection Updates
2026-02-01 00:54:41 -05:00
john-okeefe ff98c17531 feat(ssr): add server-side routes for Phase 9 frontend features
Add SSR routes for collections, progress, and devices pages:

Progress Page (/api/progress):
- Fetches all user progress with device sync sources
- Maps device types to icons (Kobo, KOReader, Web, Mobile)
- Server-renders progress visualization with real data

Collections Pages (/api/collections):
- GET /collections: List all user collections with SSR
- GET /collections/🆔 Collection detail page with books SSR
- Fetches collection metadata and book listings
- Converts database models to template data structures

Helper Functions:
- getTemplateUserWithTheme: Fetches user with theme preference
- Proper error handling for missing data

All routes use JWT authentication and fetch data server-side
for better SEO and initial page load performance. Client-side
enhancements can be added via HTMX for interactive features.

These routes support the Phase 9 frontend implementation with
proper SSR rendering for improved performance and accessibility.
2026-02-01 00:27:01 -05:00
john-okeefe 6266a06abb feat: Add SSR for conflicts and queue pages
- Update conflicts.templ to accept pre-rendered data
- Update queue.templ to accept pre-rendered data
- Update /conflicts and /queue routes in main.go for SSR
- Update stats rendering to use server-side values
- Add server-side conflict list rendering
- Add server-side queue list rendering
- Update conflicts.js to use location.reload() after operations
- Update queue.js to use location.reload() after operations
- Remove initial load calls from JavaScript files

Preserves all API endpoints and backward compatibility
2026-01-31 23:14:08 -05:00
john-okeefe 5a7144b98e feat: add device management and queue management routes
- Add /devices route for device management interface
- Add /conflicts route for sync conflict resolution
- Add /queue route for sync queue management
- Add comprehensive tests for device cap management
- Add test suite for queue management
2026-01-31 18:25:28 -05:00
john-okeefe a7f2b83bdd Integrate sync queue system and device cap API
- Start queue processor as background goroutine
- Initialize and register queue handler
- Add queue management routes (7 endpoints)
- Update KOReader handler to use checkpoint sync mode
- Add device cap management route (PUT /api/auth/users/:id/max-devices)
- Register all new endpoints with proper middleware
2026-01-31 13:06:56 -05:00
john-okeefe 2d2d643873 Add sync conflict detection and resolution system
Implement conflict detection for concurrent reading progress updates from different devices. Adds conflict management endpoints for listing, viewing, and resolving conflicts.

- Add ConflictHandler with CRUD endpoints for conflict management
- Implement automatic conflict detection in KOReader progress updates
- Add WebSocket broadcast for real-time conflict notifications
- Add database query for listing user conflicts by status
- Add integration tests and Bruno API test collection
2026-01-31 11:45:52 -05:00
john-okeefe 42c3168fcf feat: add server sync to Kobo endpoint and media routes 2026-01-31 00:29:39 -05:00
john-okeefe a3aa9f67ac feat: add Kobo device sync support and fix device route protection
- Add Kobo sync handler with markup, bookmark, analytics, and initialization endpoints
- Add Kobo integration tests and Bruno API test collection
- Move device approve/reject routes from public to protected routes
- Enhance test infrastructure with DATABASE_URL support and helper functions
- Fix device GetDevice handler nil pointer handling
- Clean up test reports and session files
2026-01-30 23:58:34 -05:00
john-okeefe d77585a6f5 feat: add WebSocket endpoint and ConnectionManager setup
Add WebSocket infrastructure to main server:
- Import sync package for ConnectionManager
- Create and start ConnectionManager with cleanup task
- Initialize WSHandler with auth dependencies
- Add /ws/sync WebSocket endpoint
- Update handler initialization to pass ConnectionManager

The WebSocket endpoint at /ws/sync enables real-time progress
updates across all connected clients (web, mobile, devices).
2026-01-30 21:48:21 -05:00
john-okeefe f8a6c3d227 Phase 3 Week 7: Add KOReader routes, tests, and documentation
- Add KOReader sync endpoints to main application router
- Create Bruno API collection for testing KOReader endpoints
- Add integration tests for KOReader functionality
- Include comprehensive README with setup instructions
- Test coverage for progress, metadata, library, and bookmarks sync
- Part of Phase 3 KOReader Integration implementation
2026-01-30 20:55:20 -05:00
john-okeefe a9fdd44471 Add library-based scanning and media item endpoints
- Add POST /api/libraries/:id/scan endpoint for admin library scanning
- Add GET /api/libraries/:id/media-items endpoint for library media items
- Move /api/libraries/types to public endpoint (no auth required)
- Update ScanEbooks handler to support library_id parameter
2026-01-30 20:16:22 -05:00
john-okeefe 23ad70158c Phase 2 Week 5: Device Registration & Management
Implement device registration and management system for universal sync.

Database Changes:
- Add device queries to queries.sql (CRUD operations, registration, auth)
- Add sync queue management queries
- Add conflict resolution queries
- Regenerate sqlc models with new device-related types

Device Handler (devices.go):
- InitiateRegistration: Start device registration with auth URL and QR code
- CheckRegistrationStatus: Poll for registration approval
- ListDevices: Get all devices for current user
- GetDevice: Get specific device details
- UpdateDevice: Update device settings (name, sync settings, frequency)
- DeleteDevice: Remove device from account
- ApproveDevice: User approves device registration via web
- RejectDevice: Reject pending device registration
- ListPendingRegistrations: Show all pending registrations
- generateDeviceToken: Generate secure Bearer token for devices

Device Authentication Middleware (device_auth.go):
- Authenticate: Validate device Bearer tokens
- RequirePermission: Check device permissions by type
- hasPermission: Define permissions per device type
- UpdateLastSeen: Auto-update device last_seen timestamp

Configuration:
- Add BaseURL field to Config for device setup URLs

API Endpoints:
POST /api/devices/register - Initiate device registration
POST /api/devices/register/status - Check registration status
GET /api/devices/approve/:id - Approve device (web UI)
POST /api/devices/reject/:id - Reject device
GET /api/devices - List user's devices
GET /api/devices/:id - Get device details
PUT /api/devices/:id - Update device settings
DELETE /api/devices/:id - Delete device
GET /api/devices/pending - List pending registrations

Bruno API Collection:
- Initiate Device Registration
- Check Registration Status
- List Devices
- Get Device
- Update Device
- Delete Device

Dependencies:
- github.com/skip2/go-qrcode for QR code generation

Device Types Supported:
- koreader: Calibre-compatible sync
- kobo: Kobo sync protocol
- web: Web interface
- mobile: Mobile apps

Device Permissions:
- sync:progress
- sync:annotations
- sync:metadata
- device:manage (web only)
2026-01-30 16:45:10 -05:00
john-okeefe 183a0b795c Fix /bookshelf route - add direct route with JWT authentication
- Added direct /bookshelf route that works with both Authorization header and cookie token
- Imported missing strings package
- Users can now access /bookshelf directly instead of /api/bookshelf
2026-01-29 16:46:57 -05:00
john-okeefe d9ca3d5a65 feat: add /bookshelf route and update redirects
- Add /bookshelf route as default page for logged-in users
- Update login and register handlers to redirect to /bookshelf
- Update homepage to auto-redirect to /bookshelf when logged in
- Preserve /dashboard route for backward compatibility
- Update test redirects to use /bookshelf

Changes:
- main.go: Add /bookshelf protected route
- auth.go: Change login/register redirects from /api/dashboard to /bookshelf (2 locations)
- edge_cases_test.go: Update test redirect to /bookshelf
- Maintains backward compatibility with existing /dashboard route

This makes the beautiful bookshelf the default landing page
for all authenticated users while keeping the old dashboard accessible.
2026-01-29 15:52:11 -05:00
john-okeefe 4dab173b16 fix: serve static files from web directory
- Update static file serving from 'static' to 'web/static'
- Maintains /static/ URL path for backwards compatibility
- Frontend assets now properly separated from backend code
2026-01-29 14:08:59 -05:00
john-okeefe 4b8cb58c84 feat: add configurable test mode and rate limiting
- Add TestMode, RateLimitEnabled, RequestsPerMinute to Config
- Add getEnvBool() and getEnvInt() helper functions
- Update rate limiter to support enabled/disabled state
- Pass test environment variables through docker-compose
- Configure rate limiter dynamically in main.go

This allows disabling rate limiting for integration testing while
maintaining security in production environments.
2026-01-29 13:33:18 -05:00
john-okeefe 799b640ddd chore(server): integrate request tracing and auto-start services
- Add RequestTracingMiddleware to middleware chain
- Auto-start scheduler for auto-scanning on server boot
- Auto-start watch mode for all libraries with 2-second delay
- Update SetupRoutes to return handler for service management
2026-01-29 09:50:40 -05:00
john-okeefe 1e04ef4861 test(security): add comprehensive security tests
- Test password complexity requirements
- Test account lockout mechanism
- Test rate limiting functionality
- Test JWT expiration (1 hour)
- Test refresh token expiration (7 days)
- Test password requirements list
- Verify transaction manager and error handler types
- All tests passing
2026-01-29 09:23:34 -05:00
john-okeefe 7db8bde4bb feat: add rate limiting to authentication endpoints
- Add rate limiter middleware (10 requests/minute per IP)
- Apply rate limiting to POST /api/auth/register and /api/auth/login
- Prevents brute force attacks and registration spam
- Automatic cleanup of old request records

Closes security issue: No rate limiting on auth endpoints
2026-01-29 09:23:33 -05:00
john-okeefe 935b867219 feat: add highlights and notes annotation system
This major update implements a complete user annotation system:

## 🎯 New Features
- User notes with position tracking for media items
- Text highlighting with customizable colors
- Highlight-note associations for detailed annotations
- Full CRUD API for both notes and highlights
- Backward compatibility with existing ebook endpoints

## 📊 Database Changes
- Add media_notes table (id, media_item_id, user_id, content, position, timestamps)
- Add media_highlights table (id, media_item_id, user_id, selection_text, start/end_position, color, optional note_id)
- Add foreign key relationships with CASCADE deletes
- Add proper indexes for performance
- Add database schema views for ebook backward compatibility

## 🔧 API Implementation
- Complete REST API endpoints for notes and highlights
- JWT authentication with proper middleware bypass
- Request validation with meaningful error responses
- UUID validation and type safety
- Support for hex color codes in highlights

## 🧪 Testing & Documentation
- Comprehensive test suite covering authentication scenarios
- Bruno API collection for manual testing
- Detailed testing guide with troubleshooting
- Updated documentation in README and TESTING.md

## 📁 Backward Compatibility
- Existing ebook endpoints continue working
- Database views maintain API contracts
- No breaking changes for existing integrations

The annotation system is now fully functional and ready for production use.
2026-01-28 17:12:40 -05:00
john-okeefe 87e1625564 fix: properly implement JWT user object in middleware
- Update JWT middleware to set complete user object in context
- Parse UUID correctly and convert to pgtype.UUID format
- Add missing imports for uuid and pgx/v5/pgtype
- Fix type conversion from UUID string to byte array
- Ensure compatibility with database.Users struct

Resolves authentication issues for library and user endpoints
2026-01-28 11:34:04 -05:00
john-okeefe e29054f841 feat: integrate library system with routing and handlers
- Add library routes to main router configuration
- Implement media items API endpoints for library content
- Update existing ebook handlers to use new schema
- Add media rating and progress tracking
- Maintain backward compatibility with existing endpoints
- Support library-specific media item queries

Updates application to support new multi-library architecture
2026-01-28 11:02:51 -05:00
john-okeefe 71584c1b55 feat: Enhance admin user management system
- Add admin override capability to DELETE /api/auth/account endpoint
- Move /api/auth/users to admin-only with complete user fields (first_name, last_name, role, theme)
- Consolidate Bruno requests: remove duplicate List Users (Admin), merge Delete Account functionality
- Update all documentation to reflect enhanced capabilities
- Implement pgx 5 standards compliance with proper error handling

BREAKING CHANGES:
- /api/auth/users endpoint now requires admin role (was previously accessible)
- DELETE /api/auth/account accepts optional user_id parameter for admin deletion
2026-01-27 13:36:11 -05:00
john-okeefe f5bfac996d feat: Implement role-based authentication and authorization
- Add AdminMiddleware for protecting sensitive operations
- Update JWT generation to include user role and details
- Modify login/registration to use enhanced JWT claims
- Update main.go to set admin-protected routes
- Add user role to JWT context for downstream handlers
2026-01-26 16:55:32 -05:00
john-okeefe 08e80ae84b refactor: reorganize project structure and update configurations
- Move migrations/ to database/schema/ for clarity on database schema definitions
- Move sqlc.yaml to internal/database/ to group with database code
- Move static/ to cmd/server/static/ to co-locate with server
- Update all configuration files and documentation
- Follow Go project conventions for better organization
2026-01-24 23:40:31 -05:00
john-okeefe 8a951fb242 Update dependencies and fix main.go issues 2026-01-23 21:27:18 -05:00
john-okeefe 7c89e9f214 Simplify homepage: remove auth check, keep login hidden for now 2026-01-23 17:56:29 -05:00
john-okeefe 327b1cc5a4 Add strings import for getToken 2026-01-23 17:55:56 -05:00
john-okeefe 21490af3f0 Add jwtgo import for homepage auth check 2026-01-23 17:55:25 -05:00
john-okeefe 2da9245bfc Update homepage: remove create account, hide login if logged in 2026-01-23 17:54:56 -05:00
john-okeefe 335c63a494 Update main.go to use templ components for routing 2026-01-23 17:47:36 -05:00