Files
bookhoard/bruno/scanner/Scan Media Items.yml
T
john-okeefe d802236874 scanner: fix library isolation, file mtime, force rescan, and deletion handling
Fix 1 - File modification time for created_at:
- Get file.ModTime() in processMediaFile and pass to CreateMediaItem
- Modified SQL INSERT to include created_at column

Fix 2 - Force rescan UPDATE instead of DELETE+INSERT:
- Changed force rescan logic to call updateMediaItem instead of delete + create
- Preserves created_at timestamp on force rescan

Fix 3 - GetMediaItemByFilePath filters by library_id:
- Added library_id to WHERE clause in SQL query
- Created GetMediaItemByFilePathAnyLibrary for cross-library lookups (KOReader)
- Added SetLibraryID method to MediaScanner
- Updated handler to call SetLibraryID for watch mode

Fix 4 - File deletion handling with persistent logging:
- Added fsnotify.Remove handler in WatchChanges
- Added orphan cleanup in ScanFolders after scan completes
- Created scanner_logger.go with daily log rotation (7 days)
- Logs to /app/logs/scanner-deletes-YYYY-MM-DD.log and scanner-errors-YYYY-MM-DD.log
- Individual deletes with enhanced safety logging

Note: Integration tests can now safely scan /app/uploads because
GetMediaItemByFilePath now filters by library_id, preventing
cross-library interference.
2026-02-26 16:39:42 -05:00

74 lines
1.7 KiB
YAML

info:
name: Scan Media Items (Background)
type: http
seq: 1
http:
method: POST
url: "{{base_url}}/api/scanner/scan"
headers:
- name: Content-Type
value: application/json
params:
- name: ""
value: ""
type: query
body:
type: json
data: |-
{
"library_id": "{{library_id}}"
}
auth: inherit
runtime:
scripts:
- type: after-response
code: |-
function onResponse(res) {
try {
const responseBody = res.getBody();
const job_id = responseBody.job_id;
if (job_id) {
bru.setEnvVar("job_id", job_id, { persist: true });
console.log("Access job_id saved:", job_id);
}
if (!job_id) {
console.log("No job_ids found in response.");
}
} catch (error) {
console.error("Error in post-response script:", error.message);
}
}
onResponse(res);
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
docs: |-
## Scan Media Items (Background)
Triggers an asynchronous media items scanning operation. The scan runs in the background and can be monitored using the job ID.
**Method:** POST
**Endpoint:** /api/scanner/scan
**Authentication:** Required (Bearer token, Admin only)
**Request Body:**
- `folder_paths` (array of strings, required): List of folder paths to scan
- Example: `["/path/to/media", "/another/path"]`
**Response:** HTTP 202 (Accepted)
```json
{
"message": "scan job enqueued",
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "pending"