Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(script): add warning if trying to render an unavailable protected server-side note (closes #21)
Elian Doranfb339213081d
diff --git a/apps/server/src/services/script.ts b/apps/server/src/services/script.tsindex 8f971f2d4f..c030aae86a 100644--- a/apps/server/src/services/script.ts+++ b/apps/server/src/services/script.ts@@ -21,7 +21,11 @@ export interface Bundle {type ScriptParams = any[];function executeNote(note: BNote, apiParams: ApiParams) {- if (!note.isJavaScript() || note.getScriptEnv() !== "backend" || !note.isContentAvailable()) {+ if (!note.isContentAvailable()) {+ throw new Error(`Cannot execute script note '${note.noteId}' because it is protected and protected session is not available. Enter protected session and try again.`);+ }++ if (!note.isJavaScript() || note.getScriptEnv() !== "backend") {log.info(`Cannot execute note ${note.noteId} "${note.title}", note must be of type "Code: JS backend"`);// Warn the user if they're trying to run a frontend script in the backend@@ -171,7 +175,7 @@ function getScriptBundleForFrontend(note: BNote, script?: string, params?: Scripexport function getScriptBundle(note: BNote, root: boolean = true, scriptEnv: string | null = null, includedNoteIds: string[] = [], overrideContent: string | null = null): Bundle | undefined {if (!note.isContentAvailable()) {- return;+ throw new Error(`Cannot execute script note '${note.noteId}' because it is protected and protected session is not available. Enter protected session and try again.`);}if (!(note.isJavaScript() || note.isHtml() || note.isJsx())) {