mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-21 22:31:46 +00:00
fix(journey): serve local file when uploading photos with Immich sync enabled
After upload, trek_photos.provider is immediately flipped to 'immich' even though Immich's thumbnail generation is async. streamPhoto then routed to Immich, which returned an error for the not-yet-processed asset. Because Cache-Control was set before the proxy attempt, the error response was cached by the browser for 24h — breaking thumbnails until a hard refresh bypassed the cache and Immich had finished processing. - streamPhoto now prefers the local file_path when it exists on disk, regardless of provider; Immich/Synology are only used when no local file is available (fixes the immediate broken-thumbnail symptom) - pipeAsset sets Cache-Control: no-store on upstream errors and uses the caller-supplied default only on success (prevents cache poisoning) - streamImmichAsset no longer pre-sets Cache-Control before the proxy - streamSynologyAsset passes the same defaultCacheControl through pipeAsset Closes #691
This commit is contained in:
@@ -253,13 +253,19 @@ export function updateSyncTimeForAlbumLink(linkId: string): void {
|
||||
db.prepare('UPDATE trip_album_links SET last_synced_at = CURRENT_TIMESTAMP WHERE id = ?').run(linkId);
|
||||
}
|
||||
|
||||
export async function pipeAsset(url: string, response: Response, headers?: Record<string, string>, signal?: AbortSignal): Promise<void> {
|
||||
export async function pipeAsset(url: string, response: Response, headers?: Record<string, string>, signal?: AbortSignal, defaultCacheControl?: string): Promise<void> {
|
||||
try {
|
||||
const resp = await safeFetch(url, { headers, signal: signal as any });
|
||||
|
||||
response.status(resp.status);
|
||||
if (resp.headers.get('content-type')) response.set('Content-Type', resp.headers.get('content-type') as string);
|
||||
if (resp.headers.get('cache-control')) response.set('Cache-Control', resp.headers.get('cache-control') as string);
|
||||
if (!resp.ok) {
|
||||
response.set('Cache-Control', 'no-store, max-age=0');
|
||||
} else if (resp.headers.get('cache-control')) {
|
||||
response.set('Cache-Control', resp.headers.get('cache-control') as string);
|
||||
} else if (defaultCacheControl) {
|
||||
response.set('Cache-Control', defaultCacheControl);
|
||||
}
|
||||
if (resp.headers.get('content-length')) response.set('Content-Length', resp.headers.get('content-length') as string);
|
||||
if (resp.headers.get('content-disposition')) response.set('Content-Disposition', resp.headers.get('content-disposition') as string);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user