From 1a4bc0b989f8b0f7521aa3e7df2e92a505c18c40 Mon Sep 17 00:00:00 2001 From: Tom <7283497+thfrei@users.noreply.github.com> Date: Tue, 3 May 2022 22:06:24 +0200 Subject: [PATCH] clean up code --- src/app.js | 5 +---- .../app/widgets/type_widgets/canvas_note.js | 21 ------------------- src/routes/api/image.js | 7 +++---- src/share/routes.js | 9 ++++---- src/share/shaca/entities/attribute.js | 3 ++- 5 files changed, 11 insertions(+), 34 deletions(-) diff --git a/src/app.js b/src/app.js index b040bad06..c024e15c0 100644 --- a/src/app.js +++ b/src/app.js @@ -30,10 +30,7 @@ app.use(express.urlencoded({extended: false})); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); app.use('/libraries', express.static(path.join(__dirname, '..', 'libraries'))); -/** - * FIXME: is it (~~crazy~~) insecure to expose node_modules globally without auth? - * without out is required for excalidraw-view mode in shared notes - */ +// node_modules required for excalidraw-view mode in shared notes app.use('/node_modules', express.static(path.join(__dirname, '..', 'node_modules'))); app.use('/images', express.static(path.join(__dirname, '..', 'images'))); const sessionParser = session({ diff --git a/src/public/app/widgets/type_widgets/canvas_note.js b/src/public/app/widgets/type_widgets/canvas_note.js index d6690405d..fa8cb1b37 100644 --- a/src/public/app/widgets/type_widgets/canvas_note.js +++ b/src/public/app/widgets/type_widgets/canvas_note.js @@ -54,15 +54,6 @@ const TPL = ` * (However, using trilium desktop instance, does not care too much about bandwidth. Size increase is probably * acceptable, as a trade off.) */ -/** - * FIXME: Buttons from one excalidraw get activated. Problems with instance?! (maybe it is only visually, once - * mouse is over one instance they change?) - */ -/** - * FIXME: FONTS from unpkg.com are loaded. Change font to HELVETICA? - * See: https://www.npmjs.com/package/@excalidraw/excalidraw => FONT_FAMILY - * => window.EXCALIDRAW_ASSET_PATH is set, however svg still contains wrong link (to excalidraw.com) - */ export default class ExcalidrawTypeWidget extends TypeWidget { constructor() { super(); @@ -418,18 +409,6 @@ export default class ExcalidrawTypeWidget extends TypeWidget { detectScroll: false, handleKeyboardGlobally: false, autoFocus: true, - // renderTopRightUI: () => { - // return React.createElement( - // React.Fragment, - // null, - // React.createElement( - // "div", - // { - // className: "excalidraw-top-right-ui", - // }, - // synchronized?"✔️":"⏳ unsaved changes" - // )); - // }, onLinkOpen, }) ) diff --git a/src/routes/api/image.js b/src/routes/api/image.js index 78ea0f124..30e7b9899 100644 --- a/src/routes/api/image.js +++ b/src/routes/api/image.js @@ -20,15 +20,14 @@ function returnImage(req, res) { } /** - * special "image" type. the canvas-note is actually type application/json but can be - * rendered on the fly to svg. + * special "image" type. the canvas-note is actually type application/json + * to avoid bitrot and enable usage as referenced image the svg is included. */ if (image.type === 'canvas-note') { - // render the svg in node.js using excalidraw and jsdom const content = image.getContent(); try { const data = JSON.parse(content); - + const svg = data.svg || '' res.set('Content-Type', "image/svg+xml"); res.set("Cache-Control", "no-cache, no-store, must-revalidate"); diff --git a/src/share/routes.js b/src/share/routes.js index 44d1cd26d..684dde3e0 100644 --- a/src/share/routes.js +++ b/src/share/routes.js @@ -122,13 +122,14 @@ function register(router) { return res.status(400).send("Requested note is not a shareable image"); } else if (image.type === "canvas-note") { /** - * FIXME: deduplicate the code from api/image.js + * special "image" type. the canvas-note is actually type application/json + * to avoid bitrot and enable usage as referenced image the svg is included. */ - // render the svg in node.js using excalidraw and jsdom const content = image.getContent(); try { - const data = JSON.parse(content) - const svg = data.svg || '' + const data = JSON.parse(content); + + const svg = data.svg || ''; addNoIndexHeader(image, res); res.set('Content-Type', "image/svg+xml"); res.set("Cache-Control", "no-cache, no-store, must-revalidate"); diff --git a/src/share/shaca/entities/attribute.js b/src/share/shaca/entities/attribute.js index 4b486d6da..9898a5f3b 100644 --- a/src/share/shaca/entities/attribute.js +++ b/src/share/shaca/entities/attribute.js @@ -38,7 +38,8 @@ class Attribute extends AbstractEntity { /** * FIXME: why can we have branch is undefined? issue when - * sharing and not sharing notes? canvas-note specific? + * sharing and not sharing notes? canvas-note specific? + * This error occured during development. */ if(branch) { branch.isHidden = true;