diff --git a/lib/models/note.js b/lib/models/note.js index 05babb4..3577d40 100644 --- a/lib/models/note.js +++ b/lib/models/note.js @@ -114,11 +114,14 @@ module.exports = function (sequelize, DataTypes) { // then will update the doc in db var fsModifiedTime = moment(fs.statSync(filePath).mtime); var dbModifiedTime = moment(note.lastchangeAt || note.createdAt); - if (fsModifiedTime.isAfter(dbModifiedTime)) { - var body = fs.readFileSync(filePath, 'utf8'); + var body = fs.readFileSync(filePath, 'utf8'); + var title = Note.parseNoteTitle(body); + body = LZString.compressToBase64(body); + title = LZString.compressToBase64(title); + if (fsModifiedTime.isAfter(dbModifiedTime) && note.content !== body) { note.update({ - title: LZString.compressToBase64(Note.parseNoteTitle(body)), - content: LZString.compressToBase64(body), + title: title, + content: body, lastchangeAt: fsModifiedTime }).then(function (note) { sequelize.models.Revision.saveNoteRevision(note, function (err, revision) {