mirror of
https://github.com/leanote/desktop-app.git
synced 2025-12-22 01:07:19 +08:00
syncContent, images, attach [ok]
This commit is contained in:
78
node_modules/note.js
generated
vendored
78
node_modules/note.js
generated
vendored
@@ -313,9 +313,15 @@ var Note = {
|
||||
|
||||
// 得到笔记内容
|
||||
// noteId是本地Id
|
||||
inSyncContent: {}, // 正在同步中的
|
||||
getNoteContent: function(noteId, callback) {
|
||||
var me = this;
|
||||
log('getNoteContent------')
|
||||
// 如果是正在sync的话, 返回
|
||||
if(me.inSyncContent[noteId]) {
|
||||
return;
|
||||
}
|
||||
me.inSyncContent[noteId] = true;
|
||||
me.getNote(noteId, function(note) {
|
||||
if(!Common.isOk(note)) {
|
||||
log('not ok');
|
||||
@@ -333,10 +339,12 @@ var Note = {
|
||||
// 远程获取
|
||||
me.getServerNoteIdByNoteId(noteId, function(serverNoteId) {
|
||||
if(!serverNoteId) {
|
||||
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) {
|
||||
@@ -351,6 +359,7 @@ var Note = {
|
||||
|
||||
});
|
||||
} else {
|
||||
me.inSyncContent[noteId] = false;
|
||||
log('not need');
|
||||
callback && callback(note);
|
||||
}
|
||||
@@ -441,13 +450,14 @@ var Note = {
|
||||
callback && callback(false);
|
||||
} else {
|
||||
callback && callback(newDoc);
|
||||
|
||||
// 下载内容, 图片, 附件
|
||||
me.syncContentAndImagesAndAttachs(newDoc);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
|
||||
// sync <- 时
|
||||
// 更新笔记, 合并之, 内容要重新获取
|
||||
// note是服务器传过来的, 需要处理下fix
|
||||
@@ -519,7 +529,6 @@ var Note = {
|
||||
// console.log('evernote');
|
||||
// console.log(everNote);
|
||||
|
||||
|
||||
// 得到本地笔记本Id
|
||||
Notebook.getNotebookIdByServerNotebookId(note.NotebookId, function(localNotebookId) {
|
||||
note['NotebookId'] = localNotebookId;
|
||||
@@ -537,6 +546,9 @@ var Note = {
|
||||
} else {
|
||||
log('强制更新...');
|
||||
callback && callback(note);
|
||||
|
||||
// 下载内容, 图片, 附件
|
||||
me.syncContentAndImagesAndAttachs(note);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -607,8 +619,6 @@ var Note = {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
|
||||
// 服务器上的数据
|
||||
@@ -1086,6 +1096,62 @@ var Note = {
|
||||
}
|
||||
},
|
||||
|
||||
// 同步内容, 图片, 附件
|
||||
// 异步操作
|
||||
syncContentAndImagesAndAttachs: function(note) {
|
||||
var me = this;
|
||||
// 内容
|
||||
console.log("syncContentAndImagesAndAttachs..................." + note.NoteId);
|
||||
me.getNoteContent(note.NoteId, function(noteAndContent) {
|
||||
if(noteAndContent) {
|
||||
console.log('sync content ' + note.NoteId + ' ok');
|
||||
var content = noteAndContent.Content;
|
||||
Web.contentSynced(note.NoteId, note.Content);
|
||||
// 图片
|
||||
if(content) {
|
||||
me.syncImages(content);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 附件
|
||||
var attachs = note.Attachs || [];
|
||||
for(var i in attachs) {
|
||||
var attach = attachs[i];
|
||||
me.downloadAttachFromServer(note.NoteId, attach.ServerFileId, attach.FileId);
|
||||
}
|
||||
},
|
||||
|
||||
// 同步图片
|
||||
inSyncImage: {}, //
|
||||
syncImages: function(content) {
|
||||
var me = this;
|
||||
if(!content) {
|
||||
return;
|
||||
}
|
||||
console.log('syncImages..................');
|
||||
console.log(content);
|
||||
// 得到图片id
|
||||
var reg = new RegExp(Evt.localUrl + "/api/file/getImage\\?fileId=(.{24})\"", 'g');
|
||||
// var a = 'abdfileId="xxx" alksdjfasdffileId="life"';
|
||||
// var reg = /fileId="(.+?)"/g;
|
||||
var s;
|
||||
// console.log(reg);
|
||||
while(s = reg.exec(content)) {
|
||||
// console.log(s);
|
||||
if(s && s.length >= 2) {
|
||||
var fileId = s[1];
|
||||
console.log('sync image: ' + fileId);
|
||||
if(!me.inSyncImage[fileId]) {
|
||||
me.inSyncImage[fileId] = true;
|
||||
File.getImage(fileId, function() {
|
||||
me.inSyncImage[fileId] = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
1) sync时判断是否有attach, 如果有, 则异步下载之
|
||||
2) 前端render note时, 判断是否有未Path的attach, 调用该服务
|
||||
@@ -1095,7 +1161,7 @@ var Note = {
|
||||
downloaded: {}, // 下载完成的
|
||||
downloadAttachFromServer: function(noteId, serverFileId, fileId) {
|
||||
var me = this;
|
||||
if(me.inDownload[serverFileId]) {
|
||||
if(me.inDownload[serverFileId] || me.downloaded[serverFileId]) {
|
||||
return;
|
||||
}
|
||||
if(!Api) {
|
||||
|
||||
Reference in New Issue
Block a user