mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-16 08:01:53 +00:00
incr 同步完成, 待send changes
This commit is contained in:
81
node_modules/note.js
generated
vendored
81
node_modules/note.js
generated
vendored
@@ -80,6 +80,7 @@ var Note = {
|
||||
noteOrContent['ContentIsDirty'] = true;
|
||||
}
|
||||
if(needUpdate) {
|
||||
updates['IsDirty'] = true;
|
||||
updates.UpdatedTime = date;
|
||||
// Set an existing field's value
|
||||
Notes.update({NoteId: noteOrContent.NoteId}, { $set: updates }, {}, function (err, numReplaced) {
|
||||
@@ -144,18 +145,16 @@ var Note = {
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
|
||||
// 远程修改本地内容
|
||||
updateNoteContentForce: function(noteId, content, callback) {
|
||||
// <img src="http://localhost:9000/api/file/getImage?fileId=54c2083f99c37bea5f000001">
|
||||
// 改成<img src="http://localhost:3232/api/file/getImage?fileId=xxx"
|
||||
|
||||
var reg = new RegExp('<img *src="' + Api.leanoteUrl + '/api/file/getImage', 'g');
|
||||
content = content.replace(reg, '<img src="' + Server.localUrl + '/api/file/getImage');
|
||||
var reg = new RegExp('src="' + Api.leanoteUrl + '/api/file/getImage', 'g');
|
||||
content = content.replace(reg, 'src="' + Server.localUrl + '/api/file/getImage');
|
||||
|
||||
// log("----<>");
|
||||
// log(content);
|
||||
log("----<>");
|
||||
log(content);
|
||||
Notes.update({NoteId: noteId}, { $set: {Content: content, InitSync: false, IsContentDirty: false} }, {}, function (err, numReplaced) {
|
||||
if(err) {
|
||||
log(err);
|
||||
@@ -220,6 +219,8 @@ var Note = {
|
||||
//----------------
|
||||
|
||||
// 强制删除
|
||||
// TODO 是否真的删除 ?
|
||||
// 有可能服务器上删除了是误删 ?
|
||||
deleteNoteForce: function(noteId, callback) {
|
||||
var me = this;
|
||||
Notes.remove({NoteId: noteId}, function(err, n) {
|
||||
@@ -247,15 +248,81 @@ var Note = {
|
||||
updateNoteForce: function(note, callback) {
|
||||
note.IsDirty = false;
|
||||
note.InitSync = true;
|
||||
Notes.update({NoteId: note.NoteId}, {$set: note}, {}, function (err, updates) { // Callback is optional
|
||||
Notes.update({NoteId: note.NoteId}, {$set: note}, {}, function (err, cnt) { // Callback is optional
|
||||
if(err) {
|
||||
console.log(err);
|
||||
callback && callback(false);
|
||||
} else {
|
||||
log('强制更新...');
|
||||
callback && callback(note);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 将本地冲突的笔记复制一份
|
||||
copyNoteForConfict: function(noteId, callback) {
|
||||
var me = this;
|
||||
me.getNote(noteId, function(note) {
|
||||
if(!note) {
|
||||
return;
|
||||
}
|
||||
// 新Id
|
||||
delete note['_id'];
|
||||
note.NoteId = Common.objectId();
|
||||
note.ConflictNoteId = noteId; // 与noteId有冲突
|
||||
note.ConflictTime = new Date(); // 发生冲突时间
|
||||
note.ConflictFixed = false; // 冲突未解决
|
||||
note.IsDirty = true;
|
||||
note.LocalIsNew = true;
|
||||
note.InitSync = false; // 都是本地的, 相当于新建的笔记
|
||||
|
||||
Notes.insert(note, function(err, newNote) {
|
||||
if(err) {
|
||||
callback(false);
|
||||
} else {
|
||||
callback(newNote);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
// 处理冲突
|
||||
// notes是服务器的数据, 与本地的有冲突
|
||||
// 1) 将本地的note复制一份
|
||||
// 2) 服务器替换之前
|
||||
fixConflicts: function(noteSyncInfo, noteWeb) {
|
||||
var me = this;
|
||||
// 处理冲突
|
||||
var conflictNotes = noteSyncInfo.conflicts;
|
||||
for(var i in conflictNotes) {
|
||||
var note = conflictNotes[i];
|
||||
var noteId = note.NoteId;
|
||||
me.copyNoteForConfict(noteId, function(newNote) {
|
||||
if(newNote) {
|
||||
me.updateNoteForce(note, function() {
|
||||
// 前端来处理, 全量sync时不用前端一个个处理
|
||||
noteWeb.fixSyncConflict && noteWeb.fixSyncConflict(note, newNote);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 处理添加的
|
||||
var addNotes = noteSyncInfo.adds;
|
||||
log('has add...');
|
||||
log(addNotes);
|
||||
noteWeb && noteWeb.addSyncNotes(addNotes);
|
||||
|
||||
log('has updates...');
|
||||
log(noteSyncInfo);
|
||||
log(noteSyncInfo.updates);
|
||||
// 处理更新的
|
||||
noteWeb.updateSyncNotes(noteSyncInfo.updates);
|
||||
|
||||
// 处理删除的
|
||||
noteWeb.deleteSyncNotes(noteSyncInfo.deletes);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Note;
|
Reference in New Issue
Block a user