mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
feat: use request host as default SSR domain (#19485)
fix: hostname and domain confusion chore: e2e test
This commit is contained in:
parent
db0415bbcc
commit
3c6e9e1191
@ -117,6 +117,13 @@ 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://127.0.0.1:2285`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fall back to my.immich.app og:image meta tag for shared asset if Host header is not present', async () => {
|
||||||
|
const resp = await request(shareUrl).get(`/${linkWithAssets.key}`).set('Host', '');
|
||||||
|
expect(resp.status).toBe(200);
|
||||||
|
expect(resp.header['content-type']).toContain('text/html');
|
||||||
expect(resp.text).toContain(`<meta property="og:image" content="https://my.immich.app`);
|
expect(resp.text).toContain(`<meta property="og:image" content="https://my.immich.app`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -86,7 +86,10 @@ export class ApiService {
|
|||||||
try {
|
try {
|
||||||
const key = shareMatches[1];
|
const key = shareMatches[1];
|
||||||
const auth = await this.authService.validateSharedLink(key);
|
const auth = await this.authService.validateSharedLink(key);
|
||||||
const meta = await this.sharedLinkService.getMetadataTags(auth);
|
const meta = await this.sharedLinkService.getMetadataTags(
|
||||||
|
auth,
|
||||||
|
request.host ? `${request.protocol}://${request.host}` : undefined,
|
||||||
|
);
|
||||||
if (meta) {
|
if (meta) {
|
||||||
html = render(index, meta);
|
html = render(index, meta);
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ export class SharedLinkService extends BaseService {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMetadataTags(auth: AuthDto): Promise<null | OpenGraphTags> {
|
async getMetadataTags(auth: AuthDto, defaultDomain?: string): Promise<null | OpenGraphTags> {
|
||||||
if (!auth.sharedLink || auth.sharedLink.password) {
|
if (!auth.sharedLink || auth.sharedLink.password) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -190,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)).href,
|
imageUrl: new URL(imagePath, getExternalDomain(config.server, defaultDomain)).href,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,8 @@ export const getMethodNames = (instance: any) => {
|
|||||||
return methods;
|
return methods;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getExternalDomain = (server: SystemConfig['server']) => server.externalDomain || `https://my.immich.app`;
|
export const getExternalDomain = (server: SystemConfig['server'], defaultDomain = 'https://my.immich.app') =>
|
||||||
|
server.externalDomain || defaultDomain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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