From a08985e7a688c3bbfa8582eaacf4ecbeb821195c Mon Sep 17 00:00:00 2001 From: Matt <69441971+sigaloid@users.noreply.github.com> Date: Fri, 24 Dec 2021 21:36:31 +0000 Subject: [PATCH] Display PDF in shared notes (#2466) * Add PDF rendering * Cleanup --- src/share/content_renderer.js | 9 +++++++-- src/share/routes.js | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/share/content_renderer.js b/src/share/content_renderer.js index 0d300f61b..51cb7248b 100644 --- a/src/share/content_renderer.js +++ b/src/share/content_renderer.js @@ -76,7 +76,12 @@ function getContent(note) { content = ``; } else if (note.type === 'file') { - content = ``; + if (note.mime === 'application/pdf') { + content = `` + } + else { + content = ``; + } } else if (note.type === 'book') { content = getChildrenList(note); @@ -84,7 +89,7 @@ function getContent(note) { else { content = '
This note type cannot be displayed.
' + getChildrenList(note); } - + return content; } diff --git a/src/share/routes.js b/src/share/routes.js index 816664313..ee0a4ce9c 100644 --- a/src/share/routes.js +++ b/src/share/routes.js @@ -78,6 +78,26 @@ function register(router) { res.send(note.getContent()); }); + + router.get('/share/api/notes/:noteId/view', (req, res, next) => { + const {noteId} = req.params; + const note = shaca.getNote(noteId); + + if (!note) { + return res.status(404).send(`Not found`); + } + + const utils = require("../services/utils"); + + const filename = utils.formatDownloadTitle(note.title, note.type, note.mime); + + // res.setHeader('Content-Disposition', utils.getContentDisposition(filename)); + + res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); + res.setHeader('Content-Type', note.mime); + + res.send(note.getContent()); + }); } module.exports = {