diff options
author | Wu Cheng-Han | 2016-12-16 15:38:05 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2016-12-16 15:38:05 +0800 |
commit | 5bb3de2675967eb2f6ea295e7c3e969769ed2a70 (patch) | |
tree | e0b3679ced52018b1d90f58f00c4c1608afa35c7 /lib | |
parent | 4b7b902806c818aa4a93671624ecb84b3902ef50 (diff) |
Add support of allow free url config option with correspond modifications
Diffstat (limited to '')
-rw-r--r-- | lib/config.js | 3 | ||||
-rwxr-xr-x | lib/response.js | 11 |
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/config.js b/lib/config.js index fee28653..d87964a0 100644 --- a/lib/config.js +++ b/lib/config.js @@ -21,6 +21,8 @@ var usecdn = process.env.HMD_USECDN ? (process.env.HMD_USECDN === 'true') : ((ty var allowanonmyous = process.env.HMD_ALLOW_ANONMYOUS ? (process.env.HMD_ALLOW_ANONMYOUS === 'true') : ((typeof config.allowanonmyous === 'boolean') ? config.allowanonmyous : true); +var allowfreeurl = process.env.HMD_ALLOW_FREEURL ? (process.env.HMD_ALLOW_FREEURL === 'true') : !!config.allowfreeurl; + // db var db = config.db || { dialect: 'sqlite', @@ -128,6 +130,7 @@ module.exports = { serverurl: getserverurl(), usecdn: usecdn, allowanonmyous: allowanonmyous, + allowfreeurl: allowfreeurl, db: db, sslkeypath: path.join(cwd, sslkeypath), sslcertpath: path.join(cwd, sslcertpath), diff --git a/lib/response.js b/lib/response.js index 3f837e71..3374eaf5 100755 --- a/lib/response.js +++ b/lib/response.js @@ -112,7 +112,8 @@ function newNote(req, res, next) { return response.errorForbidden(res); } models.Note.create({ - ownerId: owner + ownerId: owner, + alias: req.alias ? req.alias : null }).then(function (note) { return res.redirect(config.serverurl + "/" + LZString.compressToBase64(note.id)); }).catch(function (err) { @@ -133,6 +134,7 @@ function checkViewPermission(req, note) { } function findNote(req, res, callback, include) { + var noteId = req.params.noteId; var id = req.params.noteId || req.params.shortid; models.Note.parseNoteId(id, function (err, _id) { models.Note.findOne({ @@ -142,7 +144,12 @@ function findNote(req, res, callback, include) { include: include || null }).then(function (note) { if (!note) { - return response.errorNotFound(res); + if (config.allowfreeurl && noteId) { + req.alias = noteId; + return newNote(req, res); + } else { + return response.errorNotFound(res); + } } if (!checkViewPermission(req, note)) { return response.errorForbidden(res); |