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>
This commit is contained in:
Erik Michelson 2021-02-02 00:38:54 +01:00
parent 78a732abe6
commit 3808c08c2d
No known key found for this signature in database
GPG key ID: DB99ADDDC5C0AF82

View file

@ -93,11 +93,12 @@ module.exports = function (sequelize, DataTypes) {
if (!note.content) { if (!note.content) {
var body = null var body = null
let filePath = null let filePath = null
if (!note.alias) { if (note.alias) {
filePath = config.defaultNotePath
} else {
filePath = path.join(config.docsPath, note.alias + '.md') filePath = path.join(config.docsPath, note.alias + '.md')
} }
if (!filePath || !Note.checkFileExist(filePath)) {
filePath = config.defaultNotePath
}
if (Note.checkFileExist(filePath)) { if (Note.checkFileExist(filePath)) {
var fsCreatedTime = moment(fs.statSync(filePath).ctime) var fsCreatedTime = moment(fs.statSync(filePath).ctime)
body = fs.readFileSync(filePath, 'utf8') body = fs.readFileSync(filePath, 'utf8')