diff --git a/IMPLEMENTATION_EXACT.md b/IMPLEMENTATION_EXACT.md index 436dd29..1a08c50 100644 --- a/IMPLEMENTATION_EXACT.md +++ b/IMPLEMENTATION_EXACT.md @@ -159,14 +159,15 @@ func (m *DeviceAuthMiddleware) Authenticate(next echo.HandlerFunc) echo.HandlerF ``` **Explanation**: -- `goto validateDevice` is used here as a clean way to jump to common validation code after finding a device +- `goto validateDevice` jumps to common validation code (label at line 221 in the complete function below) - This is Go's idiomatic use of goto for error handling (allowed by PROJECT_GUIDELINES.md) - Tries Bearer header first (for KOReader, API clients), then URL path (Kobo), then query param (OPDS) - Each device type uses only one method: Kobo→URL path, KOReader→Bearer header +- The `validateDevice:` label is preserved in the unchanged section of the function (lines 221-270) -**KEEP THE REST OF THE FUNCTION THE SAME** (lines 62-108 remain unchanged) +**KEEP THE REST OF THE FUNCTION THE SAME** (lines 62-270 remain unchanged, including the `validateDevice:` label at line 221) -**Complete Function After Changes**: +**Complete Function After Changes** (reference for verification, shows how `goto validateDevice` connects to the label): ```go func (m *DeviceAuthMiddleware) Authenticate(next echo.HandlerFunc) echo.HandlerFunc { @@ -491,79 +492,46 @@ func (h *DeviceHandler) RegenerateDeviceToken(c echo.Context) error { **Location**: Multiple locations +**Overview**: After refactor (REFACTORING_PLAN.md Phase 1.3), templates use `handlers.DeviceInfo` directly - no conversion layer exists. Time fields are `*time.Time` (not strings). + **Required Changes**: -1. Add `auth_token` field to `DeviceData` struct +1. Add `auth_token` field to `handlers.DeviceInfo` struct 2. Add "Copy Sync URL" button for each device 3. Add "Regenerate Token" button for each device 4. Add JavaScript functions for copy and regenerate +5. Update time formatting in templates (use `.Format()` method) -**ADD FIELD** to struct: - -```go -type DeviceData struct { - 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 -} -``` - -**ADD FIELD** to struct: - -```go -type DeviceData struct { - 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.2 Update Device List Handler +#### 1.6.1 Add AuthToken to handlers.DeviceInfo Struct **File**: `internal/handlers/devices.go` -**Location**: `GetDevicesData` function (line 275-313) +**Location**: Line 78 (after `DeviceMetadata` field in `DeviceInfo` struct) -**ADD FIELD TO RESPONSE** (modify line 298-309): +**ADD THIS FIELD**: + +```go +type DeviceInfo struct { + ID uuid.UUID `json:"id"` + DeviceName string `json:"device_name"` + DeviceType string `json:"device_type"` + LastSync *time.Time `json:"last_sync"` + LastSeen *time.Time `json:"last_seen"` + SyncEnabled bool `json:"sync_enabled"` + AutoSync bool `json:"auto_sync"` + SyncFrequency int32 `json:"sync_frequency_minutes"` + CreatedAt time.Time `json:"created_at"` + DeviceMetadata json.RawMessage `json:"device_metadata,omitempty"` + AuthToken string `json:"auth_token"` // NEW: Device API key for authentication +} +``` + +#### 1.6.2 Update Device List Handlers + +**File**: `internal/handlers/devices.go` + +**Location**: `GetDevicesData` function (line 275-313) AND `ListDevices` function (line 255-267) + +**GetDevicesData** - ADD FIELD TO RESPONSE (modify line 298-309): ```go deviceList = append(deviceList, DeviceInfo{ @@ -581,7 +549,25 @@ deviceList = append(deviceList, DeviceInfo{ }) ``` -**Do the same** in `ListDevices` function (line 255-267). +**ListDevices** - ADD FIELD TO RESPONSE (modify line around 262): + +Find the loop that constructs `deviceList[i]` and add `AuthToken` field: + +```go +deviceList[i] = DeviceInfo{ + ID: device.ID.Bytes, + DeviceName: device.DeviceName, + DeviceType: device.DeviceType, + LastSync: (*time.Time)(&device.LastSync.Time), + LastSeen: (*time.Time)(&device.LastSeen.Time), + SyncEnabled: syncEnabled, + AutoSync: autoSync, + SyncFrequency: syncFreq, + CreatedAt: device.CreatedAt.Time, + DeviceMetadata: device.DeviceMetadata, + AuthToken: device.AuthToken, // NEW: Include auth token +} +``` #### 1.6.3 Update Device Card Template @@ -632,16 +618,16 @@ for _, device := range devices {