refactor(share): relocate 404 template

This commit is contained in:
Elian Doran 2025-06-09 16:22:22 +03:00
parent a61d76deed
commit 828da2aabf
No known key found for this signature in database
2 changed files with 11 additions and 5 deletions

View File

@ -108,7 +108,8 @@ function renderImageAttachment(image: SNote, res: Response, attachmentName: stri
let svgString = "<svg/>"; let svgString = "<svg/>";
const attachment = image.getAttachmentByTitle(attachmentName); const attachment = image.getAttachmentByTitle(attachmentName);
if (!attachment) { if (!attachment) {
res.status(404).render("share/404"); res.status(404);
renderDefault(res, "404");
return; return;
} }
const content = attachment.getContent(); const content = attachment.getContent();
@ -140,7 +141,8 @@ function register(router: Router) {
function renderNote(note: SNote, req: Request, res: Response) { function renderNote(note: SNote, req: Request, res: Response) {
if (!note) { if (!note) {
console.log("Unable to find note ", note); console.log("Unable to find note ", note);
res.status(404).render("share/404"); res.status(404);
renderDefault(res, "404");
return; return;
} }
@ -212,9 +214,7 @@ function register(router: Router) {
} }
if (useDefaultView) { if (useDefaultView) {
// Path is relative to apps/server/dist/assets/views renderDefault(res, "page", opts);
const shareThemePath = "../../share-theme/templates/page.ejs";
res.render(shareThemePath, opts);
} }
} }
@ -399,6 +399,12 @@ function register(router: Router) {
}); });
} }
function renderDefault(res: Response<any, Record<string, any>>, template: "page" | "404", opts: any = {}) {
// Path is relative to apps/server/dist/assets/views
const shareThemePath = `../../share-theme/templates/${template}.ejs`;
res.render(shareThemePath, opts);
}
export default { export default {
register register
}; };