Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(memories): send share link viewers the Immich preview instead of the original file

Mauricea604f8489943
diff --git a/server/src/nest/journey/journey.service.ts b/server/src/nest/journey/journey.service.ts
index 963162f08..a05cf449f 100644
--- a/server/src/nest/journey/journey.service.ts
+++ b/server/src/nest/journey/journey.service.ts
@@ -200,6 +200,7 @@ export class JourneyService {
* between them with `provider === 'immich' ? … : trySynology()`, so a third
* provider would have been handed to Synology and 404'd from inside its
* parser. An unregistered provider is now told apart from a failing one.
+ * It goes to a share link's viewer, so the provider sends the public rendition.
*/
streamProviderAsset(
res: Response,
@@ -209,6 +210,6 @@ export class JourneyService {
): Promise<void> | null {
const backend = this.providers.get(provider);
if (!backend) return null;
- return backend.streamAsset(res, ref, kind);
+ return backend.streamAsset(res, { ...ref, audience: 'public' }, kind);
}
}
diff --git a/server/src/nest/memories/immich.service.ts b/server/src/nest/memories/immich.service.ts
index 3e38dca95..cc1bc4da9 100644
--- a/server/src/nest/memories/immich.service.ts
+++ b/server/src/nest/memories/immich.service.ts
@@ -520,7 +520,7 @@ export class ImmichService {
assetId: string,
kind: 'thumbnail' | 'original',
ownerUserId?: number,
- opts?: { mediaType?: string | null; range?: string },
+ opts?: { mediaType?: string | null; range?: string; publicView?: boolean },
): Promise<void> {
const effectiveUserId = ownerUserId ?? userId;
const creds = await this.getImmichCredentials(effectiveUserId);
@@ -548,7 +548,10 @@ export class ImmichService {
cacheControl = 'private, max-age=3600';
timeout = undefined;
} else {
- url = `${creds.immich_url}/api/assets/${assetId}/thumbnail?size=fullsize`;
+ // Without a generated fullsize rendition Immich answers with the original file, GPS and all;
+ // its preview is re-encoded without the metadata, so that is what a share link gets.
+ const size = opts?.publicView ? 'preview' : 'fullsize';
+ url = `${creds.immich_url}/api/assets/${assetId}/thumbnail?size=${size}`;
timeout = 30000;
}
diff --git a/server/src/nest/memories/photo-provider.ts b/server/src/nest/memories/photo-provider.ts
index c066e1c4f..5b6beb088 100644
--- a/server/src/nest/memories/photo-provider.ts
+++ b/server/src/nest/memories/photo-provider.ts
@@ -25,6 +25,8 @@ export interface PhotoAssetRef {
mediaType?: string | null;
/** Forwarded Range header, for seeking in a video. */
range?: string;
+ /** Who the asset goes to; a share link's viewer gets an image rendered without the stored metadata. */
+ audience?: 'owner' | 'public';
}
export interface PhotoBytes {
diff --git a/server/src/nest/memories/photo-resolver.service.ts b/server/src/nest/memories/photo-resolver.service.ts
index ace31f3a1..6ee1be88b 100644
--- a/server/src/nest/memories/photo-resolver.service.ts
+++ b/server/src/nest/memories/photo-resolver.service.ts
@@ -105,8 +105,9 @@ export class PhotoResolverService {
/**
* A public share's view. A local file goes out as its location-free copy
* (PublicMediaService) and never as stored; one that cannot be cleaned falls
- * back to the thumbnail TREK re-encoded itself, else a 404. Provider assets
- * stream as for an owner.
+ * back to the thumbnail TREK re-encoded itself, else a 404. A provider is
+ * told the asset goes to the public, so it can send a rendition without the
+ * stored location in place of the original file.
*/
async streamPublicPhoto(
res: Response,
@@ -215,7 +216,7 @@ export class PhotoResolverService {
);
return;
}
- await provider.streamAsset(res, { ...ref, range }, kind);
+ await provider.streamAsset(res, { ...ref, range, audience }, kind);
}
/**
diff --git a/server/src/nest/memories/providers/immich.provider.ts b/server/src/nest/memories/providers/immich.provider.ts
index 7f39584d4..376d82002 100644
--- a/server/src/nest/memories/providers/immich.provider.ts
+++ b/server/src/nest/memories/providers/immich.provider.ts
@@ -23,6 +23,7 @@ export class ImmichPhotoProvider implements PhotoProvider {
return this.immich.streamImmichAsset(res, ref.userId, ref.assetId, kind, ref.ownerId, {
mediaType: ref.mediaType,
range: ref.range,
+ publicView: ref.audience === 'public',
});
}
diff --git a/server/tests/e2e/journey.e2e.test.ts b/server/tests/e2e/journey.e2e.test.ts
index 925e62b26..5cbf5d19b 100644
--- a/server/tests/e2e/journey.e2e.test.ts
+++ b/server/tests/e2e/journey.e2e.test.ts
@@ -16,6 +16,7 @@ import { JourneyMapService } from '../../src/nest/journey/journey-map.service';
import { JourneyShareService } from '../../src/nest/journey/journey-share.service';
import { JourneyTracksMcp } from '../../src/nest/journey/journey-tracks.mcp';
import { JourneyModule } from '../../src/nest/journey/journey.module';
+import { ImmichService } from '../../src/nest/memories/immich.service';
import { PhotoCaptureBackfillService } from '../../src/nest/memories/photo-capture-backfill.service';
import { StorageService } from '../../src/nest/storage/storage.service';
import { createTestMikroOrmModule } from '../helpers/test-orm';
@@ -117,7 +118,9 @@ const { jsvc } = vi.hoisted(() => ({
// journey hears about it after a provider add, never after an upload (#1587).
const { backfillRun, backfillSchedule } = vi.hoisted(() => ({ backfillRun: vi.fn(), backfillSchedule: vi.fn() }));
-const { sharesvc } = vi.hoisted(() => ({ sharesvc: { getPublicJourney: vi.fn() } }));
+const { sharesvc } = vi.hoisted(() => ({
+ sharesvc: { getPublicJourney: vi.fn(), validateShareTokenForAsset: vi.fn() },
+}));
// What the share service answers for a link with every section on: the route
// answers under a strict @ResponseContract, so this is also the allow-list.
@@ -688,6 +691,26 @@ describe('Journey e2e (real auth guard + temp SQLite)', () => {
expect(missing.body).toEqual({ error: 'Not found' });
});
+ it('an Immich original behind an old share link is asked for as the public rendition', async () => {
+ sharesvc.validateShareTokenForAsset.mockResolvedValueOnce({ ownerId: 1 });
+ const stream = vi.mocked(ImmichService.prototype.streamImmichAsset);
+ stream.mockImplementationOnce(async (res) => {
+ res.status(204).end();
+ });
+
+ const res = await request(server).get('/api/public/journey/tok/photo/immich/a1/1/original');
+
+ expect(res.status).toBe(204);
+ expect(stream).toHaveBeenCalledWith(
+ expect.anything(),
+ 1,
+ 'a1',
+ 'original',
+ 1,
+ expect.objectContaining({ publicView: true }),
+ );
+ });
+
// ── GPX tracks: the route and get_journey_tracks read the same service ────
const TRACK = {
diff --git a/server/tests/unit/nest/immich.service.test.ts b/server/tests/unit/nest/immich.service.test.ts
index 3ad829c70..d47bc4bdf 100644
--- a/server/tests/unit/nest/immich.service.test.ts
+++ b/server/tests/unit/nest/immich.service.test.ts
@@ -973,6 +973,23 @@ describe('streamImmichAsset', () => {
expect(url).toContain('/api/assets/a1/thumbnail');
expect((init.headers as Record<string, string>)['x-api-key']).toBe('owner-key');
});
+
+ it('IMMICH-041e: a public view of an image asks for the preview rendition, an owner and a video keep theirs', async () => {
+ await seedUser(13, 'https://immich.example', 'owner-key');
+ safeFetch.mockResolvedValue(upstream({ contentType: 'image/jpeg', body: 'bytes' }));
+
+ await svc.streamImmichAsset(makeRes() as never, USER, 'a1', 'original', 13, { publicView: true });
+ await svc.streamImmichAsset(makeRes() as never, USER, 'a1', 'original', 13);
+ await svc.streamImmichAsset(makeRes() as never, USER, 'v1', 'original', 13, {
+ mediaType: 'video',
+ publicView: true,
+ });
+
+ const urls = safeFetch.mock.calls.map((call) => String(call[0]));
+ expect(urls[0]).toContain('/api/assets/a1/thumbnail?size=preview');
+ expect(urls[1]).toContain('/api/assets/a1/thumbnail?size=fullsize');
+ expect(urls[2]).toContain('/api/assets/v1/video/playback');
+ });
});
describe('collectAlbumSelection', () => {
diff --git a/server/tests/unit/nest/photo-resolver.service.test.ts b/server/tests/unit/nest/photo-resolver.service.test.ts
index ea0faa21c..0de48538d 100644
--- a/server/tests/unit/nest/photo-resolver.service.test.ts
+++ b/server/tests/unit/nest/photo-resolver.service.test.ts
@@ -209,6 +209,17 @@ describe('streamPublicPhoto: what a share link gets', () => {
expect(res.set).not.toHaveBeenCalled();
});
+ it('RESOLVE-035: an immich original is asked for as the public rendition, and an owner still gets the original', async () => {
+ const id = await insertPhoto({ provider: 'immich', asset_id: 'a1', owner_id: 5 });
+ const res = makeRes();
+
+ await svc.streamPublicPhoto(res as never, 5, id, 'original');
+ await svc.streamPhoto(res as never, 5, id, 'original');
+
+ const views = immich.streamImmichAsset.mock.calls.map((call) => (call[5] as { publicView?: boolean }).publicView);
+ expect(views).toEqual([true, false]);
+ });
+
it('RESOLVE-034: an owner still gets the stored original', async () => {
const id = await insertPhoto({ provider: 'local', file_path: 'journey/x.jpg' });
storage.exists.mockResolvedValue(true);