mirror of
https://github.com/immich-app/immich.git
synced 2025-06-04 22:24:26 -04:00
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:
parent
74f7fd4b53
commit
e4f83680d9
@ -117,7 +117,7 @@ describe('/shared-links', () => {
|
|||||||
const resp = await request(shareUrl).get(`/${linkWithAssets.key}`);
|
const resp = await request(shareUrl).get(`/${linkWithAssets.key}`);
|
||||||
expect(resp.status).toBe(200);
|
expect(resp.status).toBe(200);
|
||||||
expect(resp.header['content-type']).toContain('text/html');
|
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`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ describe(NotificationService.name, () => {
|
|||||||
await expect(sut.sendTestEmail('', configs.smtpTransport.notifications.smtp)).resolves.not.toThrow();
|
await expect(sut.sendTestEmail('', configs.smtpTransport.notifications.smtp)).resolves.not.toThrow();
|
||||||
expect(mocks.notification.renderEmail).toHaveBeenCalledWith({
|
expect(mocks.notification.renderEmail).toHaveBeenCalledWith({
|
||||||
template: EmailTemplate.TEST_EMAIL,
|
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(mocks.notification.sendEmail).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
@ -306,7 +306,7 @@ describe(NotificationService.name, () => {
|
|||||||
).resolves.not.toThrow();
|
).resolves.not.toThrow();
|
||||||
expect(mocks.notification.renderEmail).toHaveBeenCalledWith({
|
expect(mocks.notification.renderEmail).toHaveBeenCalledWith({
|
||||||
template: EmailTemplate.TEST_EMAIL,
|
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(mocks.notification.sendEmail).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
|
@ -146,11 +146,10 @@ export class NotificationService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { server } = await this.getConfig({ withCache: false });
|
const { server } = await this.getConfig({ withCache: false });
|
||||||
const { port } = this.configRepository.getEnv();
|
|
||||||
const { html, text } = await this.notificationRepository.renderEmail({
|
const { html, text } = await this.notificationRepository.renderEmail({
|
||||||
template: EmailTemplate.TEST_EMAIL,
|
template: EmailTemplate.TEST_EMAIL,
|
||||||
data: {
|
data: {
|
||||||
baseUrl: getExternalDomain(server, port),
|
baseUrl: getExternalDomain(server),
|
||||||
displayName: user.name,
|
displayName: user.name,
|
||||||
},
|
},
|
||||||
customTemplate: tempTemplate!,
|
customTemplate: tempTemplate!,
|
||||||
@ -170,7 +169,6 @@ export class NotificationService extends BaseService {
|
|||||||
|
|
||||||
async getTemplate(name: EmailTemplate, customTemplate: string) {
|
async getTemplate(name: EmailTemplate, customTemplate: string) {
|
||||||
const { server, templates } = await this.getConfig({ withCache: false });
|
const { server, templates } = await this.getConfig({ withCache: false });
|
||||||
const { port } = this.configRepository.getEnv();
|
|
||||||
|
|
||||||
let templateResponse = '';
|
let templateResponse = '';
|
||||||
|
|
||||||
@ -179,7 +177,7 @@ export class NotificationService extends BaseService {
|
|||||||
const { html: _welcomeHtml } = await this.notificationRepository.renderEmail({
|
const { html: _welcomeHtml } = await this.notificationRepository.renderEmail({
|
||||||
template: EmailTemplate.WELCOME,
|
template: EmailTemplate.WELCOME,
|
||||||
data: {
|
data: {
|
||||||
baseUrl: getExternalDomain(server, port),
|
baseUrl: getExternalDomain(server),
|
||||||
displayName: 'John Doe',
|
displayName: 'John Doe',
|
||||||
username: 'john@doe.com',
|
username: 'john@doe.com',
|
||||||
password: 'thisIsAPassword123',
|
password: 'thisIsAPassword123',
|
||||||
@ -194,7 +192,7 @@ export class NotificationService extends BaseService {
|
|||||||
const { html: _updateAlbumHtml } = await this.notificationRepository.renderEmail({
|
const { html: _updateAlbumHtml } = await this.notificationRepository.renderEmail({
|
||||||
template: EmailTemplate.ALBUM_UPDATE,
|
template: EmailTemplate.ALBUM_UPDATE,
|
||||||
data: {
|
data: {
|
||||||
baseUrl: getExternalDomain(server, port),
|
baseUrl: getExternalDomain(server),
|
||||||
albumId: '1',
|
albumId: '1',
|
||||||
albumName: 'Favorite Photos',
|
albumName: 'Favorite Photos',
|
||||||
recipientName: 'Jane Doe',
|
recipientName: 'Jane Doe',
|
||||||
@ -210,7 +208,7 @@ export class NotificationService extends BaseService {
|
|||||||
const { html } = await this.notificationRepository.renderEmail({
|
const { html } = await this.notificationRepository.renderEmail({
|
||||||
template: EmailTemplate.ALBUM_INVITE,
|
template: EmailTemplate.ALBUM_INVITE,
|
||||||
data: {
|
data: {
|
||||||
baseUrl: getExternalDomain(server, port),
|
baseUrl: getExternalDomain(server),
|
||||||
albumId: '1',
|
albumId: '1',
|
||||||
albumName: "John Doe's Favorites",
|
albumName: "John Doe's Favorites",
|
||||||
senderName: 'John Doe',
|
senderName: 'John Doe',
|
||||||
@ -239,11 +237,10 @@ export class NotificationService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { server, templates } = await this.getConfig({ withCache: true });
|
const { server, templates } = await this.getConfig({ withCache: true });
|
||||||
const { port } = this.configRepository.getEnv();
|
|
||||||
const { html, text } = await this.notificationRepository.renderEmail({
|
const { html, text } = await this.notificationRepository.renderEmail({
|
||||||
template: EmailTemplate.WELCOME,
|
template: EmailTemplate.WELCOME,
|
||||||
data: {
|
data: {
|
||||||
baseUrl: getExternalDomain(server, port),
|
baseUrl: getExternalDomain(server),
|
||||||
displayName: user.name,
|
displayName: user.name,
|
||||||
username: user.email,
|
username: user.email,
|
||||||
password: tempPassword,
|
password: tempPassword,
|
||||||
@ -285,11 +282,10 @@ export class NotificationService extends BaseService {
|
|||||||
const attachment = await this.getAlbumThumbnailAttachment(album);
|
const attachment = await this.getAlbumThumbnailAttachment(album);
|
||||||
|
|
||||||
const { server, templates } = await this.getConfig({ withCache: false });
|
const { server, templates } = await this.getConfig({ withCache: false });
|
||||||
const { port } = this.configRepository.getEnv();
|
|
||||||
const { html, text } = await this.notificationRepository.renderEmail({
|
const { html, text } = await this.notificationRepository.renderEmail({
|
||||||
template: EmailTemplate.ALBUM_INVITE,
|
template: EmailTemplate.ALBUM_INVITE,
|
||||||
data: {
|
data: {
|
||||||
baseUrl: getExternalDomain(server, port),
|
baseUrl: getExternalDomain(server),
|
||||||
albumId: album.id,
|
albumId: album.id,
|
||||||
albumName: album.albumName,
|
albumName: album.albumName,
|
||||||
senderName: album.owner.name,
|
senderName: album.owner.name,
|
||||||
@ -332,7 +328,6 @@ export class NotificationService extends BaseService {
|
|||||||
const attachment = await this.getAlbumThumbnailAttachment(album);
|
const attachment = await this.getAlbumThumbnailAttachment(album);
|
||||||
|
|
||||||
const { server, templates } = await this.getConfig({ withCache: false });
|
const { server, templates } = await this.getConfig({ withCache: false });
|
||||||
const { port } = this.configRepository.getEnv();
|
|
||||||
|
|
||||||
for (const recipient of recipients) {
|
for (const recipient of recipients) {
|
||||||
const user = await this.userRepository.get(recipient.id, { withDeleted: false });
|
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({
|
const { html, text } = await this.notificationRepository.renderEmail({
|
||||||
template: EmailTemplate.ALBUM_UPDATE,
|
template: EmailTemplate.ALBUM_UPDATE,
|
||||||
data: {
|
data: {
|
||||||
baseUrl: getExternalDomain(server, port),
|
baseUrl: getExternalDomain(server),
|
||||||
albumId: album.id,
|
albumId: album.id,
|
||||||
albumName: album.albumName,
|
albumName: album.albumName,
|
||||||
recipientName: recipient.name,
|
recipientName: recipient.name,
|
||||||
|
@ -309,7 +309,7 @@ describe(SharedLinkService.name, () => {
|
|||||||
mocks.sharedLink.get.mockResolvedValue(sharedLinkStub.individual);
|
mocks.sharedLink.get.mockResolvedValue(sharedLinkStub.individual);
|
||||||
await expect(sut.getMetadataTags(authStub.adminSharedLink)).resolves.toEqual({
|
await expect(sut.getMetadataTags(authStub.adminSharedLink)).resolves.toEqual({
|
||||||
description: '1 shared photos & videos',
|
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',
|
title: 'Public Share',
|
||||||
});
|
});
|
||||||
expect(mocks.sharedLink.get).toHaveBeenCalled();
|
expect(mocks.sharedLink.get).toHaveBeenCalled();
|
||||||
@ -319,7 +319,7 @@ describe(SharedLinkService.name, () => {
|
|||||||
mocks.sharedLink.get.mockResolvedValue({ ...sharedLinkStub.individual, album: undefined, assets: [] });
|
mocks.sharedLink.get.mockResolvedValue({ ...sharedLinkStub.individual, album: undefined, assets: [] });
|
||||||
await expect(sut.getMetadataTags(authStub.adminSharedLink)).resolves.toEqual({
|
await expect(sut.getMetadataTags(authStub.adminSharedLink)).resolves.toEqual({
|
||||||
description: '0 shared photos & videos',
|
description: '0 shared photos & videos',
|
||||||
imageUrl: `http://localhost:2283/feature-panel.png`,
|
imageUrl: `https://my.immich.app/feature-panel.png`,
|
||||||
title: 'Public Share',
|
title: 'Public Share',
|
||||||
});
|
});
|
||||||
expect(mocks.sharedLink.get).toHaveBeenCalled();
|
expect(mocks.sharedLink.get).toHaveBeenCalled();
|
||||||
|
@ -180,7 +180,6 @@ export class SharedLinkService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const config = await this.getConfig({ withCache: true });
|
const config = await this.getConfig({ withCache: true });
|
||||||
const { port } = this.configRepository.getEnv();
|
|
||||||
const sharedLink = await this.findOrFail(auth.sharedLink.userId, auth.sharedLink.id);
|
const sharedLink = await this.findOrFail(auth.sharedLink.userId, auth.sharedLink.id);
|
||||||
const assetId = sharedLink.album?.albumThumbnailAssetId || sharedLink.assets[0]?.id;
|
const assetId = sharedLink.album?.albumThumbnailAssetId || sharedLink.assets[0]?.id;
|
||||||
const assetCount = sharedLink.assets.length > 0 ? sharedLink.assets.length : sharedLink.album?.assets.length || 0;
|
const assetCount = sharedLink.assets.length > 0 ? sharedLink.assets.length : sharedLink.album?.assets.length || 0;
|
||||||
@ -191,7 +190,7 @@ export class SharedLinkService extends BaseService {
|
|||||||
return {
|
return {
|
||||||
title: sharedLink.album ? sharedLink.album.albumName : 'Public Share',
|
title: sharedLink.album ? sharedLink.album.albumName : 'Public Share',
|
||||||
description: sharedLink.description || `${assetCount} shared photos & videos`,
|
description: sharedLink.description || `${assetCount} shared photos & videos`,
|
||||||
imageUrl: new URL(imagePath, getExternalDomain(config.server, port)).href,
|
imageUrl: new URL(imagePath, getExternalDomain(config.server)).href,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +44,7 @@ export const getMethodNames = (instance: any) => {
|
|||||||
return methods;
|
return methods;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getExternalDomain = (server: SystemConfig['server'], port: number) =>
|
export const getExternalDomain = (server: SystemConfig['server']) => server.externalDomain || `https://my.immich.app`;
|
||||||
server.externalDomain || `http://localhost:${port}`;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns a list of strings representing the keys of the object in dot notation
|
* @returns a list of strings representing the keys of the object in dot notation
|
||||||
|
Loading…
x
Reference in New Issue
Block a user