mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	Merge remote-tracking branch 'origin/stable'
# Conflicts: # package-lock.json # package.json # src/services/build.js
This commit is contained in:
		| @@ -15,7 +15,9 @@ function exportBranch(req, res) { | |||||||
|         const message = `Cannot export branch ${branchId} since it does not exist.`; |         const message = `Cannot export branch ${branchId} since it does not exist.`; | ||||||
|         log.error(message); |         log.error(message); | ||||||
|  |  | ||||||
|         res.status(500).send(message); |         res.setHeader("Content-Type", "text/plain") | ||||||
|  |             .status(500) | ||||||
|  |             .send(message); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -41,7 +43,9 @@ function exportBranch(req, res) { | |||||||
|  |  | ||||||
|         log.error(message + e.stack); |         log.error(message + e.stack); | ||||||
|  |  | ||||||
|         res.status(500).send(message); |         res.setHeader("Content-Type", "text/plain") | ||||||
|  |             .status(500) | ||||||
|  |             .send(message); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -45,7 +45,9 @@ function downloadNoteFile(noteId, res, contentDisposition = true) { | |||||||
|     const note = becca.getNote(noteId); |     const note = becca.getNote(noteId); | ||||||
|  |  | ||||||
|     if (!note) { |     if (!note) { | ||||||
|         return res.status(404).send(`Note ${noteId} doesn't exist.`); |         return res.setHeader("Content-Type", "text/plain") | ||||||
|  |             .status(404) | ||||||
|  |             .send(`Note ${noteId} doesn't exist.`); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (note.isProtected && !protectedSessionService.isProtectedSessionAvailable()) { |     if (note.isProtected && !protectedSessionService.isProtectedSessionAvailable()) { | ||||||
|   | |||||||
| @@ -20,20 +20,22 @@ function returnImage(req, res) { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * special "image" type. the canvas is actually type application/json  |      * special "image" type. the canvas is actually type application/json | ||||||
|      * to avoid bitrot and enable usage as referenced image the svg is included. |      * to avoid bitrot and enable usage as referenced image the svg is included. | ||||||
|      */ |      */ | ||||||
|     if (image.type === 'canvas') { |     if (image.type === 'canvas') { | ||||||
|         const content = image.getContent(); |         const content = image.getContent(); | ||||||
|         try { |         try { | ||||||
|             const data = JSON.parse(content); |             const data = JSON.parse(content); | ||||||
|              |  | ||||||
|             const svg = data.svg || '<svg />' |             const svg = data.svg || '<svg />' | ||||||
|             res.set('Content-Type', "image/svg+xml"); |             res.set('Content-Type', "image/svg+xml"); | ||||||
|             res.set("Cache-Control", "no-cache, no-store, must-revalidate"); |             res.set("Cache-Control", "no-cache, no-store, must-revalidate"); | ||||||
|             res.send(svg); |             res.send(svg); | ||||||
|         } catch(err) { |         } catch(err) { | ||||||
|             res.status(500).send("there was an error parsing excalidraw to svg"); |             res.setHeader("Content-Type", "text/plain") | ||||||
|  |                 .status(500) | ||||||
|  |                 .send("there was an error parsing excalidraw to svg"); | ||||||
|         } |         } | ||||||
|     } else { |     } else { | ||||||
|         res.set('Content-Type', image.mime); |         res.set('Content-Type', image.mime); | ||||||
|   | |||||||
| @@ -65,11 +65,15 @@ function downloadNoteRevision(req, res) { | |||||||
|     const noteRevision = becca.getNoteRevision(req.params.noteRevisionId); |     const noteRevision = becca.getNoteRevision(req.params.noteRevisionId); | ||||||
|  |  | ||||||
|     if (noteRevision.noteId !== req.params.noteId) { |     if (noteRevision.noteId !== req.params.noteId) { | ||||||
|         return res.status(400).send(`Note revision ${req.params.noteRevisionId} does not belong to note ${req.params.noteId}`); |         return res.setHeader("Content-Type", "text/plain") | ||||||
|  |             .status(400) | ||||||
|  |             .send(`Note revision ${req.params.noteRevisionId} does not belong to note ${req.params.noteId}`); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (noteRevision.isProtected && !protectedSessionService.isProtectedSessionAvailable()) { |     if (noteRevision.isProtected && !protectedSessionService.isProtectedSessionAvailable()) { | ||||||
|         return res.status(401).send("Protected session not available"); |         return res.setHeader("Content-Type", "text/plain") | ||||||
|  |             .status(401) | ||||||
|  |             .send("Protected session not available"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const filename = getRevisionFilename(noteRevision); |     const filename = getRevisionFilename(noteRevision); | ||||||
|   | |||||||
| @@ -49,7 +49,9 @@ function handleRequest(req, res) { | |||||||
|             catch (e) { |             catch (e) { | ||||||
|                 log.error(`Custom handler ${note.noteId} failed with ${e.message}`); |                 log.error(`Custom handler ${note.noteId} failed with ${e.message}`); | ||||||
|  |  | ||||||
|                 res.status(500).send(e.message); |                 res.setHeader("Content-Type", "text/plain") | ||||||
|  |                     .status(500) | ||||||
|  |                     .send(e.message); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         else if (attr.name === 'customResourceProvider') { |         else if (attr.name === 'customResourceProvider') { | ||||||
| @@ -65,7 +67,9 @@ function handleRequest(req, res) { | |||||||
|     const message = `No handler matched for custom ${path} request.`; |     const message = `No handler matched for custom ${path} request.`; | ||||||
|  |  | ||||||
|     log.info(message); |     log.info(message); | ||||||
|     res.status(404).send(message); |     res.setHeader("Content-Type", "text/plain") | ||||||
|  |         .status(404) | ||||||
|  |         .send(message); | ||||||
| } | } | ||||||
|  |  | ||||||
| function register(router) { | function register(router) { | ||||||
|   | |||||||
| @@ -121,6 +121,10 @@ function apiResultHandler(req, res, result) { | |||||||
|  |  | ||||||
| function send(res, statusCode, response) { | function send(res, statusCode, response) { | ||||||
|     if (typeof response === 'string') { |     if (typeof response === 'string') { | ||||||
|  |         if (statusCode >= 400) { | ||||||
|  |             res.setHeader("Content-Type", "text/plain"); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         res.status(statusCode).send(response); |         res.status(statusCode).send(response); | ||||||
|  |  | ||||||
|         return response.length; |         return response.length; | ||||||
| @@ -168,7 +172,9 @@ function route(method, path, middleware, routeHandler, resultHandler, transactio | |||||||
|                         .catch(e => { |                         .catch(e => { | ||||||
|                             log.error(`${method} ${path} threw exception: ` + e.stack); |                             log.error(`${method} ${path} threw exception: ` + e.stack); | ||||||
|  |  | ||||||
|                             res.status(500).send(e.message); |                             res.setHeader("Content-Type", "text/plain") | ||||||
|  |                                 .status(500) | ||||||
|  |                                 .send(e.message); | ||||||
|                         }); |                         }); | ||||||
|                 } |                 } | ||||||
|                 else { |                 else { | ||||||
| @@ -181,7 +187,9 @@ function route(method, path, middleware, routeHandler, resultHandler, transactio | |||||||
|         catch (e) { |         catch (e) { | ||||||
|             log.error(`${method} ${path} threw exception: ` + e.stack); |             log.error(`${method} ${path} threw exception: ` + e.stack); | ||||||
|  |  | ||||||
|             res.status(500).send(e.message); |             res.setHeader("Content-Type", "text/plain") | ||||||
|  |                 .status(500) | ||||||
|  |                 .send(e.message); | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -88,17 +88,23 @@ function checkEtapiToken(req, res, next) { | |||||||
| function reject(req, res, message) { | function reject(req, res, message) { | ||||||
|     log.info(`${req.method} ${req.path} rejected with 401 ${message}`); |     log.info(`${req.method} ${req.path} rejected with 401 ${message}`); | ||||||
|  |  | ||||||
|     res.status(401).send(message); |     res.setHeader("Content-Type", "text/plain") | ||||||
|  |         .status(401) | ||||||
|  |         .send(message); | ||||||
| } | } | ||||||
|  |  | ||||||
| function checkCredentials(req, res, next) { | function checkCredentials(req, res, next) { | ||||||
|     if (!sqlInit.isDbInitialized()) { |     if (!sqlInit.isDbInitialized()) { | ||||||
|         res.status(400).send('Database is not initialized yet.'); |         res.setHeader("Content-Type", "text/plain") | ||||||
|  |             .status(400) | ||||||
|  |             .send('Database is not initialized yet.'); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (!passwordService.isPasswordSet()) { |     if (!passwordService.isPasswordSet()) { | ||||||
|         res.status(400).send('Password has not been set yet. Please set a password and repeat the action'); |         res.setHeader("Content-Type", "text/plain") | ||||||
|  |             .status(400) | ||||||
|  |             .send('Password has not been set yet. Please set a password and repeat the action'); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -109,7 +115,9 @@ function checkCredentials(req, res, next) { | |||||||
|     // username is ignored |     // username is ignored | ||||||
|  |  | ||||||
|     if (!passwordEncryptionService.verifyPassword(password)) { |     if (!passwordEncryptionService.verifyPassword(password)) { | ||||||
|         res.status(401).send('Incorrect password'); |         res.setHeader("Content-Type", "text/plain") | ||||||
|  |             .status(401) | ||||||
|  |             .send('Incorrect password'); | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
|         next(); |         next(); | ||||||
|   | |||||||
| @@ -39,9 +39,9 @@ function register(router) { | |||||||
|         addNoIndexHeader(note, res); |         addNoIndexHeader(note, res); | ||||||
|  |  | ||||||
|         if (note.hasLabel('shareRaw') || ['image', 'file'].includes(note.type)) { |         if (note.hasLabel('shareRaw') || ['image', 'file'].includes(note.type)) { | ||||||
|             res.setHeader('Content-Type', note.mime); |             res.setHeader('Content-Type', note.mime) | ||||||
|  |                 .send(note.getContent()); | ||||||
|  |  | ||||||
|             res.send(note.getContent()); |  | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -83,7 +83,9 @@ function register(router) { | |||||||
|         const note = shaca.getNote(noteId); |         const note = shaca.getNote(noteId); | ||||||
|  |  | ||||||
|         if (!note) { |         if (!note) { | ||||||
|             return res.status(404).send(`Note '${noteId}' not found`); |             return res.setHeader("Content-Type", "text/plain") | ||||||
|  |                 .status(404) | ||||||
|  |                 .send(`Note '${noteId}' not found`); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         addNoIndexHeader(note, res); |         addNoIndexHeader(note, res); | ||||||
| @@ -98,7 +100,9 @@ function register(router) { | |||||||
|         const note = shaca.getNote(noteId); |         const note = shaca.getNote(noteId); | ||||||
|  |  | ||||||
|         if (!note) { |         if (!note) { | ||||||
|             return res.status(404).send(`Note '${noteId}' not found`); |             return res.setHeader("Content-Type", "text/plain") | ||||||
|  |                 .status(404) | ||||||
|  |                 .send(`Note '${noteId}' not found`); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         addNoIndexHeader(note, res); |         addNoIndexHeader(note, res); | ||||||
| @@ -122,13 +126,17 @@ function register(router) { | |||||||
|         const image = shaca.getNote(req.params.noteId); |         const image = shaca.getNote(req.params.noteId); | ||||||
|  |  | ||||||
|         if (!image) { |         if (!image) { | ||||||
|             return res.status(404).send(`Note '${req.params.noteId}' not found`); |             return res.setHeader('Content-Type', 'text/plain') | ||||||
|  |                 .status(404) | ||||||
|  |                 .send(`Note '${req.params.noteId}' not found`); | ||||||
|         } |         } | ||||||
|         else if (!["image", "canvas"].includes(image.type)) { |         else if (!["image", "canvas"].includes(image.type)) { | ||||||
|             return res.status(400).send("Requested note is not a shareable image"); |             return res.setHeader('Content-Type', 'text/plain') | ||||||
|  |                 .status(400) | ||||||
|  |                 .send("Requested note is not a shareable image"); | ||||||
|         } else if (image.type === "canvas") { |         } else if (image.type === "canvas") { | ||||||
|             /** |             /** | ||||||
|              * special "image" type. the canvas is actually type application/json  |              * special "image" type. the canvas is actually type application/json | ||||||
|              * to avoid bitrot and enable usage as referenced image the svg is included. |              * to avoid bitrot and enable usage as referenced image the svg is included. | ||||||
|              */ |              */ | ||||||
|             const content = image.getContent(); |             const content = image.getContent(); | ||||||
| @@ -141,7 +149,9 @@ function register(router) { | |||||||
|                 res.set("Cache-Control", "no-cache, no-store, must-revalidate"); |                 res.set("Cache-Control", "no-cache, no-store, must-revalidate"); | ||||||
|                 res.send(svg); |                 res.send(svg); | ||||||
|             } catch(err) { |             } catch(err) { | ||||||
|                 res.status(500).send("there was an error parsing excalidraw to svg"); |                 res.setHeader('Content-Type', 'text/plain') | ||||||
|  |                     .status(500) | ||||||
|  |                     .send("there was an error parsing excalidraw to svg"); | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             // normal image |             // normal image | ||||||
| @@ -159,7 +169,9 @@ function register(router) { | |||||||
|         const note = shaca.getNote(noteId); |         const note = shaca.getNote(noteId); | ||||||
|  |  | ||||||
|         if (!note) { |         if (!note) { | ||||||
|             return res.status(404).send(`Note '${noteId}' not found`); |             return res.setHeader('Content-Type', 'text/plain') | ||||||
|  |                 .status(404) | ||||||
|  |                 .send(`Note '${noteId}' not found`); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         addNoIndexHeader(note, res); |         addNoIndexHeader(note, res); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user