mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-17 00:15:12 +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});
|
||||
|
31
note.html
31
note.html
@@ -805,22 +805,29 @@ window.require = undefined;
|
||||
initPage();
|
||||
</script>
|
||||
|
||||
<!-- v2 use require.js, mdeditor -->
|
||||
<script>
|
||||
window.require = window.requireNode;
|
||||
/*
|
||||
window.baseDir = 'public/dist';
|
||||
window.require = {
|
||||
baseUrl: window.baseDir,
|
||||
};
|
||||
*/
|
||||
</script>
|
||||
<script src="public/tinymce/plugins/leaui_image/public/js/jquery.ui.widget.js"></script>
|
||||
<script src="public/tinymce/plugins/leaui_image/public/js/jquery.fileupload.js"></script>
|
||||
<script src="public/tinymce/plugins/leaui_image/public/js/jquery.iframe-transport.js"></script>
|
||||
<!-- <script src="public/js/app/paste.js"></script> -->
|
||||
|
||||
<!-- <script src="public/js/require.js"></script> -->
|
||||
<!-- <script src="public/js/main.js"></script> -->
|
||||
<!-- v2 use require.js, mdeditor -->
|
||||
<script>
|
||||
// window.require = undefined;
|
||||
|
||||
window.baseDir = 'public/dist';
|
||||
window.require = {
|
||||
baseUrl: window.baseDir,
|
||||
};
|
||||
</script>
|
||||
<script src="public/dist/require.js"></script>
|
||||
<script>
|
||||
// alert(define);
|
||||
// alert(require);
|
||||
</script>
|
||||
<script src="public/dist/main.js"></script>
|
||||
|
||||
<script>
|
||||
window.require = window.requireNode;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
43193
public/dist/main.js
vendored
43193
public/dist/main.js
vendored
File diff suppressed because one or more lines are too long
21
public/dist/main.min.js
vendored
Normal file
21
public/dist/main.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2084
public/dist/require.js
vendored
Normal file
2084
public/dist/require.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -280,8 +280,8 @@ Note.curHasChanged = function(force) {
|
||||
hasChanged.Abstract = Note.genAbstract(c);
|
||||
}
|
||||
} else {
|
||||
log("text相同");
|
||||
log(cacheNote.Content == content);
|
||||
console.log("text相同");
|
||||
console.log(cacheNote.Content == content);
|
||||
}
|
||||
|
||||
hasChanged["UserId"] = cacheNote["UserId"] || "";
|
||||
@@ -374,21 +374,24 @@ Note.genAbstract = function(content, len) {
|
||||
var d = document.createElement("div");
|
||||
d.innerHTML = result
|
||||
return d.innerHTML;
|
||||
}
|
||||
};
|
||||
|
||||
Note.getImgSrc = function(content) {
|
||||
if(!content) {
|
||||
return "";
|
||||
}
|
||||
var imgs = $(content).find("img");
|
||||
for(var i in imgs) {
|
||||
var src = imgs.eq(i).attr("src");
|
||||
if(src) {
|
||||
return src;
|
||||
try {
|
||||
var imgs = $(content).find("img");
|
||||
for(var i in imgs) {
|
||||
var src = imgs.eq(i).attr("src");
|
||||
if(src) {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
// 如果当前的改变了, 就保存它
|
||||
// 以后要定时调用
|
||||
@@ -432,7 +435,7 @@ Note.curChangedSaveIt = function(force, callback) {
|
||||
|
||||
me.saveInProcess[hasChanged.NoteId] = true;
|
||||
|
||||
Service.noteService.updateNoteOrContent(hasChanged, function(ret) {
|
||||
NoteService.updateNoteOrContent(hasChanged, function(ret) {
|
||||
me.saveInProcess[hasChanged.NoteId] = false;
|
||||
if(hasChanged.IsNew) {
|
||||
// 缓存之, 后台得到其它信息
|
||||
@@ -527,7 +530,7 @@ Note.directToNote = function(noteId) {
|
||||
// 手机不用slimScroll
|
||||
if(!LEA.isMobile && !Mobile.isMobile()) {
|
||||
$("#noteItemList").scrollTop(top);
|
||||
$("#noteItemList").slimScroll({ scrollTo: top + 'px', height: "100%", onlyScrollBar: true});
|
||||
// $("#noteItemList").slimScroll({ scrollTo: top + 'px', height: "100%", onlyScrollBar: true});
|
||||
} else {
|
||||
}
|
||||
}
|
||||
@@ -672,6 +675,10 @@ Note.changeNote = function(selectNoteId, isShare, needSaveChanged, callback) {
|
||||
}
|
||||
|
||||
self.showContentLoading();
|
||||
|
||||
console.error('chage note..........');
|
||||
console.trace();
|
||||
|
||||
Service.noteService.getNoteContent(cacheNote.NoteId, setContent); // ajaxGet(url, param, setContent);
|
||||
}
|
||||
|
||||
@@ -746,6 +753,7 @@ Note.clearAll = function() {
|
||||
// render到编辑器
|
||||
// render note
|
||||
Note.renderNote = function(note) {
|
||||
|
||||
if(!note) {
|
||||
return;
|
||||
}
|
||||
@@ -762,6 +770,8 @@ Note.renderNote = function(note) {
|
||||
|
||||
// render content
|
||||
Note.renderNoteContent = function(content) {
|
||||
console.error('---------------- note:' + note.Title);
|
||||
console.trace();
|
||||
setEditorContent(content.Content, content.IsMarkdown, content.Preview);
|
||||
|
||||
// 只有在renderNoteContent时才设置curNoteId
|
||||
@@ -1690,8 +1700,9 @@ Note._initshowConflictInfo = function() {
|
||||
// console.log(me._curFixNoteTarget);
|
||||
// console.log(target);
|
||||
|
||||
// target.insertBefore(me._curFixNoteTarget);
|
||||
me._curFixNoteTarget.insertBefore(target);
|
||||
target.insertAfter(me._curFixNoteTarget);
|
||||
// alert(3);
|
||||
// me._curFixNoteTarget.insertBefore(target);
|
||||
// 选中与之冲突的笔记
|
||||
me.changeNote(conflictNoteId);
|
||||
});
|
||||
@@ -2390,20 +2401,18 @@ Note.addSync = function(notes) {
|
||||
}
|
||||
// 更新
|
||||
Note.updateSync = function(notes) {
|
||||
log("??")
|
||||
if(isEmpty(notes)) {
|
||||
return;
|
||||
}
|
||||
log("what?")
|
||||
for(var i in notes) {
|
||||
var note = notes[i];
|
||||
note.InitSync = true; // 需要重新获取内容
|
||||
Note.addNoteCache(note);
|
||||
// 如果当前修改的是本笔记, 那么重新render之
|
||||
log('->>>')
|
||||
log(Note.curNoteId);
|
||||
console.log('->>>');
|
||||
console.log(Note.curNoteId);
|
||||
if(Note.curNoteId == note.NoteId) {
|
||||
log('yes---');
|
||||
console.log('yes---');
|
||||
Note.changeNote(Note.curNoteId);
|
||||
}
|
||||
}
|
||||
|
@@ -1303,7 +1303,7 @@ function fullSync(callback) {
|
||||
// 增量同步
|
||||
function incrSync() {
|
||||
log('incr sync');
|
||||
SyncService.incrSync(Notebook, Note);
|
||||
SyncService.incrSync();
|
||||
}
|
||||
|
||||
// note.html调用
|
||||
|
21
test.js
21
test.js
@@ -19,25 +19,30 @@ Api.addNotebook({
|
||||
// Api.uploadImage();
|
||||
User.userId = '54bdc65599c37b0da9000002';
|
||||
User.userId = '54d7620d99c37b030600002c';
|
||||
User.userId = '54db772899c37b1a6c000135';
|
||||
User.userId = '54d7620d99c37b030600002c';
|
||||
|
||||
/*
|
||||
User.init(function() {
|
||||
Api.getAttach('54d8c8de99c37b02fa000002', function() {
|
||||
});
|
||||
Note.getNote('54e16d90c596f238dc000001', function(note) {
|
||||
Note.getNote('54d76aeec596f27b0b000000', function(note) {
|
||||
console.log(note);
|
||||
console.log(note.NotebookId);
|
||||
/*
|
||||
Notebook.getNotebook(note.NotebookId, function(notebook) {
|
||||
console.log(notebook);
|
||||
});
|
||||
})
|
||||
*/
|
||||
});
|
||||
|
||||
});
|
||||
/*
|
||||
Note.getDirtyNotes(function(ret) {
|
||||
// console.log(ret);
|
||||
});
|
||||
*/
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
Api.auth('e@a.com', 'abc123');
|
||||
User.getAllUsers();
|
||||
*/
|
||||
|
||||
/*
|
||||
Note.hasNotes('54bdc65599c37b0da9000005', function(doc) {
|
||||
|
Reference in New Issue
Block a user