feat: use my.immich.app for externalDomain fallback (#17209)

* feat: use my.immich.app for externalDomain fallback

This is probably more useful than localhost.

* chore: remove port param

* fix: update expected value in tests

* fix: update expected value in e2e
This commit is contained in:
bo0tzz 2025-03-31 13:08:41 +02:00 committed by GitHub
parent 74f7fd4b53
commit e4f83680d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 14 additions and 21 deletions

View File

@ -117,7 +117,7 @@ describe('/shared-links', () => {
const resp = await request(shareUrl).get(`/${linkWithAssets.key}`);
expect(resp.status).toBe(200);
expect(resp.header['content-type']).toContain('text/html');
expect(resp.text).toContain(`<meta property="og:image" content="http://`);
expect(resp.text).toContain(`<meta property="og:image" content="https://my.immich.app`);
});
});

View File

@ -265,7 +265,7 @@ describe(NotificationService.name, () => {
await expect(sut.sendTestEmail('', configs.smtpTransport.notifications.smtp)).resolves.not.toThrow();
expect(mocks.notification.renderEmail).toHaveBeenCalledWith({
template: EmailTemplate.TEST_EMAIL,
data: { baseUrl: 'http://localhost:2283', displayName: userStub.admin.name },
data: { baseUrl: 'https://my.immich.app', displayName: userStub.admin.name },
});
expect(mocks.notification.sendEmail).toHaveBeenCalledWith(
expect.objectContaining({
@ -306,7 +306,7 @@ describe(NotificationService.name, () => {
).resolves.not.toThrow();
expect(mocks.notification.renderEmail).toHaveBeenCalledWith({
template: EmailTemplate.TEST_EMAIL,
data: { baseUrl: 'http://localhost:2283', displayName: userStub.admin.name },
data: { baseUrl: 'https://my.immich.app', displayName: userStub.admin.name },
});
expect(mocks.notification.sendEmail).toHaveBeenCalledWith(
expect.objectContaining({

View File

@ -146,11 +146,10 @@ export class NotificationService extends BaseService {
}
const { server } = await this.getConfig({ withCache: false });
const { port } = this.configRepository.getEnv();
const { html, text } = await this.notificationRepository.renderEmail({
template: EmailTemplate.TEST_EMAIL,
data: {
baseUrl: getExternalDomain(server, port),
baseUrl: getExternalDomain(server),
displayName: user.name,
},
customTemplate: tempTemplate!,
@ -170,7 +169,6 @@ export class NotificationService extends BaseService {
async getTemplate(name: EmailTemplate, customTemplate: string) {
const { server, templates } = await this.getConfig({ withCache: false });
const { port } = this.configRepository.getEnv();
let templateResponse = '';
@ -179,7 +177,7 @@ export class NotificationService extends BaseService {
const { html: _welcomeHtml } = await this.notificationRepository.renderEmail({
template: EmailTemplate.WELCOME,
data: {
baseUrl: getExternalDomain(server, port),
baseUrl: getExternalDomain(server),
displayName: 'John Doe',
username: 'john@doe.com',
password: 'thisIsAPassword123',
@ -194,7 +192,7 @@ export class NotificationService extends BaseService {
const { html: _updateAlbumHtml } = await this.notificationRepository.renderEmail({
template: EmailTemplate.ALBUM_UPDATE,
data: {
baseUrl: getExternalDomain(server, port),
baseUrl: getExternalDomain(server),
albumId: '1',
albumName: 'Favorite Photos',
recipientName: 'Jane Doe',
@ -210,7 +208,7 @@ export class NotificationService extends BaseService {
const { html } = await this.notificationRepository.renderEmail({
template: EmailTemplate.ALBUM_INVITE,
data: {
baseUrl: getExternalDomain(server, port),
baseUrl: getExternalDomain(server),
albumId: '1',
albumName: "John Doe's Favorites",
senderName: 'John Doe',
@ -239,11 +237,10 @@ export class NotificationService extends BaseService {
}
const { server, templates } = await this.getConfig({ withCache: true });
const { port } = this.configRepository.getEnv();
const { html, text } = await this.notificationRepository.renderEmail({
template: EmailTemplate.WELCOME,
data: {
baseUrl: getExternalDomain(server, port),
baseUrl: getExternalDomain(server),
displayName: user.name,
username: user.email,
password: tempPassword,
@ -285,11 +282,10 @@ export class NotificationService extends BaseService {
const attachment = await this.getAlbumThumbnailAttachment(album);
const { server, templates } = await this.getConfig({ withCache: false });
const { port } = this.configRepository.getEnv();
const { html, text } = await this.notificationRepository.renderEmail({
template: EmailTemplate.ALBUM_INVITE,
data: {
baseUrl: getExternalDomain(server, port),
baseUrl: getExternalDomain(server),
albumId: album.id,
albumName: album.albumName,
senderName: album.owner.name,
@ -332,7 +328,6 @@ export class NotificationService extends BaseService {
const attachment = await this.getAlbumThumbnailAttachment(album);
const { server, templates } = await this.getConfig({ withCache: false });
const { port } = this.configRepository.getEnv();
for (const recipient of recipients) {
const user = await this.userRepository.get(recipient.id, { withDeleted: false });
@ -349,7 +344,7 @@ export class NotificationService extends BaseService {
const { html, text } = await this.notificationRepository.renderEmail({
template: EmailTemplate.ALBUM_UPDATE,
data: {
baseUrl: getExternalDomain(server, port),
baseUrl: getExternalDomain(server),
albumId: album.id,
albumName: album.albumName,
recipientName: recipient.name,

View File

@ -309,7 +309,7 @@ describe(SharedLinkService.name, () => {
mocks.sharedLink.get.mockResolvedValue(sharedLinkStub.individual);
await expect(sut.getMetadataTags(authStub.adminSharedLink)).resolves.toEqual({
description: '1 shared photos & videos',
imageUrl: `http://localhost:2283/api/assets/asset-id/thumbnail?key=LCtkaJX4R1O_9D-2lq0STzsPryoL1UdAbyb6Sna1xxmQCSuqU2J1ZUsqt6GR-yGm1s0`,
imageUrl: `https://my.immich.app/api/assets/asset-id/thumbnail?key=LCtkaJX4R1O_9D-2lq0STzsPryoL1UdAbyb6Sna1xxmQCSuqU2J1ZUsqt6GR-yGm1s0`,
title: 'Public Share',
});
expect(mocks.sharedLink.get).toHaveBeenCalled();
@ -319,7 +319,7 @@ describe(SharedLinkService.name, () => {
mocks.sharedLink.get.mockResolvedValue({ ...sharedLinkStub.individual, album: undefined, assets: [] });
await expect(sut.getMetadataTags(authStub.adminSharedLink)).resolves.toEqual({
description: '0 shared photos & videos',
imageUrl: `http://localhost:2283/feature-panel.png`,
imageUrl: `https://my.immich.app/feature-panel.png`,
title: 'Public Share',
});
expect(mocks.sharedLink.get).toHaveBeenCalled();

View File

@ -180,7 +180,6 @@ export class SharedLinkService extends BaseService {
}
const config = await this.getConfig({ withCache: true });
const { port } = this.configRepository.getEnv();
const sharedLink = await this.findOrFail(auth.sharedLink.userId, auth.sharedLink.id);
const assetId = sharedLink.album?.albumThumbnailAssetId || sharedLink.assets[0]?.id;
const assetCount = sharedLink.assets.length > 0 ? sharedLink.assets.length : sharedLink.album?.assets.length || 0;
@ -191,7 +190,7 @@ export class SharedLinkService extends BaseService {
return {
title: sharedLink.album ? sharedLink.album.albumName : 'Public Share',
description: sharedLink.description || `${assetCount} shared photos & videos`,
imageUrl: new URL(imagePath, getExternalDomain(config.server, port)).href,
imageUrl: new URL(imagePath, getExternalDomain(config.server)).href,
};
}

View File

@ -44,8 +44,7 @@ export const getMethodNames = (instance: any) => {
return methods;
};
export const getExternalDomain = (server: SystemConfig['server'], port: number) =>
server.externalDomain || `http://localhost:${port}`;
export const getExternalDomain = (server: SystemConfig['server']) => server.externalDomain || `https://my.immich.app`;
/**
* @returns a list of strings representing the keys of the object in dot notation