fix(memories): search the photo provider by the local day, not the UTC one

"This day" sent the entry's calendar date to the provider as both bounds, and
both providers turned that date into a UTC window — Immich by concatenating a
Z suffix, Synology by relying on a date-only string parsing as UTC midnight.
For a reader at UTC+10 the searched window was 10:00 on the day to 09:59 the
next morning, so every breakfast photo was missing while the next morning's
turned up in its place, and nothing said the day was incomplete. The date
headings had the mirror defect, filing a 07:32 photo under the previous day.

Immich publishes the right anchor already: localDateTime is required on every
search result and is what its own timeline groups by. The window is padded by
a day on each side and the page narrowed again by each photo's own local date,
carried through as localTakenAt; a server that does not send it falls back to
the timestamp used until now, so nothing changes there. Because the padding
means raw rows and answered rows are no longer the same thing, the page is
filled server-side until it holds what the caller asked for, bounded so a
pathological album cannot spin.

Synology has no local stamp, so its anchor comes from the caller as a UTC
offset, resolved for the day being searched rather than for today — a day
looked up across a DST boundary would otherwise start an hour out. The MCP
tool takes the same optional input, defaulting to the behaviour it has now.

The picker's pagination sentinel moved out of the non-empty branch: a page the
new filter empties has to keep paging, and it now says so instead of claiming
there are no photos.

Closes #2336
This commit is contained in:
Maurice
2026-09-16 13:01:30 +02:00
parent a782e0e471
commit 1e35a99c11
20 changed files with 922 additions and 156 deletions
+26 -2
View File
@@ -1,4 +1,3 @@
import { describe, it, expect } from 'vitest';
import {
addTripPhotosSchema,
createAlbumLinkSchema,
@@ -10,6 +9,8 @@ import {
synologyTestSchema,
} from './memories.schema';
import { describe, it, expect } from 'vitest';
/**
* These contracts exist to describe what the endpoints already accept, not to
* tighten them — the nine routes were read as `Record<string, unknown>` and
@@ -36,6 +37,13 @@ describe('immich contracts', () => {
it('rejects a page that is neither', () => {
expect(immichSearchSchema.safeParse({ page: { nope: true } }).success).toBe(false);
});
it('takes the zone the dates are meant in, even though Immich answers by the photo', () => {
// One body goes to whichever provider, so the field has to parse on both.
expect(immichSearchSchema.safeParse({ from: '2026-03-15', utc_offset_minutes: 600 }).success).toBe(true);
expect(immichSearchSchema.safeParse({ utc_offset_minutes: '-480' }).success).toBe(true);
expect(immichSearchSchema.safeParse({}).success).toBe(true);
});
});
describe('synology contracts', () => {
@@ -58,6 +66,20 @@ describe('synology contracts', () => {
it('accepts every paging field of the search body, in either type', () => {
expect(synologySearchSchema.safeParse({ offset: '10', page: 2, limit: '100', size: 0 }).success).toBe(true);
});
it('keeps the row offset and the UTC offset as two separate fields', () => {
// `offset` is rows to skip on the NAS; `utc_offset_minutes` is which 24
// hours from/to name. A UTC+10 reader sending the zone as `offset` would
// have asked the NAS to skip 600 photos (#2336).
const parsed = synologySearchSchema.safeParse({ offset: 40, utc_offset_minutes: 600 });
expect(parsed.success).toBe(true);
expect(parsed.success && parsed.data.offset).toBe(40);
expect(parsed.success && parsed.data.utc_offset_minutes).toBe(600);
});
it('leaves the search body valid without a zone, which is the UTC day as before', () => {
expect(synologySearchSchema.safeParse({ from: '2026-03-15', to: '2026-03-15' }).success).toBe(true);
});
});
describe('unified contracts', () => {
@@ -87,6 +109,8 @@ describe('unified contracts', () => {
it('leaves the album-link fields untyped — the service validates them, and it answers 400 with its own wording', () => {
expect(createAlbumLinkSchema.safeParse({}).success).toBe(true);
expect(createAlbumLinkSchema.safeParse({ provider: 'synology', album_id: 12, album_name: null }).success).toBe(true);
expect(createAlbumLinkSchema.safeParse({ provider: 'synology', album_id: 12, album_name: null }).success).toBe(
true,
);
});
});
+18
View File
@@ -26,6 +26,18 @@ const looseBoolean = z.union([z.boolean(), z.literal('true'), z.literal('false')
/** `Number(x) || fallback` — the client sends these as strings from query-ish forms. */
const looseNumber = z.union([z.number(), z.string()]).optional();
/**
* The UTC offset the caller means its calendar days in, in minutes east of UTC
* (600 for UTC+10, -480 for UTC-8). A date-only `from`/`to` names a day on
* somebody's wall clock; without this the server can only read it as a UTC day,
* which is the wrong 24 hours for everyone outside UTC.
*
* Deliberately not called `offset`: that name is taken on the Synology body and
* means the NAS pagination offset. One body shape goes to whichever provider, so
* reusing the name would make a UTC+10 user ask the NAS to skip 600 photos.
*/
const utcOffsetMinutes = looseNumber;
// ── Immich ────────────────────────────────────────────────────────────────
export const immichSettingsSchema = z.looseObject({
@@ -46,6 +58,10 @@ export const immichSearchSchema = z.looseObject({
to: optionalText,
size: looseNumber,
page: looseNumber,
// Accepted so the client can send one body to either provider. The Immich
// route ignores it: Immich returns each photo's own local capture stamp, so
// the day is answered from the photo rather than from the reader's zone.
utc_offset_minutes: utcOffsetMinutes,
});
// ── Synology ──────────────────────────────────────────────────────────────
@@ -64,10 +80,12 @@ export const synologyTestSchema = synologySettingsSchema.extend({
export const synologySearchSchema = z.looseObject({
from: optionalText,
to: optionalText,
// Rows to skip on the NAS — pagination, nothing to do with time zones.
offset: looseNumber,
page: looseNumber,
limit: looseNumber,
size: looseNumber,
utc_offset_minutes: utcOffsetMinutes,
});
// ── Unified (provider-agnostic trip photo surface) ────────────────────────