Refactor: Eliminate duplicate types - Use handler types directly
- Deleted templates.CollectionDetailData - using templates.CollectionData everywhere - Deleted templates.BookData - using handlers.BookInfo everywhere - Deleted templates.DeviceData - using handlers.DeviceInfo everywhere - Deleted templates.ProgressItemData - using handlers.ProgressWithMedia everywhere - Deleted templates.convertDevices() helper - Use handlers types directly in templates - Enhanced handlers.ProgressWithMedia with device metadata fields - Added handlers.getDeviceIcon() helper - Updated all templates to import handlers package - Cleaned up unused imports This aligns codebase with templ's design philosophy (use Go types directly, no parallel type system)
This commit is contained in:
+49
-25
@@ -42,6 +42,7 @@
|
||||
- `internal/router/device.go` - Add regenerate token route
|
||||
- `internal/handlers/devices.go` - Add regenerate token handler
|
||||
- `templates/devices.templ` - Add copy/regenerate UI
|
||||
- `web/src/device-management.ts` - Add device management TypeScript
|
||||
- `bruno/sync-kobo/api.bru` - Add URL path token requests
|
||||
- `bruno/devices/regenerate-*.bru` - New token regeneration test files
|
||||
- `bruno/opds/*-*.bru` - New OPDS authentication test files
|
||||
@@ -86,14 +87,6 @@ SET
|
||||
updated_at = NOW()
|
||||
WHERE id = $1
|
||||
RETURNING *;
|
||||
|
||||
-- name: RevokeDevice :exec
|
||||
UPDATE devices
|
||||
SET
|
||||
auth_token = NULL,
|
||||
sync_enabled = false,
|
||||
updated_at = NOW()
|
||||
WHERE id = $1;
|
||||
```
|
||||
|
||||
**Verification**: Run `go build ./...` after adding this query to ensure sqlc generates the new function correctly.
|
||||
@@ -504,24 +497,45 @@ func (h *DeviceHandler) RegenerateDeviceToken(c echo.Context) error {
|
||||
3. Add "Regenerate Token" button for each device
|
||||
4. Add JavaScript functions for copy and regenerate
|
||||
|
||||
#### 1.6.1 Update DeviceData Struct
|
||||
|
||||
**Location**: Find `DeviceData` struct (near top of file)
|
||||
|
||||
**Current struct** (lines vary, find structure):
|
||||
**ADD FIELD** to struct:
|
||||
|
||||
```go
|
||||
type DeviceData struct {
|
||||
ID string
|
||||
DeviceName string
|
||||
DeviceType string
|
||||
LastSync string
|
||||
LastSeen string
|
||||
SyncEnabled bool
|
||||
AutoSync bool
|
||||
SyncFrequency int
|
||||
ID string
|
||||
DeviceName string
|
||||
DeviceType string
|
||||
LastSync string
|
||||
LastSeen string
|
||||
SyncEnabled bool
|
||||
AutoSync bool
|
||||
SyncFrequency int
|
||||
CreatedAt string
|
||||
DeviceMetadata json.RawMessage
|
||||
AuthToken string // NEW: Device API key for authentication
|
||||
}
|
||||
```
|
||||
|
||||
#### 1.6.3 Update Collection Detail Template
|
||||
|
||||
**File**: `templates/collection.templ`
|
||||
|
||||
**Location**: Line 213 (function signature)
|
||||
|
||||
**Current**:
|
||||
```templ
|
||||
templ CollectionDetail(user User, collection CollectionDetailData, books []BookData) {
|
||||
```
|
||||
|
||||
**CHANGE** (use handlers.BookInfo):
|
||||
|
||||
```templ
|
||||
templ CollectionDetail(user User, collection CollectionData, books []handlers.BookInfo) {
|
||||
```
|
||||
|
||||
**ADD FIELD** to struct:
|
||||
|
||||
```go
|
||||
AuthToken string // NEW: Device API key for authentication
|
||||
}
|
||||
```
|
||||
|
||||
@@ -872,7 +886,7 @@ put {
|
||||
docs {
|
||||
## Regenerate Device Token
|
||||
|
||||
Regenerates the auth token for a device, invalidating the old token immediately.
|
||||
Regenerates auth token for a device, invalidating old token immediately.
|
||||
|
||||
**Method:** PUT
|
||||
|
||||
@@ -899,7 +913,7 @@ docs {
|
||||
**Important Notes:**
|
||||
- Old token stops working immediately
|
||||
- Device must be updated with new token to resume syncing
|
||||
- No data loss - device ID remains the same
|
||||
- No data loss - device ID remains same
|
||||
|
||||
**Example Response:**
|
||||
```json
|
||||
@@ -911,14 +925,24 @@ docs {
|
||||
"device_name": "My Kobo Clara",
|
||||
"device_type": "kobo",
|
||||
"sync_enabled": true,
|
||||
"auto_sync": true
|
||||
"auto_sync": true,
|
||||
"sync_frequency_minutes": 5,
|
||||
"created_at": "2026-02-12T10:00:00Z",
|
||||
"device_metadata": "{...}"
|
||||
},
|
||||
"sync_urls": {
|
||||
"sync_url": "http://localhost:8765/api/sync/kobo/dev_new_token",
|
||||
"markup": "http://localhost:8765/api/sync/kobo/dev_new_token/markup"
|
||||
"markup": "http://localhost:8765/api/sync/kobo/dev_new_token/markup",
|
||||
"bookmark": "http://localhost:8765/api/sync/kobo/dev_new_token/bookmark",
|
||||
"init": "http://localhost:8765/api/sync/kobo/dev_new_token/v1/initialization"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Important Notes:**
|
||||
- Old token stops working immediately
|
||||
- Device must be updated with new token to resume syncing
|
||||
- No data loss - device ID remains same
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user