mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 23:24:46 -04:00
Add HTTP 404 error on non-existent note downloads
When FreeURL mode is enabled and you called the /download route, the note was created and the user redirected to the blank note. This is caused because the findNote method automatically creates a note when no existing one is found. This commit adds a new parameter to the findNote method which allows to disable this behaviour. In that case a HTTP 404 error will be returned. Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
929ceca20f
commit
7e597226ec
2 changed files with 6 additions and 3 deletions
|
@ -119,7 +119,7 @@ exports.doAction = function (req, res, next) {
|
||||||
default:
|
default:
|
||||||
return res.redirect(config.serverURL + '/' + noteId)
|
return res.redirect(config.serverURL + '/' + noteId)
|
||||||
}
|
}
|
||||||
})
|
}, null, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.downloadMarkdown = function (req, res, note) {
|
exports.downloadMarkdown = function (req, res, note) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ const errors = require('../../errors')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
exports.findNote = function (req, res, callback, include) {
|
exports.findNote = function (req, res, callback, include, createIfNotFound = true) {
|
||||||
const id = req.params.noteId || req.params.shortid
|
const id = req.params.noteId || req.params.shortid
|
||||||
models.Note.parseNoteId(id, function (err, _id) {
|
models.Note.parseNoteId(id, function (err, _id) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -18,9 +18,12 @@ exports.findNote = function (req, res, callback, include) {
|
||||||
},
|
},
|
||||||
include: include || null
|
include: include || null
|
||||||
}).then(function (note) {
|
}).then(function (note) {
|
||||||
if (!note) {
|
if (!note && createIfNotFound) {
|
||||||
return exports.newNote(req, res, '')
|
return exports.newNote(req, res, '')
|
||||||
}
|
}
|
||||||
|
if (!note && !createIfNotFound) {
|
||||||
|
return errors.errorNotFound(res)
|
||||||
|
}
|
||||||
if (!exports.checkViewPermission(req, note)) {
|
if (!exports.checkViewPermission(req, note)) {
|
||||||
return errors.errorForbidden(res)
|
return errors.errorForbidden(res)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue