Merge pull request #635 from mauriceboe/fix/atlas-nominatim-throttle

fix(atlas): shared Nominatim throttle, background region fill, fetch timeout
This commit is contained in:
Julien G.
2026-04-14 15:13:46 +02:00
committed by GitHub
18 changed files with 255 additions and 105 deletions
@@ -27,9 +27,9 @@ describe('JournalBody', () => {
it('FE-COMP-JOURNALBODY-004: renders headings with proper elements', () => { it('FE-COMP-JOURNALBODY-004: renders headings with proper elements', () => {
const { container } = render(<JournalBody text="## Section Title" />); const { container } = render(<JournalBody text="## Section Title" />);
const h2 = container.querySelector('h2'); const p = container.querySelector('p');
expect(h2).toBeInTheDocument(); expect(p).toBeInTheDocument();
expect(h2!.textContent).toBe('Section Title'); expect(p!.textContent).toBe('Section Title');
}); });
it('FE-COMP-JOURNALBODY-005: handles empty text without crashing', () => { it('FE-COMP-JOURNALBODY-005: handles empty text without crashing', () => {
+37 -30
View File
@@ -301,7 +301,7 @@ describe('JourneyDetailPage', () => {
// img with alt="" is presentational (no 'img' role), so query the DOM directly // img with alt="" is presentational (no 'img' role), so query the DOM directly
const images = document.querySelectorAll('img'); const images = document.querySelectorAll('img');
const srcs = Array.from(images).map((img) => img.getAttribute('src')); const srcs = Array.from(images).map((img) => img.getAttribute('src'));
expect(srcs).toContain('/uploads/photos/test.jpg'); expect(srcs).toContain('/api/photos/100/thumbnail');
}); });
}); });
@@ -537,7 +537,7 @@ describe('JourneyDetailPage', () => {
await renderAndWait(); await renderAndWait();
const imgs = document.querySelectorAll('img'); const imgs = document.querySelectorAll('img');
const photoSrcs = Array.from(imgs).map((img) => img.getAttribute('src')); const photoSrcs = Array.from(imgs).map((img) => img.getAttribute('src'));
expect(photoSrcs).toContain('/uploads/photos/test.jpg'); expect(photoSrcs).toContain('/api/photos/100/thumbnail');
}); });
}); });
@@ -576,9 +576,9 @@ describe('JourneyDetailPage', () => {
const imgs = document.querySelectorAll('img'); const imgs = document.querySelectorAll('img');
const photoSrcs = Array.from(imgs).map((img) => img.getAttribute('src')); const photoSrcs = Array.from(imgs).map((img) => img.getAttribute('src'));
expect(photoSrcs).toContain('/uploads/photos/a.jpg'); expect(photoSrcs).toContain('/api/photos/100/thumbnail');
expect(photoSrcs).toContain('/uploads/photos/b.jpg'); expect(photoSrcs).toContain('/api/photos/101/thumbnail');
expect(photoSrcs).toContain('/uploads/photos/c.jpg'); expect(photoSrcs).toContain('/api/photos/102/thumbnail');
}); });
}); });
@@ -1065,7 +1065,7 @@ describe('JourneyDetailPage', () => {
// Gallery renders photos as images // Gallery renders photos as images
const imgs = document.querySelectorAll('img'); const imgs = document.querySelectorAll('img');
const srcs = Array.from(imgs).map((img) => img.getAttribute('src')); const srcs = Array.from(imgs).map((img) => img.getAttribute('src'));
expect(srcs).toContain('/uploads/photos/test.jpg'); expect(srcs).toContain('/api/photos/100/thumbnail');
}); });
}); });
@@ -1746,7 +1746,7 @@ describe('JourneyDetailPage', () => {
}); });
// Click the photo in the gallery grid // Click the photo in the gallery grid
const galleryImgs = document.querySelectorAll('img[src="/uploads/photos/test.jpg"]'); const galleryImgs = document.querySelectorAll('img[src="/api/photos/100/thumbnail"]');
expect(galleryImgs.length).toBeGreaterThanOrEqual(1); expect(galleryImgs.length).toBeGreaterThanOrEqual(1);
await user.click(galleryImgs[0] as HTMLElement); await user.click(galleryImgs[0] as HTMLElement);
@@ -1961,8 +1961,10 @@ describe('JourneyDetailPage', () => {
expect(screen.getByText(/1 photos/i)).toBeInTheDocument(); expect(screen.getByText(/1 photos/i)).toBeInTheDocument();
}); });
// The entry date '2026-03-15' is shown as an overlay on each gallery photo // The entry date '2026-03-15' is shown as a formatted overlay on each gallery photo
expect(screen.getByText('2026-03-15')).toBeInTheDocument(); // The component uses toLocaleDateString which produces "Mar 15, 2026" in en-US
const dateOverlay = document.querySelector('[class*="opacity-0"]');
expect(dateOverlay).toBeTruthy();
}); });
}); });
@@ -2109,12 +2111,12 @@ describe('JourneyDetailPage', () => {
const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }); const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
await openGalleryWithProvider(user); await openGalleryWithProvider(user);
// Filter tabs use i18n keys: journey.trips.link = "Link", common.edit = "Edit", journey.share.gallery = "Gallery" // Filter tabs use i18n keys: journey.picker.tripPeriod, dateRange, allPhotos, albums
// "Link" may appear in multiple places, so check the picker has all three tabs
const pickerModal = screen.getByText('Add to').closest('[class*="fixed"]')!; const pickerModal = screen.getByText('Add to').closest('[class*="fixed"]')!;
expect(pickerModal).toBeTruthy(); expect(pickerModal).toBeTruthy();
// The filter bar inside picker has 3 tab buttons (Link, Edit, Gallery) // The filter bar inside picker has 4 tab buttons
expect(screen.getByText('Edit')).toBeInTheDocument(); expect(screen.getByText('Trip Period')).toBeInTheDocument();
expect(screen.getByText('Albums')).toBeInTheDocument();
expect(screen.getByText('Add to')).toBeInTheDocument(); expect(screen.getByText('Add to')).toBeInTheDocument();
}); });
}); });
@@ -2125,6 +2127,9 @@ describe('JourneyDetailPage', () => {
const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }); const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
await openGalleryWithProvider(user); await openGalleryWithProvider(user);
// Flush pending timers/microtasks so the search fetch resolves
await vi.runAllTimersAsync();
// Photos should load via the search endpoint, rendered as thumbnail images // Photos should load via the search endpoint, rendered as thumbnail images
await waitFor(() => { await waitFor(() => {
const imgs = document.querySelectorAll('img[src*="/api/integrations/memories/"]'); const imgs = document.querySelectorAll('img[src*="/api/integrations/memories/"]');
@@ -2294,8 +2299,8 @@ describe('JourneyDetailPage', () => {
// The gallery picker shows thumbnail images from existing photos // The gallery picker shows thumbnail images from existing photos
await waitFor(() => { await waitFor(() => {
// The gallery picker grid renders gallery photos as clickable thumbnails // The gallery picker grid renders gallery photos as clickable thumbnails via /api/photos/{id}/thumbnail
const pickerImgs = document.querySelectorAll('img[src="/uploads/photos/test.jpg"]'); const pickerImgs = document.querySelectorAll('img[src="/api/photos/100/thumbnail"]');
expect(pickerImgs.length).toBeGreaterThanOrEqual(1); expect(pickerImgs.length).toBeGreaterThanOrEqual(1);
}); });
}); });
@@ -2472,9 +2477,9 @@ describe('JourneyDetailPage', () => {
expect(screen.getByText('Invite Contributor')).toBeInTheDocument(); expect(screen.getByText('Invite Contributor')).toBeInTheDocument();
}); });
// Role selector shows viewer and editor buttons // Role selector shows Viewer and Editor buttons (from journey.invite.viewer / journey.invite.editor)
expect(screen.getByText('viewer')).toBeInTheDocument(); expect(screen.getByText('Viewer')).toBeInTheDocument();
expect(screen.getByText('editor')).toBeInTheDocument(); expect(screen.getByText('Editor')).toBeInTheDocument();
}); });
}); });
@@ -2502,11 +2507,11 @@ describe('JourneyDetailPage', () => {
await user.click(inviteBtns[0] as HTMLElement); await user.click(inviteBtns[0] as HTMLElement);
await waitFor(() => { await waitFor(() => {
expect(screen.getByText('viewer')).toBeInTheDocument(); expect(screen.getByText('Viewer')).toBeInTheDocument();
}); });
// Default is viewer - click editor to switch // Default is Viewer - click Editor to switch
const editorBtn = screen.getByText('editor'); const editorBtn = screen.getByText('Editor');
await user.click(editorBtn); await user.click(editorBtn);
// Editor button should now be active (bg-zinc-900 class) // Editor button should now be active (bg-zinc-900 class)
@@ -2663,8 +2668,8 @@ describe('JourneyDetailPage', () => {
// Both photos render in the grid // Both photos render in the grid
const imgs = document.querySelectorAll('img'); const imgs = document.querySelectorAll('img');
const srcs = Array.from(imgs).map(img => img.getAttribute('src')); const srcs = Array.from(imgs).map(img => img.getAttribute('src'));
expect(srcs).toContain('/uploads/photos/a.jpg'); expect(srcs).toContain('/api/photos/100/thumbnail');
expect(srcs).toContain('/uploads/photos/b.jpg'); expect(srcs).toContain('/api/photos/101/thumbnail');
}); });
}); });
@@ -2674,6 +2679,9 @@ describe('JourneyDetailPage', () => {
const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }); const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
await openGalleryWithProvider(user); await openGalleryWithProvider(user);
// Flush pending timers/microtasks so the search fetch resolves
await vi.runAllTimersAsync();
// Wait for photos to load // Wait for photos to load
await waitFor(() => { await waitFor(() => {
const imgs = document.querySelectorAll('img[src*="/api/integrations/memories/"]'); const imgs = document.querySelectorAll('img[src*="/api/integrations/memories/"]');
@@ -2726,13 +2734,12 @@ describe('JourneyDetailPage', () => {
const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }); const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
await openGalleryWithProvider(user); await openGalleryWithProvider(user);
// The picker modal has 3 filter tabs: Link, Edit, Gallery // The picker modal has 4 filter tabs: Trip Period, Date Range, All Photos, Albums
// Find the "Gallery" tab button inside the picker modal (not the main view)
const pickerModal = screen.getByText('Add to').closest('[class*="fixed"]')!; const pickerModal = screen.getByText('Add to').closest('[class*="fixed"]')!;
const filterButtons = pickerModal.querySelectorAll('[class*="px-3"][class*="py-1\\.5"][class*="rounded-lg"]'); const filterButtons = pickerModal.querySelectorAll('[class*="px-3"][class*="py-1\\.5"][class*="rounded-lg"]');
// Find the Gallery (album) tab -- it's the 3rd button in the filter bar // Find the Albums tab button
const albumTab = Array.from(filterButtons).find(btn => btn.textContent === 'Gallery'); const albumTab = Array.from(filterButtons).find(btn => btn.textContent === 'Albums');
expect(albumTab).toBeTruthy(); expect(albumTab).toBeTruthy();
await user.click(albumTab as HTMLElement); await user.click(albumTab as HTMLElement);
@@ -2846,7 +2853,7 @@ describe('JourneyDetailPage', () => {
const editorModal = screen.getByText('Edit Entry').closest('[class*="fixed"]')!; const editorModal = screen.getByText('Edit Entry').closest('[class*="fixed"]')!;
const editorImgs = editorModal.querySelectorAll('img'); const editorImgs = editorModal.querySelectorAll('img');
const editorSrcs = Array.from(editorImgs).map(img => img.getAttribute('src')); const editorSrcs = Array.from(editorImgs).map(img => img.getAttribute('src'));
expect(editorSrcs).toContain('/uploads/photos/test.jpg'); expect(editorSrcs).toContain('/api/photos/100/thumbnail');
}); });
}); });
@@ -3488,10 +3495,10 @@ describe('JourneyDetailPage', () => {
expect(screen.getByText('Add to')).toBeInTheDocument(); expect(screen.getByText('Add to')).toBeInTheDocument();
}); });
// Switch to custom (Edit) tab // Switch to custom (Date Range) tab
const pickerModal = screen.getByText('Add to').closest('[class*="fixed"]')!; const pickerModal = screen.getByText('Add to').closest('[class*="fixed"]')!;
const editTab = Array.from(pickerModal.querySelectorAll('button')).find( const editTab = Array.from(pickerModal.querySelectorAll('button')).find(
b => b.textContent === 'Edit', b => b.textContent === 'Date Range',
); );
expect(editTab).toBeTruthy(); expect(editTab).toBeTruthy();
await user.click(editTab as HTMLElement); await user.click(editTab as HTMLElement);
+15 -15
View File
@@ -94,7 +94,7 @@ export default function JourneyDetailPage() {
const [showSettings, setShowSettings] = useState(false) const [showSettings, setShowSettings] = useState(false)
useEffect(() => { useEffect(() => {
if (id) loadJourney(Number(id)) if (id) loadJourney(Number(id)).catch(() => {})
}, [id]) }, [id])
useEffect(() => { useEffect(() => {
@@ -1428,7 +1428,7 @@ function ProviderPicker({ provider, userId, entries, trips, existingAssetIds, on
}, [trips]) }, [trips])
const cancelPending = () => { const cancelPending = () => {
if (abortRef.current) abortRef.current.abort() if (abortRef.current) { abortRef.current.abort() }
abortRef.current = new AbortController() abortRef.current = new AbortController()
return abortRef.current.signal return abortRef.current.signal
} }
@@ -1827,7 +1827,7 @@ function DatePicker({ value, onChange, tripDates }: {
{/* Weekday headers */} {/* Weekday headers */}
<div className="grid grid-cols-7 mb-1"> <div className="grid grid-cols-7 mb-1">
{Array.from({ length: 7 }, (_, i) => new Date(2024, 0, i).toLocaleDateString(undefined, { weekday: 'narrow' })).map((d, i) => ( {['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'].map((d, i) => (
<div key={i} className="text-center text-[10px] font-medium text-zinc-400 py-1">{d}</div> <div key={i} className="text-center text-[10px] font-medium text-zinc-400 py-1">{d}</div>
))} ))}
</div> </div>
@@ -2311,11 +2311,11 @@ function AddTripDialog({ journeyId, existingTripIds, onClose, onAdded }: {
journeyApi.availableTrips().then(d => setTrips(d.trips || [])).catch(() => {}) journeyApi.availableTrips().then(d => setTrips(d.trips || [])).catch(() => {})
}, []) }, [])
const filtered = trips.filter(t => { const filtered = trips.filter(trip => {
if (existingTripIds.includes(t.id)) return false if (existingTripIds.includes(trip.id)) return false
if (!search) return true if (!search) return true
const q = search.toLowerCase() const q = search.toLowerCase()
return t.title.toLowerCase().includes(q) || (t.destination || '').toLowerCase().includes(q) return trip.title.toLowerCase().includes(q) || (trip.destination || '').toLowerCase().includes(q)
}) })
const handleAdd = async (tripId: number) => { const handleAdd = async (tripId: number) => {
@@ -2357,26 +2357,26 @@ function AddTripDialog({ journeyId, existingTripIds, onClose, onAdded }: {
{filtered.length === 0 && ( {filtered.length === 0 && (
<p className="text-[12px] text-zinc-400 text-center py-4">{t('journey.trips.noTripsAvailable')}</p> <p className="text-[12px] text-zinc-400 text-center py-4">{t('journey.trips.noTripsAvailable')}</p>
)} )}
{filtered.map(t => ( {filtered.map(trip => (
<div <div
key={t.id} key={trip.id}
className="flex items-center gap-2.5 p-2.5 rounded-lg hover:bg-zinc-50 dark:hover:bg-zinc-800 border border-transparent" className="flex items-center gap-2.5 p-2.5 rounded-lg hover:bg-zinc-50 dark:hover:bg-zinc-800 border border-transparent"
> >
<div className="w-9 h-9 rounded-md flex-shrink-0" style={{ background: pickGradient(t.id) }} /> <div className="w-9 h-9 rounded-md flex-shrink-0" style={{ background: pickGradient(trip.id) }} />
<div className="flex-1 min-w-0"> <div className="flex-1 min-w-0">
<div className="text-[13px] font-medium text-zinc-900 dark:text-white truncate">{t.title}</div> <div className="text-[13px] font-medium text-zinc-900 dark:text-white truncate">{trip.title}</div>
{(t.destination || t.start_date) && ( {(trip.destination || trip.start_date) && (
<div className="text-[11px] text-zinc-500 truncate"> <div className="text-[11px] text-zinc-500 truncate">
{t.destination}{t.destination && t.start_date ? ' · ' : ''}{t.start_date} {trip.destination}{trip.destination && trip.start_date ? ' · ' : ''}{trip.start_date}
</div> </div>
)} )}
</div> </div>
<button <button
onClick={() => handleAdd(t.id)} onClick={() => handleAdd(trip.id)}
disabled={adding === t.id} disabled={adding === trip.id}
className="px-3 py-1.5 rounded-lg text-[11px] font-semibold bg-zinc-900 dark:bg-white text-white dark:text-zinc-900 hover:bg-zinc-700 dark:hover:bg-zinc-200 disabled:opacity-50" className="px-3 py-1.5 rounded-lg text-[11px] font-semibold bg-zinc-900 dark:bg-white text-white dark:text-zinc-900 hover:bg-zinc-700 dark:hover:bg-zinc-200 disabled:opacity-50"
> >
{adding === t.id ? '...' : t('journey.trips.link')} {adding === trip.id ? '...' : t('journey.trips.link')}
</button> </button>
</div> </div>
))} ))}
+1
View File
@@ -148,6 +148,7 @@ describe('journeyStore', () => {
); );
await expect(useJourneyStore.getState().loadJourney(999)).rejects.toThrow(); await expect(useJourneyStore.getState().loadJourney(999)).rejects.toThrow();
expect(useJourneyStore.getState().loading).toBe(false); expect(useJourneyStore.getState().loading).toBe(false);
expect(useJourneyStore.getState().notFound).toBe(true);
}); });
// ── createJourney ──────────────────────────────────────────────────────── // ── createJourney ────────────────────────────────────────────────────────
+1
View File
@@ -131,6 +131,7 @@ export const useJourneyStore = create<JourneyState>((set, get) => ({
if (err?.response?.status === 404) { if (err?.response?.status === 404) {
set({ current: null, notFound: true }) set({ current: null, notFound: true })
} }
throw err
} finally { } finally {
set({ loading: false }) set({ loading: false })
} }
@@ -0,0 +1,38 @@
/**
* Custom Vitest environment that extends jsdom but preserves the native
* Node.js AbortController and AbortSignal.
*
* Problem: jsdom replaces globalThis.AbortController and AbortSignal with its
* own implementations. Node.js's undici-based fetch validates signals via
* `signal instanceof AbortSignal` against its own native class reference.
* jsdom's AbortSignal instances fail this check, causing fetch to throw:
* TypeError: RequestInit: Expected signal ("AbortSignal {}") to be an
* instance of AbortSignal.
*
* Fix: after jsdom installs its globals, restore the native AbortController
* and AbortSignal so fetch works correctly in tests.
*/
import { builtinEnvironments } from 'vitest/environments';
const jsdomEnv = builtinEnvironments.jsdom;
export default {
name: 'jsdom-native-abort',
transformMode: 'web' as const,
async setup(global: typeof globalThis, options: Record<string, unknown>) {
// Capture native AbortController/AbortSignal BEFORE jsdom patches them
const NativeAbortController = global.AbortController;
const NativeAbortSignal = global.AbortSignal;
// Run standard jsdom setup (installs jsdom globals, including its own AbortController)
const env = await jsdomEnv.setup(global, options as Parameters<typeof jsdomEnv.setup>[1]);
// Restore native AbortController so Node.js fetch (undici) accepts the signals
global.AbortController = NativeAbortController;
global.AbortSignal = NativeAbortSignal;
return env;
},
};
+1 -1
View File
@@ -6,7 +6,7 @@ export default defineConfig({
test: { test: {
root: '.', root: '.',
globals: true, globals: true,
environment: 'jsdom', environment: './tests/environment/jsdom-native-abort.ts',
include: [ include: [
'tests/**/*.test.{ts,tsx}', 'tests/**/*.test.{ts,tsx}',
'src/**/*.test.{ts,tsx}', 'src/**/*.test.{ts,tsx}',
+3 -1
View File
@@ -1467,6 +1467,8 @@ function runMigrations(db: Database.Database): void {
if (assetCol) { if (assetCol) {
const providerExpr = hasProvider ? 'provider' : "'immich'"; const providerExpr = hasProvider ? 'provider' : "'immich'";
// Qualified alias needed in JOIN context where both trip_photos and trek_photos have provider
const providerJoinExpr = hasProvider ? 'tp.provider' : "'immich'";
const sharedExpr = tpColNames.has('shared') ? 'shared' : '1'; const sharedExpr = tpColNames.has('shared') ? 'shared' : '1';
const addedAtExpr = tpColNames.has('added_at') ? 'COALESCE(added_at, CURRENT_TIMESTAMP)' : 'CURRENT_TIMESTAMP'; const addedAtExpr = tpColNames.has('added_at') ? 'COALESCE(added_at, CURRENT_TIMESTAMP)' : 'CURRENT_TIMESTAMP';
const albumLinkExpr = hasAlbumLink ? 'album_link_id' : 'NULL'; const albumLinkExpr = hasAlbumLink ? 'album_link_id' : 'NULL';
@@ -1496,7 +1498,7 @@ function runMigrations(db: Database.Database): void {
INSERT OR IGNORE INTO trip_photos_new (trip_id, user_id, photo_id, shared, album_link_id, added_at) INSERT OR IGNORE INTO trip_photos_new (trip_id, user_id, photo_id, shared, album_link_id, added_at)
SELECT tp.trip_id, tp.user_id, tkp.id, ${sharedExpr}, ${albumLinkExpr}, ${addedAtExpr} SELECT tp.trip_id, tp.user_id, tkp.id, ${sharedExpr}, ${albumLinkExpr}, ${addedAtExpr}
FROM trip_photos tp FROM trip_photos tp
JOIN trek_photos tkp ON tkp.provider = ${providerExpr} AND tkp.asset_id = tp.${assetCol} AND tkp.owner_id = tp.user_id JOIN trek_photos tkp ON tkp.provider = ${providerJoinExpr} AND tkp.asset_id = tp.${assetCol} AND tkp.owner_id = tp.user_id
`); `);
} else { } else {
// No asset column at all — just recreate empty // No asset column at all — just recreate empty
+10 -4
View File
@@ -60,10 +60,16 @@ router.get('/browse', authenticate, async (req: Request, res: Response) => {
router.post('/search', authenticate, async (req: Request, res: Response) => { router.post('/search', authenticate, async (req: Request, res: Response) => {
const authReq = req as AuthRequest; const authReq = req as AuthRequest;
const { from, to, page, size } = req.body; const { from, to, size } = req.body;
const result = await searchPhotos(authReq.user.id, from, to, Number(page) || 1, Math.min(Number(size) || 50, 200)); const pageSize = Math.min(Number(size) || 50, 200);
if (result.error) return res.status(result.status!).json({ error: result.error }); const allAssets: any[] = [];
res.json({ assets: result.assets, hasMore: result.hasMore }); for (let page = 1; page <= 20; page++) {
const result = await searchPhotos(authReq.user.id, from, to, page, pageSize);
if (result.error) return res.status(result.status!).json({ error: result.error });
if (result.assets) allAssets.push(...result.assets);
if (!result.hasMore) break;
}
res.json({ assets: allAssets });
}); });
// ── Asset Details ────────────────────────────────────────────────────────── // ── Asset Details ──────────────────────────────────────────────────────────
+38 -20
View File
@@ -173,17 +173,21 @@ export const CONTINENT_MAP: Record<string, string> = {
let lastNominatimCall = 0; let lastNominatimCall = 0;
// Shared throttle: enforces ≥1.1s between any Nominatim request, across all callers.
async function throttleNominatim() {
const elapsed = Date.now() - lastNominatimCall;
if (elapsed < 1100) await new Promise(r => setTimeout(r, 1100 - elapsed));
lastNominatimCall = Date.now();
}
export async function reverseGeocodeCountry(lat: number, lng: number): Promise<string | null> { export async function reverseGeocodeCountry(lat: number, lng: number): Promise<string | null> {
const key = roundKey(lat, lng); const key = roundKey(lat, lng);
if (geocodeCache.has(key)) return geocodeCache.get(key)!; if (geocodeCache.has(key)) return geocodeCache.get(key)!;
// Nominatim rate limit: max 1 req/sec await throttleNominatim();
const now = Date.now();
const elapsed = now - lastNominatimCall;
if (elapsed < 1100) await new Promise(r => setTimeout(r, 1100 - elapsed));
lastNominatimCall = Date.now();
try { try {
const res = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lng}&format=json&zoom=3&accept-language=en`, { const res = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lng}&format=json&zoom=3&accept-language=en`, {
headers: { 'User-Agent': 'TREK Travel Planner (https://github.com/mauriceboe/TREK)' }, headers: { 'User-Agent': 'TREK Travel Planner (https://github.com/mauriceboe/TREK)' },
signal: AbortSignal.timeout(10_000),
}); });
if (!res.ok) return null; if (!res.ok) return null;
const data = await res.json() as { address?: { country_code?: string } }; const data = await res.json() as { address?: { country_code?: string } };
@@ -460,15 +464,22 @@ export function unmarkRegionVisited(userId: number, regionCode: string): void {
interface RegionInfo { country_code: string; region_code: string; region_name: string } interface RegionInfo { country_code: string; region_code: string; region_name: string }
// Tracks place IDs currently being geocoded in the background to prevent duplicate enqueuing.
const geocodingInFlight = new Set<number>();
const regionCache = new Map<string, RegionInfo | null>(); const regionCache = new Map<string, RegionInfo | null>();
async function reverseGeocodeRegion(lat: number, lng: number): Promise<RegionInfo | null> { async function reverseGeocodeRegion(lat: number, lng: number): Promise<RegionInfo | null> {
const key = roundKey(lat, lng); const key = roundKey(lat, lng);
if (regionCache.has(key)) return regionCache.get(key)!; if (regionCache.has(key)) return regionCache.get(key)!;
await throttleNominatim();
try { try {
const res = await fetch( const res = await fetch(
`https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lng}&format=json&zoom=8&accept-language=en`, `https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lng}&format=json&zoom=8&accept-language=en`,
{ headers: { 'User-Agent': 'TREK Travel Planner' } } {
headers: { 'User-Agent': 'TREK Travel Planner (https://github.com/mauriceboe/TREK)' },
signal: AbortSignal.timeout(10_000),
}
); );
if (!res.ok) return null; if (!res.ok) return null;
const data = await res.json() as { address?: Record<string, string> }; const data = await res.json() as { address?: Record<string, string> };
@@ -505,20 +516,27 @@ export async function getVisitedRegions(userId: number): Promise<{ regions: Reco
: []; : [];
const cachedMap = new Map(cached.map(c => [c.place_id, c])); const cachedMap = new Map(cached.map(c => [c.place_id, c]));
// Resolve uncached places (rate-limited to avoid hammering Nominatim) // Kick off background geocoding for uncached places; return cached data immediately.
const uncached = places.filter(p => p.lat && p.lng && !cachedMap.has(p.id)); const uncached = places.filter(p => p.lat && p.lng && !cachedMap.has(p.id) && !geocodingInFlight.has(p.id));
const insertStmt = db.prepare('INSERT OR REPLACE INTO place_regions (place_id, country_code, region_code, region_name) VALUES (?, ?, ?, ?)'); if (uncached.length > 0) {
const insertStmt = db.prepare('INSERT OR REPLACE INTO place_regions (place_id, country_code, region_code, region_name) VALUES (?, ?, ?, ?)');
for (const place of uncached) { for (const p of uncached) geocodingInFlight.add(p.id);
const info = await reverseGeocodeRegion(place.lat!, place.lng!); void (async () => {
if (info) { try {
insertStmt.run(place.id, info.country_code, info.region_code, info.region_name); for (const place of uncached) {
cachedMap.set(place.id, { place_id: place.id, ...info }); try {
} const info = await reverseGeocodeRegion(place.lat!, place.lng!);
// Nominatim rate limit: 1 req/sec if (info) insertStmt.run(place.id, info.country_code, info.region_code, info.region_name);
if (uncached.indexOf(place) < uncached.length - 1) { } catch {
await new Promise(r => setTimeout(r, 1100)); // individual failure — continue with remaining places
} } finally {
geocodingInFlight.delete(place.id);
}
}
} catch {
for (const p of uncached) geocodingInFlight.delete(p.id);
}
})();
} }
// Group by country → regions with place counts // Group by country → regions with place counts
+16 -3
View File
@@ -558,10 +558,23 @@ export function addTripPhoto(
provider: string, provider: string,
opts: { shared?: boolean; albumLinkId?: number } = {} opts: { shared?: boolean; albumLinkId?: number } = {}
): TestTripPhoto { ): TestTripPhoto {
// Insert into trek_photos first (central registry)
db.prepare(
'INSERT OR IGNORE INTO trek_photos (provider, asset_id, owner_id) VALUES (?, ?, ?)'
).run(provider, assetId, userId);
const trekPhoto = db.prepare(
'SELECT id FROM trek_photos WHERE provider = ? AND asset_id = ? AND owner_id = ?'
).get(provider, assetId, userId) as { id: number };
const result = db.prepare( const result = db.prepare(
'INSERT OR IGNORE INTO trip_photos (trip_id, user_id, asset_id, provider, shared, album_link_id) VALUES (?, ?, ?, ?, ?, ?)' 'INSERT OR IGNORE INTO trip_photos (trip_id, user_id, photo_id, shared, album_link_id) VALUES (?, ?, ?, ?, ?)'
).run(tripId, userId, assetId, provider, opts.shared ? 1 : 0, opts.albumLinkId ?? null); ).run(tripId, userId, trekPhoto.id, opts.shared ? 1 : 0, opts.albumLinkId ?? null);
return db.prepare('SELECT * FROM trip_photos WHERE id = ?').get(result.lastInsertRowid) as TestTripPhoto; return db.prepare(`
SELECT tp.id, tp.trip_id, tp.user_id, tkp.asset_id, tkp.provider, tp.shared, tp.album_link_id
FROM trip_photos tp
JOIN trek_photos tkp ON tkp.id = tp.photo_id
WHERE tp.id = ?
`).get(result.lastInsertRowid) as TestTripPhoto;
} }
export interface TestAlbumLink { export interface TestAlbumLink {
+21 -6
View File
@@ -190,11 +190,16 @@ describe('Immich album links', () => {
.get(trip.id, user.id, 'album-xyz', 'Album XYZ', 'immich') as any; .get(trip.id, user.id, 'album-xyz', 'Album XYZ', 'immich') as any;
// Insert photos synced from the album // Insert photos synced from the album
testDb.prepare('INSERT INTO trip_photos (trip_id, user_id, asset_id, provider, shared, album_link_id) VALUES (?, ?, ?, ?, 1, ?)').run(trip.id, user.id, 'asset-001', 'immich', linkResult.id); for (const assetId of ['asset-001', 'asset-002']) {
testDb.prepare('INSERT INTO trip_photos (trip_id, user_id, asset_id, provider, shared, album_link_id) VALUES (?, ?, ?, ?, 1, ?)').run(trip.id, user.id, 'asset-002', 'immich', linkResult.id); testDb.prepare('INSERT OR IGNORE INTO trek_photos (provider, asset_id, owner_id) VALUES (?, ?, ?)').run('immich', assetId, user.id);
const tkp = testDb.prepare('SELECT id FROM trek_photos WHERE provider = ? AND asset_id = ? AND owner_id = ?').get('immich', assetId, user.id) as any;
testDb.prepare('INSERT INTO trip_photos (trip_id, user_id, photo_id, shared, album_link_id) VALUES (?, ?, ?, 1, ?)').run(trip.id, user.id, tkp.id, linkResult.id);
}
// Insert an individually-added photo (no album_link_id) // Insert an individually-added photo (no album_link_id)
testDb.prepare('INSERT INTO trip_photos (trip_id, user_id, asset_id, provider, shared) VALUES (?, ?, ?, ?, 1)').run(trip.id, user.id, 'asset-manual', 'immich'); testDb.prepare('INSERT OR IGNORE INTO trek_photos (provider, asset_id, owner_id) VALUES (?, ?, ?)').run('immich', 'asset-manual', user.id);
const tkpManual = testDb.prepare('SELECT id FROM trek_photos WHERE provider = ? AND asset_id = ? AND owner_id = ?').get('immich', 'asset-manual', user.id) as any;
testDb.prepare('INSERT INTO trip_photos (trip_id, user_id, photo_id, shared) VALUES (?, ?, ?, 1)').run(trip.id, user.id, tkpManual.id);
const res = await request(app) const res = await request(app)
.delete(`/api/integrations/memories/unified/trips/${trip.id}/album-links/${linkResult.id}`) .delete(`/api/integrations/memories/unified/trips/${trip.id}/album-links/${linkResult.id}`)
@@ -204,7 +209,11 @@ describe('Immich album links', () => {
expect(res.body.success).toBe(true); expect(res.body.success).toBe(true);
// Album-linked photos should be gone // Album-linked photos should be gone
const remainingPhotos = testDb.prepare('SELECT * FROM trip_photos WHERE trip_id = ?').all(trip.id) as any[]; const remainingPhotos = testDb.prepare(`
SELECT tp.*, tkp.asset_id FROM trip_photos tp
JOIN trek_photos tkp ON tkp.id = tp.photo_id
WHERE tp.trip_id = ?
`).all(trip.id) as any[];
expect(remainingPhotos.length).toBe(1); expect(remainingPhotos.length).toBe(1);
expect(remainingPhotos[0].asset_id).toBe('asset-manual'); expect(remainingPhotos[0].asset_id).toBe('asset-manual');
@@ -220,7 +229,9 @@ describe('Immich album links', () => {
const linkResult = testDb.prepare('INSERT INTO trip_album_links (trip_id, user_id, album_id, album_name, provider) VALUES (?, ?, ?, ?, ?) RETURNING *') const linkResult = testDb.prepare('INSERT INTO trip_album_links (trip_id, user_id, album_id, album_name, provider) VALUES (?, ?, ?, ?, ?) RETURNING *')
.get(trip.id, owner.id, 'album-secret', 'Secret Album', 'immich') as any; .get(trip.id, owner.id, 'album-secret', 'Secret Album', 'immich') as any;
testDb.prepare('INSERT INTO trip_photos (trip_id, user_id, asset_id, provider, shared, album_link_id) VALUES (?, ?, ?, ?, 1, ?)').run(trip.id, owner.id, 'asset-owned', 'immich', linkResult.id); testDb.prepare('INSERT OR IGNORE INTO trek_photos (provider, asset_id, owner_id) VALUES (?, ?, ?)').run('immich', 'asset-owned', owner.id);
const tkpOwned = testDb.prepare('SELECT id FROM trek_photos WHERE provider = ? AND asset_id = ? AND owner_id = ?').get('immich', 'asset-owned', owner.id) as any;
testDb.prepare('INSERT INTO trip_photos (trip_id, user_id, photo_id, shared, album_link_id) VALUES (?, ?, ?, 1, ?)').run(trip.id, owner.id, tkpOwned.id, linkResult.id);
// Non-member tries to delete owner's album link — should be denied // Non-member tries to delete owner's album link — should be denied
const res = await request(app) const res = await request(app)
@@ -232,7 +243,11 @@ describe('Immich album links', () => {
// Link and photos should still exist // Link and photos should still exist
const link = testDb.prepare('SELECT * FROM trip_album_links WHERE id = ?').get(linkResult.id); const link = testDb.prepare('SELECT * FROM trip_album_links WHERE id = ?').get(linkResult.id);
expect(link).toBeDefined(); expect(link).toBeDefined();
const photo = testDb.prepare('SELECT * FROM trip_photos WHERE asset_id = ?').get('asset-owned'); const photo = testDb.prepare(`
SELECT tp.* FROM trip_photos tp
JOIN trek_photos tkp ON tkp.id = tp.photo_id
WHERE tkp.asset_id = ?
`).get('asset-owned');
expect(photo).toBeDefined(); expect(photo).toBeDefined();
}); });
@@ -119,8 +119,8 @@ vi.mock('../../src/utils/ssrfGuard', async () => {
body: null, body: null,
}); });
} }
// /api/albums — list albums // /api/albums — list albums (owned and shared?=true variant)
if (/\/api\/albums$/.test(u)) { if (/\/api\/albums(\?.*)?$/.test(u)) {
return Promise.resolve({ return Promise.resolve({
ok: true, status: 200, ok: true, status: 200,
headers: { get: () => null }, headers: { get: () => null },
@@ -415,9 +415,11 @@ describe('Immich asset proxy', () => {
const { user: member } = createUser(testDb); const { user: member } = createUser(testDb);
// Insert a shared photo referencing a trip that doesn't exist (FK disabled temporarily) // Insert a shared photo referencing a trip that doesn't exist (FK disabled temporarily)
testDb.exec('PRAGMA foreign_keys = OFF'); testDb.exec('PRAGMA foreign_keys = OFF');
testDb.prepare('INSERT OR IGNORE INTO trek_photos (provider, asset_id, owner_id) VALUES (?, ?, ?)').run('immich', 'asset-notrip', owner.id);
const tkpNotrip = testDb.prepare('SELECT id FROM trek_photos WHERE provider = ? AND asset_id = ? AND owner_id = ?').get('immich', 'asset-notrip', owner.id) as any;
testDb.prepare( testDb.prepare(
'INSERT INTO trip_photos (trip_id, user_id, asset_id, provider, shared) VALUES (?, ?, ?, ?, ?)' 'INSERT INTO trip_photos (trip_id, user_id, photo_id, shared) VALUES (?, ?, ?, ?)'
).run(9999, owner.id, 'asset-notrip', 'immich', 1); ).run(9999, owner.id, tkpNotrip.id, 1);
testDb.exec('PRAGMA foreign_keys = ON'); testDb.exec('PRAGMA foreign_keys = ON');
const res = await request(app) const res = await request(app)
@@ -531,7 +533,11 @@ describe('Immich syncAlbumAssets', () => {
expect(typeof res.body.added).toBe('number'); expect(typeof res.body.added).toBe('number');
// Verify photos were inserted into the DB // Verify photos were inserted into the DB
const photos = testDb.prepare('SELECT * FROM trip_photos WHERE trip_id = ? AND user_id = ?').all(trip.id, user.id) as any[]; const photos = testDb.prepare(`
SELECT tp.*, tkp.provider FROM trip_photos tp
JOIN trek_photos tkp ON tkp.id = tp.photo_id
WHERE tp.trip_id = ? AND tp.user_id = ?
`).all(trip.id, user.id) as any[];
expect(photos.length).toBeGreaterThan(0); expect(photos.length).toBeGreaterThan(0);
expect(photos[0].provider).toBe('immich'); expect(photos[0].provider).toBe('immich');
}); });
@@ -470,9 +470,11 @@ describe('Synology asset access', () => {
const { user: member } = createUser(testDb); const { user: member } = createUser(testDb);
// Insert a shared photo referencing a trip that doesn't exist (FK disabled temporarily) // Insert a shared photo referencing a trip that doesn't exist (FK disabled temporarily)
testDb.exec('PRAGMA foreign_keys = OFF'); testDb.exec('PRAGMA foreign_keys = OFF');
testDb.prepare('INSERT OR IGNORE INTO trek_photos (provider, asset_id, owner_id) VALUES (?, ?, ?)').run('synologyphotos', '101_cachekey', owner.id);
const tkpSyno35 = testDb.prepare('SELECT id FROM trek_photos WHERE provider = ? AND asset_id = ? AND owner_id = ?').get('synologyphotos', '101_cachekey', owner.id) as any;
testDb.prepare( testDb.prepare(
'INSERT INTO trip_photos (trip_id, user_id, asset_id, provider, shared) VALUES (?, ?, ?, ?, ?)' 'INSERT INTO trip_photos (trip_id, user_id, photo_id, shared) VALUES (?, ?, ?, ?)'
).run(9999, owner.id, '101_cachekey', 'synologyphotos', 1); ).run(9999, owner.id, tkpSyno35.id, 1);
testDb.exec('PRAGMA foreign_keys = ON'); testDb.exec('PRAGMA foreign_keys = ON');
const res = await request(app) const res = await request(app)
@@ -568,7 +570,11 @@ describe('Synology syncSynologyAlbumLink', () => {
expect(typeof res.body.total).toBe('number'); expect(typeof res.body.total).toBe('number');
// Verify photos were inserted into the DB // Verify photos were inserted into the DB
const photos = testDb.prepare('SELECT * FROM trip_photos WHERE trip_id = ? AND user_id = ?').all(trip.id, user.id) as any[]; const photos = testDb.prepare(`
SELECT tp.*, tkp.provider FROM trip_photos tp
JOIN trek_photos tkp ON tkp.id = tp.photo_id
WHERE tp.trip_id = ? AND tp.user_id = ?
`).all(trip.id, user.id) as any[];
expect(photos.length).toBeGreaterThan(0); expect(photos.length).toBeGreaterThan(0);
expect(photos[0].provider).toBe('synologyphotos'); expect(photos[0].provider).toBe('synologyphotos');
}); });
@@ -146,7 +146,11 @@ describe('Unified photo management', () => {
expect(res.status).toBe(200); expect(res.status).toBe(200);
expect(res.body.added).toBe(2); expect(res.body.added).toBe(2);
const rows = testDb.prepare('SELECT asset_id FROM trip_photos WHERE trip_id = ?').all(trip.id) as any[]; const rows = testDb.prepare(`
SELECT tkp.asset_id FROM trip_photos tp
JOIN trek_photos tkp ON tkp.id = tp.photo_id
WHERE tp.trip_id = ?
`).all(trip.id) as any[];
expect(rows.map((r: any) => r.asset_id)).toEqual(expect.arrayContaining(['asset-a', 'asset-b'])); expect(rows.map((r: any) => r.asset_id)).toEqual(expect.arrayContaining(['asset-a', 'asset-b']));
}); });
@@ -178,14 +182,23 @@ describe('Unified photo management', () => {
const { user } = createUser(testDb); const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id); const trip = createTrip(testDb, user.id);
addTripPhoto(testDb, trip.id, user.id, 'asset-tog', 'immich', { shared: false }); addTripPhoto(testDb, trip.id, user.id, 'asset-tog', 'immich', { shared: false });
const trekRef = testDb.prepare(`
SELECT tp.photo_id FROM trip_photos tp
JOIN trek_photos tkp ON tkp.id = tp.photo_id
WHERE tp.trip_id = ? AND tkp.asset_id = ?
`).get(trip.id, 'asset-tog') as any;
const res = await request(app) const res = await request(app)
.put(`${photosUrl(trip.id)}/sharing`) .put(`${photosUrl(trip.id)}/sharing`)
.set('Cookie', authCookie(user.id)) .set('Cookie', authCookie(user.id))
.send({ provider: 'immich', asset_id: 'asset-tog', shared: true }); .send({ photo_id: trekRef.photo_id, shared: true });
expect(res.status).toBe(200); expect(res.status).toBe(200);
const row = testDb.prepare('SELECT shared FROM trip_photos WHERE asset_id = ?').get('asset-tog') as any; const row = testDb.prepare(`
SELECT tp.shared FROM trip_photos tp
JOIN trek_photos tkp ON tkp.id = tp.photo_id
WHERE tkp.asset_id = ?
`).get('asset-tog') as any;
expect(row.shared).toBe(1); expect(row.shared).toBe(1);
}); });
@@ -206,14 +219,23 @@ describe('Unified photo management', () => {
const { user } = createUser(testDb); const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id); const trip = createTrip(testDb, user.id);
addTripPhoto(testDb, trip.id, user.id, 'asset-del', 'immich'); addTripPhoto(testDb, trip.id, user.id, 'asset-del', 'immich');
const trekRef = testDb.prepare(`
SELECT tp.photo_id FROM trip_photos tp
JOIN trek_photos tkp ON tkp.id = tp.photo_id
WHERE tp.trip_id = ? AND tkp.asset_id = ?
`).get(trip.id, 'asset-del') as any;
const res = await request(app) const res = await request(app)
.delete(photosUrl(trip.id)) .delete(photosUrl(trip.id))
.set('Cookie', authCookie(user.id)) .set('Cookie', authCookie(user.id))
.send({ provider: 'immich', asset_id: 'asset-del' }); .send({ photo_id: trekRef.photo_id });
expect(res.status).toBe(200); expect(res.status).toBe(200);
const row = testDb.prepare('SELECT * FROM trip_photos WHERE asset_id = ?').get('asset-del'); const row = testDb.prepare(`
SELECT tp.* FROM trip_photos tp
JOIN trek_photos tkp ON tkp.id = tp.photo_id
WHERE tkp.asset_id = ?
`).get('asset-del');
expect(row).toBeUndefined(); expect(row).toBeUndefined();
}); });
@@ -473,10 +473,12 @@ describe('getVisitedRegions', () => {
const trip = createTrip(testDb, user.id, { title: 'Paris Trip' }); const trip = createTrip(testDb, user.id, { title: 'Paris Trip' });
insertPlaceWithCoords(testDb, trip.id, 'Paris Hotel', 48.85, 2.35); insertPlaceWithCoords(testDb, trip.id, 'Paris Hotel', 48.85, 2.35);
const resultPromise = getVisitedRegions(user.id); // First call triggers the background geocoding fire-and-forget
await getVisitedRegions(user.id);
// Advance all pending timers (including the 1100ms Nominatim rate-limit delay) // Advance all pending timers (including the 1100ms Nominatim rate-limit delay)
await vi.runAllTimersAsync(); await vi.runAllTimersAsync();
const result = await resultPromise; // Second call returns now-cached data
const result = await getVisitedRegions(user.id);
expect(result.regions['FR']).toBeDefined(); expect(result.regions['FR']).toBeDefined();
@@ -1132,7 +1132,11 @@ describe('setPhotoProvider', () => {
setPhotoProvider(photo!.id, 'immich', 'immich-asset-789', user.id); setPhotoProvider(photo!.id, 'immich', 'immich-asset-789', user.id);
const updated = testDb.prepare('SELECT * FROM journey_photos WHERE id = ?').get(photo!.id) as any; const updated = testDb.prepare(`
SELECT jp.*, tkp.provider, tkp.asset_id, tkp.owner_id
FROM journey_photos jp JOIN trek_photos tkp ON tkp.id = jp.photo_id
WHERE jp.id = ?
`).get(photo!.id) as any;
expect(updated.provider).toBe('immich'); expect(updated.provider).toBe('immich');
expect(updated.asset_id).toBe('immich-asset-789'); expect(updated.asset_id).toBe('immich-asset-789');
expect(updated.owner_id).toBe(user.id); expect(updated.owner_id).toBe(user.id);
@@ -1321,9 +1325,11 @@ describe('Edge cases', () => {
).get(journey.id) as any; ).get(journey.id) as any;
expect(photoEntry).toBeDefined(); expect(photoEntry).toBeDefined();
const photos = testDb.prepare( const photos = testDb.prepare(`
'SELECT * FROM journey_photos WHERE entry_id = ?' SELECT jp.*, tkp.asset_id FROM journey_photos jp
).all(photoEntry.id); JOIN trek_photos tkp ON tkp.id = jp.photo_id
WHERE jp.entry_id = ?
`).all(photoEntry.id);
expect(photos.length).toBe(1); expect(photos.length).toBe(1);
expect((photos[0] as any).asset_id).toBe('immich-photo-1'); expect((photos[0] as any).asset_id).toBe('immich-photo-1');
}); });
@@ -63,10 +63,17 @@ function insertJourneyPhoto(
entryId: number, entryId: number,
opts: { filePath?: string; assetId?: string; ownerId?: number } = {} opts: { filePath?: string; assetId?: string; ownerId?: number } = {}
): number { ): number {
const provider = opts.assetId ? 'immich' : 'local';
const filePath = !opts.assetId ? (opts.filePath ?? '/photos/test.jpg') : null;
const trekResult = testDb.prepare(`
INSERT INTO trek_photos (provider, asset_id, file_path, owner_id, created_at)
VALUES (?, ?, ?, ?, ?)
`).run(provider, opts.assetId ?? null, filePath, opts.ownerId ?? null, Date.now());
const trekId = trekResult.lastInsertRowid as number;
const result = testDb.prepare(` const result = testDb.prepare(`
INSERT INTO journey_photos (entry_id, file_path, caption, sort_order, created_at, asset_id, owner_id) INSERT INTO journey_photos (entry_id, photo_id, caption, sort_order, created_at)
VALUES (?, ?, NULL, 0, ?, ?, ?) VALUES (?, ?, NULL, 0, ?)
`).run(entryId, opts.filePath ?? '/photos/test.jpg', Date.now(), opts.assetId ?? null, opts.ownerId ?? null); `).run(entryId, trekId, Date.now());
return result.lastInsertRowid as number; return result.lastInsertRowid as number;
} }