mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
fix: return 404 for invalid shared link pages (#19493)
This commit is contained in:
parent
2e13543d5d
commit
88b8afb8d6
@ -119,6 +119,16 @@ describe('/shared-links', () => {
|
|||||||
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="https://my.immich.app`);
|
expect(resp.text).toContain(`<meta property="og:image" content="https://my.immich.app`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return 404 for an invalid shared link', async () => {
|
||||||
|
const resp = await request(shareUrl).get(`/invalid-key`);
|
||||||
|
expect(resp.status).toBe(404);
|
||||||
|
expect(resp.header['content-type']).toContain('text/html');
|
||||||
|
expect(resp.text).not.toContain(`og:type`);
|
||||||
|
expect(resp.text).not.toContain(`og:title`);
|
||||||
|
expect(resp.text).not.toContain(`og:description`);
|
||||||
|
expect(resp.text).not.toContain(`og:image`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('GET /shared-links', () => {
|
describe('GET /shared-links', () => {
|
||||||
|
@ -78,36 +78,24 @@ export class ApiService {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
const targets = [
|
let status = 200;
|
||||||
{
|
|
||||||
regex: /^\/share\/(.+)$/,
|
|
||||||
onMatch: async (matches: RegExpMatchArray) => {
|
|
||||||
const key = matches[1];
|
|
||||||
const auth = await this.authService.validateSharedLink(key);
|
|
||||||
return this.sharedLinkService.getMetadataTags(auth);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
let html = index;
|
let html = index;
|
||||||
|
|
||||||
try {
|
const shareMatches = request.url.match(/^\/share\/(.+)$/);
|
||||||
for (const { regex, onMatch } of targets) {
|
if (shareMatches) {
|
||||||
const matches = request.url.match(regex);
|
try {
|
||||||
if (matches) {
|
const key = shareMatches[1];
|
||||||
const meta = await onMatch(matches);
|
const auth = await this.authService.validateSharedLink(key);
|
||||||
if (meta) {
|
const meta = await this.sharedLinkService.getMetadataTags(auth);
|
||||||
html = render(index, meta);
|
if (meta) {
|
||||||
}
|
html = render(index, meta);
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
status = 404;
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
// nothing to do here
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res.type('text/html').header('Cache-Control', 'no-store').send(html);
|
res.status(status).type('text/html').header('Cache-Control', 'no-store').send(html);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user