summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Michelson2021-02-02 00:38:54 +0100
committerErik Michelson2021-02-02 00:38:54 +0100
commit3808c08c2db3641b0928f6dc743feb3a31bcbf43 (patch)
treea0962741d5dc1638d96b65a07c51af05106eabef
parent78a732abe691b496fa3692aa2add37f7344db1fa (diff)
Fix note creation in FreeURL mode not using template
As explained in #391, the previous note creation logic didn't handle the case "alias is set, but it's not a file on disk". The fix introduces a separate if-statement for this scenario at the cost of a doubled filesystem read access. Co-Authored-By: @evanlinde Signed-off-by: Erik Michelson <github@erik.michelson.eu>
-rw-r--r--lib/models/note.js7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/models/note.js b/lib/models/note.js
index 9fe02359..7418c47e 100644
--- a/lib/models/note.js
+++ b/lib/models/note.js
@@ -93,11 +93,12 @@ module.exports = function (sequelize, DataTypes) {
if (!note.content) {
var body = null
let filePath = null
- if (!note.alias) {
- filePath = config.defaultNotePath
- } else {
+ if (note.alias) {
filePath = path.join(config.docsPath, note.alias + '.md')
}
+ if (!filePath || !Note.checkFileExist(filePath)) {
+ filePath = config.defaultNotePath
+ }
if (Note.checkFileExist(filePath)) {
var fsCreatedTime = moment(fs.statSync(filePath).ctime)
body = fs.readFileSync(filePath, 'utf8')