mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-17 08:38:18 +00:00
markdown sync问题
markdown fixConflict有问题 原因, changeNote保存了笔记, 在nodejs端判断title, content, tags是否修改了, 若修改了才算是dirty [ok] markdown 莫名变成了非markdown editor 更新了其它非markdown笔记导致 send changes 后, server端总会返回IsMarkdown为false [ok]
This commit is contained in:
21
node_modules/api.js
generated
vendored
21
node_modules/api.js
generated
vendored
@@ -498,11 +498,11 @@ var Api = {
|
||||
Title: note.Title,
|
||||
NotebookId: serverNotebookId,
|
||||
Content: note.Content,
|
||||
IsMarkdown: note.isMarkdown,
|
||||
IsMarkdown: note.IsMarkdown,
|
||||
Tags: note.Tags,
|
||||
IsBlog: note.IsBlog,
|
||||
Files: note.Files,
|
||||
FileDatas: note.FileDatas
|
||||
FileDatas: note.FileDatas,
|
||||
}
|
||||
// log('add note');
|
||||
// log(data);
|
||||
@@ -543,6 +543,9 @@ var Api = {
|
||||
updateNote: function(note, callback) {
|
||||
var me = this;
|
||||
Notebook.getServerNotebookIdByNotebookId(note.NotebookId, function(serverNotebookId) {
|
||||
if(!note.Tags || note.Tags.length == 0) {
|
||||
note.Tags = [''];
|
||||
}
|
||||
var data = {
|
||||
noteId: note.ServerNoteId,
|
||||
notebookId: serverNotebookId || "",
|
||||
@@ -551,7 +554,8 @@ var Api = {
|
||||
isTrash: note.IsTrash,
|
||||
content: note.Content,
|
||||
Files: note.Files,
|
||||
FileDatas: note.FileDatas
|
||||
FileDatas: note.FileDatas,
|
||||
tags: note.Tags, // 新添加
|
||||
}
|
||||
console.log('update note :');
|
||||
console.log(data);
|
||||
@@ -573,6 +577,8 @@ var Api = {
|
||||
var ret = resp.body;
|
||||
log('update note ret:');
|
||||
log(ret);
|
||||
// 没有传IsMarkdown, 后台会传过来总为false
|
||||
delete ret['IsMarkdown'];
|
||||
callback(ret);
|
||||
/*
|
||||
if(Common.isOk(ret)) {
|
||||
@@ -630,11 +636,12 @@ var Api = {
|
||||
return callback && callback(false);
|
||||
}
|
||||
var ret = resp.body;
|
||||
log('add tag ret ==========');
|
||||
log(ret);
|
||||
console.log('add tag ret ==========');
|
||||
console.log(ret);
|
||||
if(Common.isOk(ret)) {
|
||||
// 以后不要再发了
|
||||
Tag.setNotDirty(title);
|
||||
// Tag.setNotDirty(title);
|
||||
// 更新, 添加usn
|
||||
Tag.setNotDirtyAndUsn(title, ret.Usn);
|
||||
callback && callback(ret);
|
||||
} else {
|
||||
callback && callback(false);
|
||||
|
86
node_modules/note.js
generated
vendored
86
node_modules/note.js
generated
vendored
@@ -44,7 +44,8 @@ var Note = {
|
||||
var me = this;
|
||||
var userId = User.getCurActiveUserId();
|
||||
noteOrContent['UserId'] = userId;
|
||||
console.log('updateNoteOrContent: ');
|
||||
console.error("updateNoteOrContent")
|
||||
console.trace('updateNoteOrContent: ');
|
||||
console.log(noteOrContent);
|
||||
var date = new Date();
|
||||
noteOrContent.UpdatedTime = date;
|
||||
@@ -92,25 +93,46 @@ var Note = {
|
||||
needUpdate = true;
|
||||
}
|
||||
}
|
||||
if('Content' in updateFields) {
|
||||
if('Content' in updates) {
|
||||
// 内容更新了, 因为内容是以后才从远程获取的, 获取内容后改变ContentIsDirty=false
|
||||
noteOrContent['ContentIsDirty'] = true;
|
||||
}
|
||||
if(needUpdate) {
|
||||
updates['IsDirty'] = true;
|
||||
updates['LocalIsDelete'] = false;
|
||||
updates.UpdatedTime = date;
|
||||
// Set an existing field's value
|
||||
Notes.update({NoteId: noteOrContent.NoteId}, { $set: updates }, {}, function (err, numReplaced) {
|
||||
if(err) {
|
||||
callback && callback(false);
|
||||
} else {
|
||||
callback && callback(noteOrContent);
|
||||
|
||||
if('Content' in updates) {
|
||||
me.addNoteHistory(noteOrContent.NoteId, noteOrContent.Content);
|
||||
var isDirty = false;
|
||||
me.getNote(noteOrContent.NoteId, function(dbNote) {
|
||||
// 只有title, Content, Tags修改了才算是IsDirty
|
||||
if('Content' in updates && dbNote['Content'] != updates['Content']) {
|
||||
isDirty = true;
|
||||
} else if('Title' in updates && dbNote['Title'] != updates['Title']) {
|
||||
isDirty = true;
|
||||
} else if('Tags' in updates) {
|
||||
var dbTags = dbNote['Tags'] || [];
|
||||
var nowTags = updates['Tags'] || [];
|
||||
if(dbTags.join(',') != nowTags.join(',')) {
|
||||
isDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
console.log('update note isDirty: ' + noteOrContent.NoteId);
|
||||
console.error(isDirty);
|
||||
|
||||
updates['IsDirty'] = isDirty;
|
||||
updates['LocalIsDelete'] = false;
|
||||
updates.UpdatedTime = date;
|
||||
|
||||
// Set an existing field's value
|
||||
Notes.update({NoteId: noteOrContent.NoteId}, { $set: updates }, {}, function (err, numReplaced) {
|
||||
if(err) {
|
||||
callback && callback(false);
|
||||
} else {
|
||||
callback && callback(noteOrContent);
|
||||
|
||||
if('Content' in updates) {
|
||||
me.addNoteHistory(noteOrContent.NoteId, noteOrContent.Content);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -198,7 +220,8 @@ var Note = {
|
||||
|
||||
searchNote: function(key, callback) {
|
||||
var reg = new RegExp(key);
|
||||
Notes.find({IsTrash: false, LocalIsDelete: false, $or: [{Title: reg}, {Content: reg}]}).sort({'UpdatedTime': -1}).exec(function(err, notes) {
|
||||
var userId = User.getCurActiveUserId();
|
||||
Notes.find({UserId: userId, IsTrash: false, LocalIsDelete: false, $or: [{Title: reg}, {Content: reg}]}).sort({'UpdatedTime': -1}).exec(function(err, notes) {
|
||||
if(!err && notes) {
|
||||
console.log('search ' + key + ' result: ' + notes.length);
|
||||
callback(notes);
|
||||
@@ -209,7 +232,8 @@ var Note = {
|
||||
},
|
||||
|
||||
searchNoteByTag: function(tag, callback) {
|
||||
Notes.find({IsTrash: false, LocalIsDelete: false, Tags: {$in: [tag]}}).sort({'UpdatedTime': -1}).exec(function(err, notes) {
|
||||
var userId = User.getCurActiveUserId();
|
||||
Notes.find({UserId: userId, IsTrash: false, LocalIsDelete: false, Tags: {$in: [tag]}}).sort({'UpdatedTime': -1}).exec(function(err, notes) {
|
||||
if(!err && notes) {
|
||||
console.log('search by tag: ' + tag + ' result: ' + notes.length);
|
||||
callback(notes);
|
||||
@@ -332,10 +356,10 @@ var Note = {
|
||||
content = content.replace(reg, Server.localUrl + '/api/file/getImage');
|
||||
|
||||
var reg2 = new RegExp(Evt.leanoteUrl + '/api/file/getAttach', 'g');
|
||||
content = content.replace(reg, Evt.localUrl + '/api/file/getAttach');
|
||||
content = content.replace(reg2, Evt.localUrl + '/api/file/getAttach');
|
||||
|
||||
var reg3 = new RegExp(Evt.leanoteUrl + '/api/file/getAllAttach', 'g');
|
||||
content = content.replace(reg, Evt.localUrl + '/api/file/getAllAttach');
|
||||
content = content.replace(reg3, Evt.localUrl + '/api/file/getAllAttach');
|
||||
|
||||
return content;
|
||||
},
|
||||
@@ -345,15 +369,16 @@ var Note = {
|
||||
if(!content) {
|
||||
return content;
|
||||
}
|
||||
console.log(Evt.localUrl + '/api/file/getImage');
|
||||
// console.log(Evt.localUrl + '/api/file/getImage');
|
||||
// console.log(content);
|
||||
var reg = new RegExp(Evt.localUrl + '/api/file/getImage', 'g');
|
||||
content = content.replace(reg, Evt.leanoteUrl + '/api/file/getImage');
|
||||
|
||||
var reg2 = new RegExp(Evt.localUrl + '/api/file/getAttach', 'g');
|
||||
content = content.replace(reg, Evt.leanoteUrl + '/api/file/getAttach');
|
||||
content = content.replace(reg2, Evt.leanoteUrl + '/api/file/getAttach');
|
||||
|
||||
var reg3 = new RegExp(Evt.localUrl + '/api/file/getAllAttach', 'g');
|
||||
content = content.replace(reg, Evt.leanoteUrl + '/api/file/getAllAttach');
|
||||
content = content.replace(reg3, Evt.leanoteUrl + '/api/file/getAllAttach');
|
||||
|
||||
return content;
|
||||
},
|
||||
@@ -452,12 +477,17 @@ var Note = {
|
||||
|
||||
getNoteByServerNoteId: function(noteId, callback) {
|
||||
var me = this;
|
||||
Notes.findOne({ServerNoteId: noteId}, function(err, doc) {
|
||||
Notes.find({ServerNoteId: noteId}, function(err, doc) {
|
||||
// console.log(doc.length + '...');
|
||||
if(doc.length > 1) {
|
||||
console.error(doc.length + '. ..');
|
||||
}
|
||||
console.log('note length: ' + doc.length + '. ..');
|
||||
if(err || !doc) {
|
||||
log('getNoteByServerNoteId 不存在' + noteId);
|
||||
callback && callback(false);
|
||||
} else {
|
||||
doc = doc[0];
|
||||
callback && callback(doc);
|
||||
}
|
||||
});
|
||||
@@ -617,6 +647,8 @@ var Note = {
|
||||
|
||||
console.log("updateNoteForce 后的")
|
||||
console.log(note);
|
||||
console.log(note.ServerNoteId + " " + note.IsDirty);
|
||||
|
||||
console.log('ever note');
|
||||
console.log(everNote.NoteId);
|
||||
console.log(everNote);
|
||||
@@ -632,6 +664,11 @@ var Note = {
|
||||
console.log('强制更新...');
|
||||
callback && callback(note);
|
||||
|
||||
me.getNoteByServerNoteId(note.ServerNoteId, function(t) {
|
||||
console.log('强制更新后的...');
|
||||
console.log(t);
|
||||
});
|
||||
|
||||
// 下载内容, 图片, 附件
|
||||
me.syncContentAndImagesAndAttachs(note);
|
||||
}
|
||||
@@ -750,7 +787,7 @@ var Note = {
|
||||
// 新Id
|
||||
delete note['_id'];
|
||||
delete note['ServerNoteId'];
|
||||
note.NoteId = Common.objectId();
|
||||
note.NoteId = Common.objectId(); // 新生成一个NoteId
|
||||
note.ConflictNoteId = noteId; // 与noteId有冲突
|
||||
note.ConflictTime = new Date(); // 发生冲突时间
|
||||
note.ConflictFixed = false; // 冲突未解决
|
||||
@@ -794,7 +831,7 @@ var Note = {
|
||||
}, function() {
|
||||
note.Attachs = newAttachs;
|
||||
console.log('conflict 复制后的');
|
||||
console.log(note.Attachs);
|
||||
console.log(note);
|
||||
Notes.insert(note, function(err, newNote) {
|
||||
if(err) {
|
||||
callback(false);
|
||||
@@ -888,6 +925,7 @@ var Note = {
|
||||
async.eachSeries(conflictNotes, function(note, cb) { // note是服务器上最新的, note.NoteId, ServerNoteId已转换
|
||||
var noteId = note.NoteId; // 本地noteId
|
||||
// 复制一份, 本地的复制一份, 然后服务器上的替换本地的
|
||||
// newNote其实是现有的复制一份得到的
|
||||
me.copyNoteForConfict(noteId, function(newNote) {
|
||||
if(newNote) {
|
||||
// 更新之前的
|
||||
|
11
node_modules/sync.js
generated
vendored
11
node_modules/sync.js
generated
vendored
@@ -278,7 +278,7 @@ var Sync = {
|
||||
Note.getNoteByServerNoteId(noteId, function(noteLocal) {
|
||||
// 2.1 本地没有, 表示是新建
|
||||
if(!noteLocal) {
|
||||
log('add: ...')
|
||||
console.log('add: ...');
|
||||
Note.addNoteForce(note, function(note) {
|
||||
me._syncInfo.note.adds.push(note);
|
||||
return canCall();
|
||||
@@ -287,7 +287,10 @@ var Sync = {
|
||||
// 2.2 本地是否修改了, 冲突, 报告给前端, 前端处理
|
||||
// 冲突, 将本地修改的笔记复制一份(设置冲突字段, ConflictNoteId), 远程的覆盖本地的
|
||||
if(noteLocal.IsDirty) {
|
||||
log('note 冲突....')
|
||||
console.log('note 冲突.... serverNoteId: ' + noteId);
|
||||
console.log(noteLocal.NoteId);
|
||||
console.log(noteLocal.IsDirty);
|
||||
console.log(noteLocal);
|
||||
note.ServerNoteId = note.NoteId;
|
||||
note.NoteId = noteLocal.NoteId;
|
||||
me._syncInfo.note.conflicts.push(note);
|
||||
@@ -823,6 +826,7 @@ var Sync = {
|
||||
return cb();
|
||||
}
|
||||
me._syncInfo.note.changeAdds.push(newTag);
|
||||
// Tag.updateTagForce(newTag);
|
||||
me.checkNeedIncSyncAgain(newTag.Usn);
|
||||
cb();
|
||||
});
|
||||
@@ -831,6 +835,9 @@ var Sync = {
|
||||
Api.deleteTag(tag, function(ret) {
|
||||
if(Common.isOk(ret)) {
|
||||
me.checkNeedIncSyncAgain(ret.Usn);
|
||||
} else {
|
||||
// 有问题, 可能本地不存在
|
||||
Tag.setNotDirty(tag);
|
||||
}
|
||||
return cb();
|
||||
});
|
||||
|
10
node_modules/tag.js
generated
vendored
10
node_modules/tag.js
generated
vendored
@@ -97,6 +97,16 @@ var Tag = {
|
||||
});
|
||||
},
|
||||
|
||||
// 添加tag后的返回, 更新usn
|
||||
updateTagForce: function(tag, callback) {
|
||||
var me = this;
|
||||
tag.IsDirty = false;
|
||||
var userId = User.getCurActiveUserId();
|
||||
Tags.update({UserId: userId, Tag: tag.Tag}, {$set: tag}, function() {
|
||||
callback && callback();
|
||||
});
|
||||
},
|
||||
|
||||
// 服务器上更新过来, 已经存在了
|
||||
setNotDirty: function(title) {
|
||||
var me = this;
|
||||
|
Reference in New Issue
Block a user