sync前保存

This commit is contained in:
life
2015-05-02 23:01:10 +08:00
parent 5b598ba13a
commit f3e02ac20e
5 changed files with 67 additions and 34 deletions

7
src/node_modules/api.js generated vendored
View File

@@ -157,6 +157,7 @@ var Api = {
getSyncNotebooks: function(afterUsn, maxEntry, callback) {
var me = this;
var url = this.getUrl('notebook/getSyncNotebooks', {afterUsn: afterUsn, maxEntry: maxEntry});
// console.log(url);
needle.get(url,
function(error, response) {
me.checkError(error, response);
@@ -215,17 +216,15 @@ var Api = {
},
getLastSyncState: function(callback) {
var me = this;
log('--getSyncState--')
var url = this.getUrl('user/getSyncState');
log(url);
needle.get(url, function(error, response) {
me.checkError(error, response);
if(error) {
return callback && callback(false);
}
var ret = response.body;
log('--getSyncState--ret---')
log(ret);
console.log('--getSyncState--ret---')
console.log(ret);
if(Common.isOk(ret)) {
callback && callback(ret);
} else {

61
src/node_modules/sync.js generated vendored
View File

@@ -622,36 +622,57 @@ var Sync = {
// 没有上次同步的时间, 则需要进行一次全量同步, 不可能会发生
if(!lastSyncUsn) {
console.error('getLastSyncState error!!');
me.setSyncFinished();
return;
}
// 同步笔记本
me.syncNotebook(lastSyncUsn, function(ok) {
if(ok) {
console.log('-------incr notebook ok-----------' + lastSyncUsn);
me.addSyncProcessStatus(10);
// 同步笔记
me.syncNote(lastSyncUsn, function(ok) {
// 先从服务器上得到usn, 与本地的判断, 是否需要pull
console.log('先从服务器上得到usn, 与本地的判断, 是否需要pull');
Api.getLastSyncState(function(serverState) {
if(!serverState) {
console.error('get Server LastSyncState error!!');
me.setSyncFinished();
return;
}
console.log(serverState.LastSyncUsn + ' ' + lastSyncUsn);
if(serverState.LastSyncUsn > lastSyncUsn) {
// 需要同步笔记本
console.log('需要pull');
// 同步笔记本
me.syncNotebook(lastSyncUsn, function(ok) {
if(ok) {
console.log('-------incr note ok-----------' + lastSyncUsn);
me.addSyncProcessStatus(30);
// 同步标签
me.syncTag(lastSyncUsn, function() {
console.log('-------incr tag ok-----------' + lastSyncUsn);
me.addSyncProcessStatus(10);
// 更新上次同步时间
me.updateLastSyncState(function() {
// send changes
me.sendChanges(again);
});
console.log('-------incr notebook ok-----------' + lastSyncUsn);
me.addSyncProcessStatus(10);
// 同步笔记
me.syncNote(lastSyncUsn, function(ok) {
if(ok) {
console.log('-------incr note ok-----------' + lastSyncUsn);
me.addSyncProcessStatus(30);
// 同步标签
me.syncTag(lastSyncUsn, function() {
console.log('-------incr tag ok-----------' + lastSyncUsn);
me.addSyncProcessStatus(10);
// 更新上次同步时间
me.updateLastSyncState(function() {
// send changes
me.sendChanges(again);
});
});
} else {
console.log('-------incr note not ok-----------')
me.fixConflicts();
}
});
} else {
console.log('-------incr note not ok-----------')
me.fixConflicts();
}
});
} else {
me.fixConflicts();
console.log('不需要pull');
me.addSyncProcessStatus(50);
me.sendChanges(again);
}
});
});