mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-16 16:04:56 +00:00
sync
This commit is contained in:
5
node_modules/api.js
generated
vendored
5
node_modules/api.js
generated
vendored
@@ -466,7 +466,7 @@ var Api = {
|
||||
// noteId是serverNoteId
|
||||
getNote: function(noteId, callback) {
|
||||
var me = this;
|
||||
needle.get(this.getUrl('note/getNote', {NoteId: noteId}), function(error, response) {
|
||||
needle.get(me.getUrl('note/getNote', {noteId: noteId}), function(error, response) {
|
||||
me.checkError(error, response);
|
||||
if(error) {
|
||||
return callback && callback(false);
|
||||
@@ -475,7 +475,8 @@ var Api = {
|
||||
if(Common.isOk(ret)) {
|
||||
callback && callback(ret);
|
||||
} else {
|
||||
log(error);
|
||||
console.error(error);
|
||||
console.log(me.getUrl('note/getNote', {noteId: noteId}));
|
||||
callback && callback(false);
|
||||
}
|
||||
});
|
||||
|
10
node_modules/db.js
generated
vendored
10
node_modules/db.js
generated
vendored
@@ -6,8 +6,14 @@ var Evt = require('evt');
|
||||
// var dbPath = require('nw.gui').App.dataPath + '/nedb';
|
||||
// var dbPath = Evt.getBasePath() + '/Users/life/Library/Application Support/Leanote' + '/nedb';
|
||||
var dbPath = Evt.getBasePath() + '/nedb';
|
||||
console.log(",,,,,,,,,,,,,");
|
||||
console.log(dbPath);
|
||||
|
||||
// test
|
||||
if(dbPath.length < 6) {
|
||||
var dbPath = '/Users/life/Library/Application Support/Leanote' + '/nedb';
|
||||
}
|
||||
|
||||
// console.log(",,,,,,,,,,,,,");
|
||||
// console.log(dbPath);
|
||||
var db = {};
|
||||
var dbNames = ['notebooks', 'notes', 'users', 'tags', 'images', 'attachs', 'noteHistories'];
|
||||
for(var i in dbNames) {
|
||||
|
74
node_modules/note.js
generated
vendored
74
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: ' + noteOrContent.NoteId);
|
||||
console.log('updateNoteOrContent: ');
|
||||
console.log(noteOrContent);
|
||||
var date = new Date();
|
||||
noteOrContent.UpdatedTime = date;
|
||||
|
||||
@@ -394,7 +395,7 @@ var Note = {
|
||||
inSyncContent: {}, // 正在同步中的
|
||||
getNoteContent: function(noteId, callback) {
|
||||
var me = this;
|
||||
log('getNoteContent------')
|
||||
console.log('getNoteContent------')
|
||||
// 如果是正在sync的话, 返回
|
||||
if(me.inSyncContent[noteId]) {
|
||||
return;
|
||||
@@ -620,10 +621,10 @@ var Note = {
|
||||
console.log(err);
|
||||
console.log(cnt);
|
||||
if(err) {
|
||||
console.log(err);
|
||||
console.error(err);
|
||||
callback && callback(false);
|
||||
} else {
|
||||
log('强制更新...');
|
||||
console.log('强制更新...');
|
||||
callback && callback(note);
|
||||
|
||||
// 下载内容, 图片, 附件
|
||||
@@ -875,8 +876,8 @@ var Note = {
|
||||
var me = this;
|
||||
|
||||
var conflictNotes = noteSyncInfo.conflicts;
|
||||
log('fix note conflicts');
|
||||
log(conflictNotes);
|
||||
console.log('fix note conflicts');
|
||||
console.log(conflictNotes);
|
||||
// 这里为什么要同步? 因为fixConflicts后要进行send changes, 这些有冲突的不能发送changes
|
||||
if(conflictNotes) {
|
||||
async.eachSeries(conflictNotes, function(note, cb) { // note是服务器上最新的, note.NoteId, ServerNoteId已转换
|
||||
@@ -911,35 +912,43 @@ var Note = {
|
||||
console.log('changeConflicts');
|
||||
console.log(changeConflicts);
|
||||
for(var i in changeConflicts) {
|
||||
var note = changeConflicts[i]; // note是本地的note
|
||||
// 复制一份
|
||||
me.copyNoteForConfict(note.NoteId, function(newNote) {
|
||||
if(newNote) {
|
||||
// 更新之前的, 要先从服务器上得到服务版的
|
||||
// 这里的note是本地的, 所以将服务器上的覆盖它
|
||||
if(!Api) {
|
||||
Api = require('api');
|
||||
}
|
||||
Api.getNote(note.ServerNoteId, function(serverNote) {
|
||||
serverNote.ServerNoteId = serverNote.NoteId;
|
||||
serverNote.NoteId = note.NoteId;
|
||||
me.updateNoteForceForConflict(serverNote, function(note2) {
|
||||
if(!note2) {
|
||||
// 前端来处理, 全量sync时不用前端一个个处理
|
||||
Web.fixSyncConflict(note2, newNote);
|
||||
}
|
||||
(function(i) {
|
||||
|
||||
var note = changeConflicts[i]; // note是本地的note
|
||||
// 复制一份
|
||||
me.copyNoteForConfict(note.NoteId, function(newNote) {
|
||||
if(newNote) {
|
||||
// 更新之前的, 要先从服务器上得到服务版的
|
||||
// 这里的note是本地的, 所以将服务器上的覆盖它
|
||||
if(!Api) {
|
||||
Api = require('api');
|
||||
}
|
||||
Api.getNote(note.ServerNoteId, function(serverNote) {
|
||||
serverNote.ServerNoteId = serverNote.NoteId;
|
||||
serverNote.NoteId = note.NoteId;
|
||||
console.error("changeConflicts -> get note from server");
|
||||
console.log(serverNote);
|
||||
console.log(note);
|
||||
me.updateNoteForceForConflict(serverNote, function(note2) {
|
||||
if(!note2) {
|
||||
// 前端来处理, 全量sync时不用前端一个个处理
|
||||
Web.fixSyncConflict(note2, newNote);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
}
|
||||
});
|
||||
|
||||
})(i);
|
||||
|
||||
}
|
||||
|
||||
// 服务器没有, 但是是发送更新的, 所以需要作为添加以后再send changes
|
||||
if(noteSyncInfo.changeNeedAdds) {
|
||||
var needAddNotes = noteSyncInfo.changeNeedAdds;
|
||||
for(var i in needAddNotes) {
|
||||
log('need add ');
|
||||
console.log('need add ');
|
||||
var note = needAddNotes[i];
|
||||
me.setIsNew(note.NoteId);
|
||||
}
|
||||
@@ -947,13 +956,12 @@ var Note = {
|
||||
|
||||
// 处理添加的
|
||||
var addNotes = noteSyncInfo.adds;
|
||||
log('has add...');
|
||||
log(addNotes);
|
||||
console.log('has add...');
|
||||
console.log(addNotes);
|
||||
Web.addSyncNote(addNotes);
|
||||
|
||||
log('has updates...');
|
||||
log(noteSyncInfo);
|
||||
log(noteSyncInfo.updates);
|
||||
console.log('has updates...');
|
||||
console.log(noteSyncInfo.updates);
|
||||
// 处理更新的
|
||||
Web.updateSyncNote(noteSyncInfo.updates);
|
||||
|
||||
|
23
node_modules/sync.js
generated
vendored
23
node_modules/sync.js
generated
vendored
@@ -557,7 +557,7 @@ var Sync = {
|
||||
User.getLastSyncState(function(lastSyncUsn, lastSyncTime) {
|
||||
// 没有上次同步的时间, 则需要进行一次全量同步, 不可能会发生
|
||||
if(!lastSyncUsn) {
|
||||
console.log('error!!');
|
||||
console.error('getLastSyncState error!!');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -575,7 +575,7 @@ var Sync = {
|
||||
// 更新上次同步时间
|
||||
me.updateLastSyncState(function() {
|
||||
// send changes
|
||||
me.sendChanges();
|
||||
me.sendChanges(again);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
@@ -675,6 +675,8 @@ var Sync = {
|
||||
if(User.getLastSyncUsn() > usn) { // 添加标签时如果标签已经存在, 则返回的是旧的
|
||||
return;
|
||||
}
|
||||
console.error('---?? checkNeedIncSyncAgain ??------' + usn)
|
||||
console.trace();
|
||||
me._needIncrSyncAgain = true;
|
||||
}
|
||||
}
|
||||
@@ -707,6 +709,7 @@ var Sync = {
|
||||
|
||||
Note.updateNoteForceForSendChange(newNote, true);
|
||||
|
||||
// 这里
|
||||
me.checkNeedIncSyncAgain(newNote.Usn);
|
||||
|
||||
cb();
|
||||
@@ -840,10 +843,16 @@ var Sync = {
|
||||
});
|
||||
},
|
||||
|
||||
sendChanges: function() {
|
||||
// again, 再一次sync, 不要send changes
|
||||
sendChanges: function(again) {
|
||||
var me = this;
|
||||
console.log('send changes before...')
|
||||
// 先处理冲突, 可以同时进行
|
||||
if(again) {
|
||||
console.error('send changes again....');
|
||||
me.fixConflictsForSendChanges(function(){});
|
||||
return;
|
||||
}
|
||||
me.fixConflicts(function() {
|
||||
// send changes
|
||||
console.log('send changes');
|
||||
@@ -862,10 +871,14 @@ var Sync = {
|
||||
// 重新再来一次增量同步
|
||||
if(me._needIncrSyncAgain) {
|
||||
console.error('-- _needIncrSyncAgain -- ')
|
||||
me.incrSync(true);
|
||||
console.log('send changes 后解决冲突, 先fix, 再incSync again');
|
||||
me.fixConflictsForSendChanges(function(){
|
||||
me.incrSync(true);
|
||||
});
|
||||
} else {
|
||||
console.log('send changes 后解决冲突');
|
||||
me.fixConflictsForSendChanges(function(){});
|
||||
me.fixConflictsForSendChanges(function(){
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
4
node_modules/user.js
generated
vendored
4
node_modules/user.js
generated
vendored
@@ -27,6 +27,7 @@ User = {
|
||||
LastSyncTime: null,
|
||||
// 登录后保存当前
|
||||
setCurUser: function(user) {
|
||||
var me = this;
|
||||
if(user) {
|
||||
this.token = user.Token;
|
||||
this.userId = user.UserId;
|
||||
@@ -175,9 +176,10 @@ User = {
|
||||
if(!Api) {
|
||||
Api = require('api');
|
||||
}
|
||||
log('--updateLastSyncState---')
|
||||
Api.getLastSyncState(function(state) {
|
||||
if(state) {
|
||||
console.error('--updateLastSyncState---')
|
||||
console.log(state);
|
||||
me.LastSyncUsn = state.LastSyncUsn;
|
||||
me.LastSyncTime = state.LastSyncTime;
|
||||
db.users.update({UserId: me.getCurActiveUserId()}, {$set: state});
|
||||
|
Reference in New Issue
Block a user