mirror of
https://github.com/leanote/desktop-app.git
synced 2025-12-21 01:07:43 +08:00
sync attach ok
This commit is contained in:
62
node_modules/note.js
generated
vendored
62
node_modules/note.js
generated
vendored
@@ -1086,6 +1086,68 @@ var Note = {
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
1) sync时判断是否有attach, 如果有, 则异步下载之
|
||||
2) 前端render note时, 判断是否有未Path的attach, 调用该服务
|
||||
从服务器端下载文件, 并通过到前端已下载完成
|
||||
*/
|
||||
inDownload: {}, // 正在下载的文件 fileId => true
|
||||
downloaded: {}, // 下载完成的
|
||||
downloadAttachFromServer: function(noteId, serverFileId, fileId) {
|
||||
var me = this;
|
||||
if(me.inDownload[serverFileId]) {
|
||||
return;
|
||||
}
|
||||
if(!Api) {
|
||||
Api = require('api');
|
||||
}
|
||||
|
||||
me.inDownload[serverFileId] = true;
|
||||
Api.getAttach(serverFileId, function(ok, toPath, filename) {
|
||||
me.inDownload[serverFileId] = false;
|
||||
if(ok) {
|
||||
me.downloaded[serverFileId] = fileId;
|
||||
// 更新serverFileId与fileId的映射, 修改的是note
|
||||
me.syncAttach(noteId, serverFileId, fileId, toPath, filename, function(ok, attachs, attach) {
|
||||
if(ok) {
|
||||
// 通知web
|
||||
Web.attachSynced(attachs, attach, noteId);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 下次再下载 ?
|
||||
// 或者放到一个队列中 ?
|
||||
// TODO
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 同步附件, 更新serverFileId
|
||||
syncAttach: function(noteId, serverFileId, fileId, path, filename, callback) {
|
||||
var me = this;
|
||||
me.getNote(noteId, function(note) {
|
||||
if(!note) {
|
||||
callback(false);
|
||||
}
|
||||
var attachs = note.Attachs;
|
||||
for(var i in attachs) {
|
||||
var attach = attachs[i];
|
||||
if(attach.FileId == fileId) {
|
||||
attach.ServerFileId = serverFileId;
|
||||
attach.Path = path;
|
||||
// attach.Title = filename;
|
||||
// attach.Filename = filename;
|
||||
|
||||
Notes.update({_id: note._id}, {$set: {Attachs: attachs}}, function() {
|
||||
callback(true, attachs, attach);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
callback(false);
|
||||
});
|
||||
},
|
||||
|
||||
// 根据标签得到笔记数量
|
||||
countNoteByTag: function(title, callback) {
|
||||
var userId = User.getCurActiveUserId();
|
||||
|
||||
Reference in New Issue
Block a user