diff options
author | David Mehren | 2020-11-27 18:31:19 +0100 |
---|---|---|
committer | GitHub | 2020-11-27 18:31:19 +0100 |
commit | 61f54db63eea7e590cd751d4878d1c445c7f9cf8 (patch) | |
tree | be3a61e1aa170556c7370b45e1792a0ba0dbbd52 /lib/web/note | |
parent | 07f72adc548ab8b30c4dbcc948f7cf166fdcf0db (diff) | |
parent | 97312b5ed3db8e5967184fc2f693a47dcba091f5 (diff) |
Merge pull request #596 from hedgedoc/remove-pdf-export-code
Remove pdf export code
Diffstat (limited to 'lib/web/note')
-rw-r--r-- | lib/web/note/actions.js | 33 | ||||
-rw-r--r-- | lib/web/note/controller.js | 8 |
2 files changed, 0 insertions, 41 deletions
diff --git a/lib/web/note/actions.js b/lib/web/note/actions.js index 9ff7fedb..d92d2443 100644 --- a/lib/web/note/actions.js +++ b/lib/web/note/actions.js @@ -2,9 +2,7 @@ const models = require('../../models') const logger = require('../../logger') const config = require('../../config') const errors = require('../../errors') -const fs = require('fs') const shortId = require('shortid') -const markdownpdf = require('markdown-pdf') const moment = require('moment') const querystring = require('querystring') @@ -33,37 +31,6 @@ exports.getInfo = function getInfo (req, res, note) { res.send(data) } -exports.createPDF = function createPDF (req, res, note) { - const url = config.serverURL || 'http://' + req.get('host') - const body = note.content - const extracted = models.Note.extractMeta(body) - let content = extracted.markdown - const title = models.Note.decodeTitle(note.title) - - if (!fs.existsSync(config.tmpPath)) { - fs.mkdirSync(config.tmpPath) - } - const path = config.tmpPath + '/' + Date.now() + '.pdf' - content = content.replace(/\]\(\//g, '](' + url + '/') - markdownpdf().from.string(content).to(path, function () { - if (!fs.existsSync(path)) { - logger.error('PDF seems to not be generated as expected. File doesn\'t exist: ' + path) - return errors.errorInternalError(res) - } - const stream = fs.createReadStream(path) - let filename = title - // Be careful of special characters - filename = encodeURIComponent(filename) - // Ideally this should strip them - res.setHeader('Content-disposition', 'attachment; filename="' + filename + '.pdf"') - res.setHeader('Cache-Control', 'private') - res.setHeader('Content-Type', 'application/pdf; charset=UTF-8') - res.setHeader('X-Robots-Tag', 'noindex, nofollow') // prevent crawling - stream.pipe(res) - fs.unlinkSync(path) - }) -} - exports.createGist = function createGist (req, res, note) { const data = { client_id: config.github.clientID, diff --git a/lib/web/note/controller.js b/lib/web/note/controller.js index f79574df..45aea9e2 100644 --- a/lib/web/note/controller.js +++ b/lib/web/note/controller.js @@ -110,14 +110,6 @@ exports.doAction = function (req, res, next) { case 'info': noteActions.getInfo(req, res, note) break - case 'pdf': - if (config.allowPDFExport) { - noteActions.createPDF(req, res, note) - } else { - logger.error('PDF export failed: Disabled by config. Set "allowPDFExport: true" to enable. Check the documentation for details') - errors.errorForbidden(res) - } - break case 'gist': noteActions.createGist(req, res, note) break |