fix: honor library param in /image, /photos, /memories

The Phase 3 plumbing accepted `library=` but didn't actually route
requests through the scoped library once it was resolved. Three
concrete bugs surfaced when testing against a second mounted library:

- `/image` always resolved paths against AppState.base_path (primary),
  so thumbnails for non-primary libraries 400'd when their rel_paths
  didn't exist under primary. Now resolves against the scoped library
  and defaults to primary when the param is omitted.

- `/memories` walked the scoped library correctly but its helper
  functions hardcoded `library_id: PRIMARY_LIBRARY_ID` on every
  MemoryItem, causing clients to route thumbnails back to primary
  regardless of which library the memory actually came from.

- `/photos` non-recursive listing delegated to a `RealFileSystem`
  constructed from AppState.base_path at startup, so walks always
  hit primary even when `library=2` was passed. The non-primary
  path now uses list_files against the scoped library's root;
  primary still goes through FileSystemAccess to preserve the
  existing test mock plumbing.

Also adds `library` to ThumbnailRequest so the /image query param
is actually parsed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Cameron
2026-04-17 17:16:11 -04:00
committed by cameron
parent 0aaea91cc2
commit c01a0479b7
4 changed files with 58 additions and 20 deletions

View File

@@ -369,6 +369,7 @@ fn collect_exif_memories(
exif_dao: &Data<Mutex<Box<dyn ExifDao>>>,
context: &opentelemetry::Context,
base_path: &str,
library_id: i32,
now: NaiveDate,
span_mode: MemoriesSpan,
years_back: u32,
@@ -423,7 +424,7 @@ fn collect_exif_memories(
path: file_path.clone(),
created,
modified,
library_id: crate::libraries::PRIMARY_LIBRARY_ID,
library_id,
},
file_date,
))
@@ -434,6 +435,7 @@ fn collect_exif_memories(
/// Collect memories from file system scan (for files not in EXIF DB)
fn collect_filesystem_memories(
base_path: &str,
library_id: i32,
path_excluder: &PathExcluder,
skip_paths: &HashSet<PathBuf>,
now: NaiveDate,
@@ -485,7 +487,7 @@ fn collect_filesystem_memories(
path: path_relative,
created,
modified,
library_id: crate::libraries::PRIMARY_LIBRARY_ID,
library_id,
},
file_date,
))
@@ -560,6 +562,7 @@ pub async fn list_memories(
&exif_dao,
&span_context,
&scoped_library.root_path,
scoped_library.id,
now,
span_mode,
years_back,
@@ -576,6 +579,7 @@ pub async fn list_memories(
// Phase 2: File system scan (skip EXIF files)
let fs_memories = collect_filesystem_memories(
&scoped_library.root_path,
scoped_library.id,
&path_excluder,
&exif_paths,
now,
@@ -1122,7 +1126,7 @@ mod tests {
path: "photo1.jpg".to_string(),
created: Some(jan_15_2024_9am),
modified: Some(jan_15_2024_9am),
library_id: crate::libraries::PRIMARY_LIBRARY_ID,
library_id: 1,
},
NaiveDate::from_ymd_opt(2024, 1, 15).unwrap(),
),
@@ -1131,7 +1135,7 @@ mod tests {
path: "photo2.jpg".to_string(),
created: Some(jan_15_2020_10am),
modified: Some(jan_15_2020_10am),
library_id: crate::libraries::PRIMARY_LIBRARY_ID,
library_id: 1,
},
NaiveDate::from_ymd_opt(2020, 1, 15).unwrap(),
),
@@ -1140,7 +1144,7 @@ mod tests {
path: "photo3.jpg".to_string(),
created: Some(jan_16_2021_8am),
modified: Some(jan_16_2021_8am),
library_id: crate::libraries::PRIMARY_LIBRARY_ID,
library_id: 1,
},
NaiveDate::from_ymd_opt(2021, 1, 16).unwrap(),
),