fix(share): custom share templates no longer working

This commit is contained in:
Elian Doran 2025-06-05 14:32:25 +03:00
parent 79dae44dbc
commit b39119119b
No known key found for this signature in database
3 changed files with 14 additions and 6 deletions

Binary file not shown.

View File

@ -33,4 +33,13 @@ describe("Share API test", () => {
expect(cannotSetHeadersCount).toBe(0); expect(cannotSetHeadersCount).toBe(0);
}); });
it("renders custom share template", async () => {
const response = await supertest(app)
.get("/share/pQvNLLoHcMwH")
.expect(200);
expect(cannotSetHeadersCount).toBe(0);
expect(response.text).toContain("Content Start");
expect(response.text).toContain("Content End");
});
}); });

View File

@ -136,7 +136,7 @@ function renderImageAttachment(image: SNote, res: Response, attachmentName: stri
} }
function register(router: Router) { function register(router: Router) {
function renderNote(note: SNote, req: Request, res: Response) { async 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).render("share/404");
@ -197,11 +197,10 @@ function register(router: Router) {
try { try {
const content = templateNote.getContent(); const content = templateNote.getContent();
if (typeof content === "string") { if (typeof content === "string") {
import("ejs").then((ejs) => { const ejs = await import("ejs");
const ejsResult = ejs.render(content, opts, { includer }); const ejsResult = ejs.render(content, opts, { includer });
res.send(ejsResult); res.send(ejsResult);
useDefaultView = false; // Rendering went okay, don't use default view useDefaultView = false; // Rendering went okay, don't use default view
});
} }
} catch (e: unknown) { } catch (e: unknown) {
const [errMessage, errStack] = safeExtractMessageAndStackFromError(e); const [errMessage, errStack] = safeExtractMessageAndStackFromError(e);