From 90822cc8a372d4a9e363a7bc44c2ff8247ea457b Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 5 Apr 2026 11:59:45 +0300 Subject: [PATCH] chore: address requested changes --- apps/client/src/services/doc_renderer.ts | 32 +++++++++++-------- apps/server/src/services/open_id.ts | 39 +++++++++++------------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/apps/client/src/services/doc_renderer.ts b/apps/client/src/services/doc_renderer.ts index d2b2140847..74ccfa8447 100644 --- a/apps/client/src/services/doc_renderer.ts +++ b/apps/client/src/services/doc_renderer.ts @@ -21,20 +21,26 @@ export function isValidDocName(docName: string): boolean { export default function renderDoc(note: FNote) { return new Promise>((resolve) => { - let docName = note.getLabelValue("docName"); + const docName = note.getLabelValue("docName"); const $content = $("
"); - if (docName) { - // find doc based on language - const url = getUrl(docName, getCurrentLanguage()); + // find doc based on language + const url = getUrl(docName, getCurrentLanguage()); + + if (url) { $content.load(url, async (response, status) => { // fallback to english doc if no translation available if (status === "error") { const fallbackUrl = getUrl(docName, "en"); - $content.load(fallbackUrl, async () => { - await processContent(fallbackUrl, $content) + + if (fallbackUrl) { + $content.load(fallbackUrl, async () => { + await processContent(fallbackUrl, $content); + resolve($content); + }); + } else { resolve($content); - }); + } return; } @@ -44,8 +50,6 @@ export default function renderDoc(note: FNote) { } else { resolve($content); } - - return $content; }); } @@ -55,7 +59,7 @@ async function processContent(url: string, $content: JQuery) { // Images are relative to the docnote but that will not work when rendered in the application since the path breaks. $content.find("img").each((i, el) => { const $img = $(el); - $img.attr("src", dir + "/" + $img.attr("src")); + $img.attr("src", `${dir }/${ $img.attr("src")}`); }); formatCodeBlocks($content); @@ -64,15 +68,17 @@ async function processContent(url: string, $content: JQuery) { await applyReferenceLinks($content[0]); } -function getUrl(docNameValue: string, language: string) { +function getUrl(docNameValue: string | null, language: string) { + if (!docNameValue) return; + if (!isValidDocName(docNameValue)) { console.error(`Invalid docName: ${docNameValue}`); - return ""; + return null; } // Cannot have spaces in the URL due to how JQuery.load works. docNameValue = docNameValue.replaceAll(" ", "%20"); - const basePath = window.glob.isDev ? window.glob.assetPath + "/.." : window.glob.assetPath; + const basePath = window.glob.isDev ? `${window.glob.assetPath }/..` : window.glob.assetPath; return `${basePath}/doc_notes/${language}/${docNameValue}.html`; } diff --git a/apps/server/src/services/open_id.ts b/apps/server/src/services/open_id.ts index 1f2de28ba0..a6593e1bb2 100644 --- a/apps/server/src/services/open_id.ts +++ b/apps/server/src/services/open_id.ts @@ -1,4 +1,3 @@ -import crypto from "crypto"; import type { NextFunction, Request, Response } from "express"; import type { Session } from "express-openid-connect"; @@ -60,34 +59,31 @@ function getOAuthStatus() { }; } -function isTokenValid(req: Request, res: Response, next: NextFunction) { +async function isTokenValid(req: Request, res: Response, next: NextFunction) { const userStatus = openIDEncryption.isSubjectIdentifierSaved(); if (req.oidc !== undefined) { - const result = req.oidc - .fetchUserInfo() - .then((result) => { - return { - success: true, - message: "Token is valid", - user: userStatus, - }; - }) - .catch((result) => { - return { - success: false, - message: "Token is not valid", - user: userStatus, - }; - }); - return result; - } + try { + await req.oidc.fetchUserInfo(); + return { + success: true, + message: "Token is valid", + user: userStatus, + }; + } catch { + return { + success: false, + message: "Token is not valid", + user: userStatus, + }; + } + } + return { success: false, message: "Token not set up", user: userStatus, }; - } function getSSOIssuerName() { @@ -122,7 +118,6 @@ function generateOAuthConfig() { scope: "openid profile email", access_type: "offline", prompt: "consent", - state: crypto.randomUUID() }, routes: authRoutes, idpLogout: true,