diff --git a/TASKS-scanning-progress.md b/TASKS-scanning-progress.md new file mode 100644 index 0000000..82df616 --- /dev/null +++ b/TASKS-scanning-progress.md @@ -0,0 +1,624 @@ +# Scanning & Dashboard Issues - Implementation Plan + +**Date Created:** 2025-02-24 +**Status:** Documented - Ready to Implement + +--- + +## โ Fixed Issues + +### Bruno Collection File +**File:** `/home/nymusicman/Code/bookhoard/bruno/scanner/Scan Media Items.yml` + +**Problem:** Invalid JSON syntax - library_id variable was not quoted + +**Original (Line 20):** +```yaml +"library_id": {{library_id}} # โ WRONG - UUID not quoted +``` + +**Fixed:** +```yaml +"library_id": "{{library_id}}" # โ CORRECT - quoted string +``` + +**Impact:** Bruno requests now work correctly. API scanning confirmed functional. + +--- + +## ๐ง Remaining Issues + +### Issue 1: Scan Library Button (Frontend) +**Severity:** HIGH - Button completely non-functional +**File:** `templates/admin.templ` (lines 69-85) + +**Current Broken Code:** +```javascript +function quickScan() { + fetch('/api/scanner/scan', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + localStorage.getItem('token') + }, + body: JSON.stringify({ + folder_paths: [] // โ EMPTY ARRAY! Causes 400 error + }) + }) +} +``` + +**Why It Fails:** +- Sends `folder_paths: []` (empty array) +- Handler checks `if len(req.FolderPaths) > 0` โ FALSE for empty array +- Returns 400: "either library_id or folder_paths required for scanning" +- No scan job is created +- No progress feedback +- Users can't scan from UI + +**What Should Happen:** +1. Fetch all libraries from `/api/libraries` +2. Trigger scan for each library via `/api/libraries/{id}/scan` +3. Collect all job IDs +4. Poll `/api/scanner/status/{jobId}` for progress +5. Display progress UI +6. Show results when complete + +--- + +### Issue 2: Scanned Books Not Showing on Dashboard +**Severity:** MEDIUM - Data exists but not visible +**Status:** Requires diagnosis + +**Symptoms:** +- Book successfully scanned via API +- Book exists in database +- Book not visible on `/dashboard` page +- Book appears in `/api/media-items` endpoint + +**Expected Behavior:** +- Book should appear in "recently-added" section +- Should be at top of list (most recent `created_at`) +- Should be visible immediately after scan + +**Possible Root Causes:** + +#### Hypothesis 1: System Collections Missing +- System collections (including "recently-added") created during user registration +- Possible creation failure or user created before feature existed +- Check: Query database for user's system collections + +#### Hypothesis 2: Wrong Library Selected +- Dashboard shows books for selected library only +- Book might be in different library than displayed +- Check: Compare book's library_id with dashboard's selected library + +#### Hypothesis 3: Collection Hidden +- User preferences might hide "recently-added" collection +- `show_on_dashboard = false` in database +- Check: User's dashboard preferences + +#### Hypothesis 4: Empty Result Set +- Query limit too low +- Ordering incorrect +- Check: API responses directly + +--- + +## ๐ Implementation Plan + +### Part 1: Fix Scan Library Button + +**Files to Modify:** +- `templates/admin.templ` + +**Implementation Steps:** + +#### Step 1: Replace quickScan() Function + +**Location:** `templates/admin.templ` lines 69-85 + +**New Implementation:** +```javascript +async function quickScan() { + const token = localStorage.getItem('token'); + + try { + // Step 1: Get all libraries + const libsResp = await fetch('/api/libraries', { + headers: { 'Authorization': `Bearer ${token}` } + }); + + if (!libsResp.ok) { + throw new Error('Failed to get libraries'); + } + + const libsData = await libsResp.json(); + + if (!libsData.data || libsData.data.length === 0) { + alert('No libraries found. Please create a library first.'); + return; + } + + const libraries = libsData.data; + + // Step 2: Scan each library + const jobs = []; + const libraryNames = {}; + + for (const lib of libraries) { + const scanResp = await fetch(`/api/libraries/${lib.id}/scan`, { + method: 'POST', + headers: { 'Authorization': `Bearer ${token}` } + }); + + if (scanResp.ok) { + const result = await scanResp.json(); + jobs.push(result.job_id); + libraryNames[result.job_id] = lib.name; + } else { + console.error(`Failed to scan library: ${lib.name}`); + } + } + + if (jobs.length === 0) { + alert('Failed to start scan for any library'); + return; + } + + // Step 3: Show progress UI + showScanProgress(jobs, libraryNames); + + } catch (error) { + console.error('Scan error:', error); + alert('Failed to start scan: ' + error.message); + } +} +``` + +#### Step 2: Add Progress UI to admin.templ + +**Location:** After the Quick Actions grid (around line 64) + +**Add this HTML:** +```html + +