Skip to content

Commit 5bb3de2

Browse files
committed
Add support of allow free url config option with correspond modifications
1 parent 4b7b902 commit 5bb3de2

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Environment variables (will overwrite other server configs)
119119
| HMD_URL_ADDPORT | `true` or `false` | set to add port on callback url (port 80 or 443 won't applied) (only applied when domain is set) |
120120
| HMD_USECDN | `true` or `false` | set to use CDN resources or not (default is `true`) |
121121
| HMD_ALLOW_ANONMYOUS | `true` or `false` | set to allow anonmyous usage (default is `true`) |
122+
| HMD_ALLOW_FREEURL | `true` or `false` | set to allow new note by accessing not exist note url |
122123
| HMD_FACEBOOK_CLIENTID | no example | Facebook API client id |
123124
| HMD_FACEBOOK_CLIENTSECRET | no example | Facebook API client secret |
124125
| HMD_TWITTER_CONSUMERKEY | no example | Twitter API consumer key |
@@ -155,6 +156,7 @@ Server settings `config.json`
155156
| urladdport | `true` or `false` | set to add port on callback url (port 80 or 443 won't applied) (only applied when domain is set) |
156157
| usecdn | `true` or `false` | set to use CDN resources or not (default is `true`) |
157158
| allowanonmyous | `true` or `false` | set to allow anonmyous usage (default is `true`) |
159+
| allowfreeurl | `true` or `false` | set to allow new note by accessing not exist note url |
158160
| db | `{ "dialect": "sqlite", "storage": "./db.hackmd.sqlite" }` | set the db configs, [see more here](http://sequelize.readthedocs.org/en/latest/api/sequelize/) |
159161
| sslkeypath | `./cert/client.key` | ssl key path (only need when you set usessl) |
160162
| sslcertpath | `./cert/hackmd_io.crt` | ssl cert path (only need when you set usessl) |

lib/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ var usecdn = process.env.HMD_USECDN ? (process.env.HMD_USECDN === 'true') : ((ty
2121

2222
var allowanonmyous = process.env.HMD_ALLOW_ANONMYOUS ? (process.env.HMD_ALLOW_ANONMYOUS === 'true') : ((typeof config.allowanonmyous === 'boolean') ? config.allowanonmyous : true);
2323

24+
var allowfreeurl = process.env.HMD_ALLOW_FREEURL ? (process.env.HMD_ALLOW_FREEURL === 'true') : !!config.allowfreeurl;
25+
2426
// db
2527
var db = config.db || {
2628
dialect: 'sqlite',
@@ -128,6 +130,7 @@ module.exports = {
128130
serverurl: getserverurl(),
129131
usecdn: usecdn,
130132
allowanonmyous: allowanonmyous,
133+
allowfreeurl: allowfreeurl,
131134
db: db,
132135
sslkeypath: path.join(cwd, sslkeypath),
133136
sslcertpath: path.join(cwd, sslcertpath),

lib/response.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ function newNote(req, res, next) {
112112
return response.errorForbidden(res);
113113
}
114114
models.Note.create({
115-
ownerId: owner
115+
ownerId: owner,
116+
alias: req.alias ? req.alias : null
116117
}).then(function (note) {
117118
return res.redirect(config.serverurl + "/" + LZString.compressToBase64(note.id));
118119
}).catch(function (err) {
@@ -133,6 +134,7 @@ function checkViewPermission(req, note) {
133134
}
134135

135136
function findNote(req, res, callback, include) {
137+
var noteId = req.params.noteId;
136138
var id = req.params.noteId || req.params.shortid;
137139
models.Note.parseNoteId(id, function (err, _id) {
138140
models.Note.findOne({
@@ -142,7 +144,12 @@ function findNote(req, res, callback, include) {
142144
include: include || null
143145
}).then(function (note) {
144146
if (!note) {
145-
return response.errorNotFound(res);
147+
if (config.allowfreeurl && noteId) {
148+
req.alias = noteId;
149+
return newNote(req, res);
150+
} else {
151+
return response.errorNotFound(res);
152+
}
146153
}
147154
if (!checkViewPermission(req, note)) {
148155
return response.errorForbidden(res);

0 commit comments

Comments
 (0)