写作模式, sync问题

This commit is contained in:
life
2015-03-08 01:52:30 +08:00
parent 4a48b11a10
commit 49bec63ded
20 changed files with 522 additions and 7318 deletions

2
node_modules/api.js generated vendored
View File

@@ -226,7 +226,7 @@ var Api = {
getNoteContent: function(noteId, callback) {
var me = this;
var url = this.getUrl('note/getNoteContent', {noteId: noteId});
log(url);
console.log(url);
needle.get(url, function(error, response) {
me.checkError(error, response);
if(error) {

12
node_modules/file.js generated vendored
View File

@@ -258,16 +258,16 @@ var File = {
// 访问api, 得到图片
function getImageFromApi() {
log('从远程得到图片 ' + fileId);
console.log('fetch servers image ' + fileId);
Api.getImage(fileId, function(fileLocalPath, filename) {
if(fileLocalPath) {
log('图片保存到本地成功');
console.log('save image to local');
// 保存到本地数据库中
me.addImageForce(fileId, fileLocalPath, function(doc) {
if(doc) {
log('保存到本地数据库成功');
console.log('save image to local success');
} else {
log('保存到数据库失败');
console.log('save image to local error');
}
callback(fileLocalPath);
// return me.retImage(fileLocalPath, res);
@@ -275,7 +275,7 @@ var File = {
} else {
// 远程取不到图片, 是没有网络? 还是远程真的没有了
// TODO
log('取不远程的图片' + fileId);
console.log("cann't get server's image" + fileId);
callback(false);
// return me.e404(res);
}
@@ -285,7 +285,7 @@ var File = {
// has表示本地数据库有记录
me.getImageLocalPath(fileId, function(has, fileLocalPath) {
// 本地有
log('re img')
console.log('re img')
console.log(fileLocalPath);
// console.log(fs.exists(fileLocalPath));
if(has && fileLocalPath) {

43
node_modules/note.js generated vendored
View File

@@ -429,37 +429,52 @@ var Note = {
// 得到笔记内容
// noteId是本地Id
inSyncContent: {}, // 正在同步中的
inSyncTimes: {}, // 10次就要再尝试了
getNoteContent: function(noteId, callback) {
var me = this;
console.log('getNoteContent------')
console.log('getNoteContent------' + noteId);
// 如果是正在sync的话, 返回
/*
if(me.inSyncContent[noteId]) {
console.log('in sync now' + noteId); // 下周分享 node-webkit
return;
}
*/
me.inSyncContent[noteId] = true;
me.inSyncTimes[noteId]++;
if(me.inSyncTimes[noteId] > 10) {
callback && callback(false);
}
me.getNote(noteId, function(note) {
if(!Common.isOk(note)) {
log('not ok');
log(note);
me.inSyncContent[noteId] = false;
console.log('not ok');
console.log(note);
callback && callback(false);
} else {
// 如果笔记是刚同步过来的, 那么内容要重新获取
if(note.InitSync) {
log('need load from server');
console.log('need load from server');
if(!Api) {
Api = require('api')
}
var serverNoteId = note.ServerNoteId;
// 远程获取
me.getServerNoteIdByNoteId(noteId, function(serverNoteId) {
// me.getServerNoteIdByNoteId(noteId, function(serverNoteId) {
if(!serverNoteId) {
console.error(noteId + ' getServerNoteIdByNoteId error');
me.inSyncContent[noteId] = false;
return callback && callback(false);
}
Api.getNoteContent(serverNoteId, function(noteContent) {
me.inSyncContent[noteId] = false;
// 同步到本地
if(Common.isOk(noteContent)) {
me.updateNoteContentForce(noteId, noteContent.Content, function(content) {
@@ -468,15 +483,25 @@ var Note = {
callback && callback(noteContent);
});
} else {
callback && callback(false);
console.error(noteId + ' api.getNoteContent error');
// 这里, 可能太多的要同步了
setTimeout(function() {
me.getNoteContent(noteId, callback);
}, 500);
// callback && callback(false);
}
});
});
// });
} else {
me.inSyncContent[noteId] = false;
log('not need');
console.log('not need');
callback && callback(note);
// Web.alertWeb("NONO");
}
}
});
@@ -1266,6 +1291,8 @@ var Note = {
if(content) {
me.syncImages(content);
}
} else {
// Web.alertWeb(note.NoteId + ' ' + note.Title + ' getContent error!!');
}
});

6
node_modules/sync.js generated vendored
View File

@@ -36,17 +36,17 @@ var Sync = {
_syncNotebookIsLastChunk: false,
_totalSyncNotebookNum: 0, // 需要同步的数量
_tocalHasSyncNotebookNum: 0, // 已同步的数量
_notebookMaxEntry: 1,
_notebookMaxEntry: 200,
// note
_syncNoteIsLastChunk: false,
_totalSyncNoteNum: 0, // 需要同步的数量
_noteMaxEntry: 1,
_noteMaxEntry: 200,
// tag
_syncTagIsLastChunk: false,
_totalSyncTagNum: 0, // 需要同步的数量
_tagMaxEntry: 1,
_tagMaxEntry: 200,
_initSyncInfo: function() {
var me = this;

4
node_modules/web.js generated vendored
View File

@@ -20,6 +20,10 @@ var Web = {
me.Note.notLogin();
},
alertWeb: function(msg) {
var me = this;
me.Note.alertWeb(msg);
},
// 注入前端变量
set: function(notebook, note, attach, tag) {