mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix: return 404 for invalid shared link pages (#19493)
This commit is contained in:
parent
2e13543d5d
commit
88b8afb8d6
2 changed files with 22 additions and 24 deletions
|
|
@ -78,36 +78,24 @@ export class ApiService {
|
|||
return next();
|
||||
}
|
||||
|
||||
const targets = [
|
||||
{
|
||||
regex: /^\/share\/(.+)$/,
|
||||
onMatch: async (matches: RegExpMatchArray) => {
|
||||
const key = matches[1];
|
||||
const auth = await this.authService.validateSharedLink(key);
|
||||
return this.sharedLinkService.getMetadataTags(auth);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
let status = 200;
|
||||
let html = index;
|
||||
|
||||
try {
|
||||
for (const { regex, onMatch } of targets) {
|
||||
const matches = request.url.match(regex);
|
||||
if (matches) {
|
||||
const meta = await onMatch(matches);
|
||||
if (meta) {
|
||||
html = render(index, meta);
|
||||
}
|
||||
|
||||
break;
|
||||
const shareMatches = request.url.match(/^\/share\/(.+)$/);
|
||||
if (shareMatches) {
|
||||
try {
|
||||
const key = shareMatches[1];
|
||||
const auth = await this.authService.validateSharedLink(key);
|
||||
const meta = await this.sharedLinkService.getMetadataTags(auth);
|
||||
if (meta) {
|
||||
html = render(index, meta);
|
||||
}
|
||||
} 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…
Add table
Add a link
Reference in a new issue