This commit is contained in:
life
2017-01-19 11:35:51 +08:00
parent 097e4486a0
commit 2f615069c2
11 changed files with 341 additions and 183 deletions

67
node_modules/note.js generated vendored
View File

@@ -881,6 +881,8 @@ var Note = {
needReloadContent = true;
}
// console.log('...', JSON.stringify(note))
note.IsDirty = false;
note.InitSync = needReloadContent;
note.LocalIsNew = false;
@@ -939,6 +941,7 @@ var Note = {
allAttachs.push(everAttachsMap[serverFileId]);
}
}
// console.log('allAttachs', allAttachs);
note.Attachs = allAttachs;
note.ServerNoteId = note.NoteId;
@@ -964,14 +967,15 @@ var Note = {
delete note['CreatedTime'];
db.notes.update({NoteId: note.NoteId}, {$set: note}, {}, function (err, cnt) { // Callback is optional
console.log('re:');
console.log(err);
console.log(cnt);
// console.log('re:');
// console.log(err);
// console.log(cnt);
if(err) {
console.error(err);
callback && callback(false);
} else {
console.log('强制更新...');
console.log(' 强制更新本地笔记...', note.Title);
callback && callback(note);
/*
@@ -985,6 +989,8 @@ var Note = {
Notebook.reCountNotebookNumberNotes(note.NotebookId);
// 下载内容, 图片, 附件
// console.log('..', note)
// console.log(JSON.stringify(note), note.Attachs)
me.syncContentAndImagesAndAttachs(note);
}
});
@@ -1004,8 +1010,7 @@ var Note = {
// note.LocalIsDelete = false;
// note.UserId = User.getCurActiveUserId();
//
console.log("updateNoteForceForSendChange");
console.log(note);
// console.log(" updateNoteForceForSendChange", note);
// 如果是添加的, 因为不会传内容
// if(isAdd) {
@@ -1014,9 +1019,9 @@ var Note = {
delete note['NotebookId']; // 不要设置notebookId, 2/16 fixed
console.log('server data from::::');
console.log(note.NoteId);
console.log(note.Files);
// console.log('server data from::::');
// console.log(note.NoteId);
// console.log(note.Files);
// 修改Imags的LocalFileId <=> FileId的映射
File.updateImageForce(note.Files);
@@ -1033,7 +1038,7 @@ var Note = {
// 之前也是有attachs的, 得到之前的attachs, 进行个merge
me.getNote(note.NoteId, function(everNote) {
if(!everNote) {
console.log('我靠, 没有?' + note.NoteId);
console.log(' 没有?' + note.NoteId);
return;
}
var everAttachs = everNote.Attachs || [];
@@ -1045,8 +1050,7 @@ var Note = {
}
}
note.Attachs = everAttachs;
console.log('fix after');
console.log(everAttachs);
console.log(' fix after', everAttachs);
delete note['Files'];
delete note['UpdatedTime'];
@@ -1055,8 +1059,7 @@ var Note = {
// multi: true, 避免有历史的笔记有问题
db.notes.update({NoteId: note.NoteId}, {$set: note}, {multi: true}, function(err, n) {
if(err || !n) {
log('updateNoteForceForSendChange err');
log(err);
console.log(' updateNoteForceForSendChange err', err);
return callback && callback(false);
}
return callback && callback(true);
@@ -1118,8 +1121,8 @@ var Note = {
// 只复制有path的
var attachs = note.Attachs || [];
var newAttachs = [];
console.log('不会吧.............')
console.log(attachs);
// console.log('不会吧.............')
// console.log(attachs);
async.eachSeries(attachs, function(attach, cb) {
if(!attach.Path) {
return cb();
@@ -1128,8 +1131,7 @@ var Note = {
var filePathAttr = Common.splitFile(attach.Path);
filePathAttr.nameNotExt += '_cp_' + attach.FileId; // 另一个
var newPath = filePathAttr.getFullPath();
console.log('复制文件');
console.log(attach);
console.log(' 复制文件', attach);
// 复制之
// try {
Common.copyFile(attach.Path, newPath, function(ret) {
@@ -1149,8 +1151,7 @@ var Note = {
*/
}, function() {
note.Attachs = newAttachs;
console.log('conflict 复制后的');
console.log(note);
console.log(' conflict 复制后的', note);
db.notes.insert(note, function(err, newNote) {
if(err) {
callback(false);
@@ -1256,8 +1257,9 @@ var Note = {
var me = this;
var conflictNotes = noteSyncInfo.conflicts;
console.log('fix note conflicts');
console.log(conflictNotes);
if (!isEmpty(conflictNotes)) {
console.log(' fix note conflicts', conflictNotes);
}
// 这里为什么要同步? 因为fixConflicts后要进行send changes, 这些有冲突的不能发送changes
conflictNotes || (conflictNotes = []);
if(!Api) {
@@ -1327,8 +1329,15 @@ var Note = {
// 因为在处理冲突的时候有些成为更新了, 所以必须在此之后调用
// console.log('has updates...');
// console.log(noteSyncInfo.updates);
// 处理更新的
Web.updateSyncNote(noteSyncInfo.updates);
if (!Common.isEmpty(noteSyncInfo.updates)) {
Web.updateSyncNote(noteSyncInfo.updates);
}
if (!Common.isEmpty(noteSyncInfo.changeUpdates)) {
Web.updateChangeUpdates(noteSyncInfo.changeUpdates);
}
});
// 发送改变的冲突
@@ -1373,7 +1382,7 @@ var Note = {
if(noteSyncInfo.changeNeedAdds) {
var needAddNotes = noteSyncInfo.changeNeedAdds;
for(var i in needAddNotes) {
console.log('need add ');
console.log(' need add note');
var note = needAddNotes[i];
me.setIsNew(note.NoteId);
}
@@ -1381,9 +1390,10 @@ var Note = {
// 处理添加的
var addNotes = noteSyncInfo.adds;
console.log('has add...');
console.log(addNotes);
Web.addSyncNote(addNotes);
if (!isEmpty(addNotes)) {
console.log(' has add note...', addNotes);
Web.addSyncNote(addNotes);
}
// 处理删除的
Web.deleteSyncNote(noteSyncInfo.deletes);
@@ -1467,7 +1477,6 @@ var Note = {
});
});
}, function() {
console.log(notes);
callback(notes);
});
}
@@ -1659,7 +1668,7 @@ var Note = {
// 附件
var attachs = note.Attachs || [];
for(var i in attachs) {
for(var i = 0; i < attachs.length; ++i) {
var attach = attachs[i];
me.downloadAttachFromServer(note.NoteId, attach.ServerFileId, attach.FileId);
}