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.
This commit is contained in:
@@ -2,7 +2,20 @@ info:
|
||||
name: Get Book Collections
|
||||
type: http
|
||||
seq: 12
|
||||
|
||||
http:
|
||||
method: GET
|
||||
url: '{{base_url}}/api/collections/books/{{book_id}}'
|
||||
url: "{{base_url}}/api/collections/books"
|
||||
body:
|
||||
type: json
|
||||
data: |-
|
||||
{
|
||||
"collection_id": "{{collection_id}}"
|
||||
}
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
followRedirects: true
|
||||
maxRedirects: 5
|
||||
|
||||
@@ -13,9 +13,9 @@ variables:
|
||||
- name: note_id
|
||||
value: 7710a602-g29b-61d4-c716-446655440002
|
||||
- name: library_id
|
||||
value: 551ac19c-896a-4406-b479-353fc489b295
|
||||
value: 849151fb-564e-4b24-89e3-d11360789576
|
||||
- name: job_id
|
||||
value: 450094c6-a8f1-4125-aea7-77df80223877
|
||||
value: 295654b3-eb4b-4e85-ac6c-9361c5821195
|
||||
- name: rating
|
||||
value: "5"
|
||||
- name: is_visible
|
||||
@@ -33,4 +33,4 @@ variables:
|
||||
- secret: true
|
||||
name: other_device_id
|
||||
- name: collection_id
|
||||
value: 11e8d915-ef95-4257-98b3-b8eeacfd59b9
|
||||
value: 412c03c3-0843-4bd4-b764-cc9457bb9df2
|
||||
|
||||
@@ -2,15 +2,20 @@ info:
|
||||
name: Get Scan Settings
|
||||
type: http
|
||||
seq: 2
|
||||
|
||||
http:
|
||||
method: GET
|
||||
url: '{{base_url}}/api/library/scan-settings'
|
||||
auth: inherit
|
||||
body:
|
||||
type: none
|
||||
url: "{{base_url}}/api/libraries/scan-settings"
|
||||
headers:
|
||||
- key: Content-Type
|
||||
value: application/json
|
||||
- name: ""
|
||||
value: application/json
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
followRedirects: true
|
||||
maxRedirects: 5
|
||||
|
||||
docs: |-
|
||||
## Get Scan Settings
|
||||
|
||||
@@ -2,17 +2,27 @@ info:
|
||||
name: Update Scan Settings
|
||||
type: http
|
||||
seq: 1
|
||||
|
||||
http:
|
||||
method: PUT
|
||||
url: '{{base_url}}/api/library/scan-settings'
|
||||
auth: inherit
|
||||
url: "{{base_url}}/api/libraries/scan-settings"
|
||||
headers:
|
||||
- name: ""
|
||||
value: application/json
|
||||
body:
|
||||
type: json
|
||||
jsonBody: "{\n \"scan_frequency_minutes\": 60,\n \"auto_scan_enabled\":\
|
||||
\ true"
|
||||
headers:
|
||||
- key: Content-Type
|
||||
value: application/json
|
||||
data: |-
|
||||
{
|
||||
"scan_frequency_minutes": 30,
|
||||
"auto_scan_enabled": true
|
||||
}
|
||||
auth: inherit
|
||||
|
||||
settings:
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
followRedirects: true
|
||||
maxRedirects: 5
|
||||
|
||||
docs: |-
|
||||
## Update Scan Settings
|
||||
|
||||
@@ -21,6 +21,29 @@ http:
|
||||
}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user