mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-14 23:22:40 +00:00
大坑一个
This commit is contained in:
8
node_modules/common.js
generated
vendored
8
node_modules/common.js
generated
vendored
@@ -5,6 +5,14 @@ var ObjectId = require('objectid');
|
||||
|
||||
// var gui = require('nw.gui');
|
||||
// console.log(gui.App);
|
||||
//
|
||||
process.on('uncaughtException', function (err) {
|
||||
// 打印出错误
|
||||
console.log('~!!~ uncaughtException ~!!~');
|
||||
console.log(err);
|
||||
// 打印出错误的调用栈方便调试
|
||||
console.log(err.stack);
|
||||
});
|
||||
|
||||
function log(o) {console.log(o)}
|
||||
// log("<>>>>>>>>>>>>>>>>>>>>");
|
||||
|
91
node_modules/note.js
generated
vendored
91
node_modules/note.js
generated
vendored
@@ -371,24 +371,7 @@ var Note = {
|
||||
});
|
||||
},
|
||||
|
||||
// 删除附件
|
||||
deleteAttachs: function(attachs) {
|
||||
var me = this;
|
||||
var fileBasePath = User.getCurUserAttachsPath();
|
||||
if(!attachs) {
|
||||
return;
|
||||
}
|
||||
for(var i in attachs) {
|
||||
var path = attachs[i].Path;
|
||||
if(path && path.indexOf(fileBasePath) > 0) {
|
||||
try {
|
||||
fs.unlink(path);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// sync <- 时
|
||||
// 更新笔记, 合并之, 内容要重新获取
|
||||
@@ -879,10 +862,76 @@ var Note = {
|
||||
var me = this;
|
||||
console.log('updateAttach');
|
||||
console.log(attachs);
|
||||
Notes.update({NoteId: noteId}, {$set: {Attachs: attachs, IsDirty: true}});
|
||||
|
||||
// File, 删除修改了的
|
||||
File.deleteNotExistsAttach(noteId, attachs);
|
||||
// 删除修改了的
|
||||
me.deleteNotExistsAttach(noteId, attachs, function() {
|
||||
// 一个坑!!!!!!!!!!!, js是引用的, needb并不会立即写到硬盘上, 在内存中是一个引用
|
||||
var t = [];
|
||||
for(var i in attachs) {
|
||||
t.push(attachs[i]);
|
||||
}
|
||||
Notes.update({NoteId: noteId}, {$set: {Attachs: t, IsDirty: true, UpdatedTime: new Date()}} );
|
||||
});
|
||||
},
|
||||
|
||||
// web端操作, 删除attach时, 删除不要的attach
|
||||
deleteNotExistsAttach: function(noteId, attachs, callback) {
|
||||
var me = this;
|
||||
// console.log('--');
|
||||
me.getNote(noteId, function(note) {
|
||||
if(!note) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
var everAttachs = note.Attachs || [];
|
||||
var nowMap = {};
|
||||
for(var i in attachs) {
|
||||
nowMap[attachs[i].FileId] = attachs[i];
|
||||
}
|
||||
// console.log(note);
|
||||
// console.log('end');
|
||||
// console.log(everAttachs.length);
|
||||
// console.log(attachs.length);
|
||||
// console.log(attachs == everAttachs);
|
||||
var fileBasePath = User.getCurUserAttachsPath();
|
||||
for(var i in everAttachs) {
|
||||
var attach = everAttachs[i];
|
||||
var path = attach.Path;
|
||||
if(!nowMap[attach.FileId]) { // 如果不在, 则删除之
|
||||
// console.log(">>>>>>>>>");
|
||||
try {
|
||||
// 删除源文件, 别删错了啊
|
||||
if(path.indexOf(fileBasePath) >= 0) {
|
||||
fs.unlink(path);
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 一个坑!!!!!!!!!!!
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
||||
// 删除附件, 在sync时
|
||||
deleteAttachs: function(attachs) {
|
||||
var me = this;
|
||||
var fileBasePath = User.getCurUserAttachsPath();
|
||||
if(!attachs) {
|
||||
return;
|
||||
}
|
||||
for(var i in attachs) {
|
||||
var path = attachs[i].Path;
|
||||
if(path && path.indexOf(fileBasePath) > 0) {
|
||||
try {
|
||||
fs.unlink(path);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
@@ -1725,7 +1725,7 @@ var Attach = {
|
||||
*/
|
||||
var html = "";
|
||||
var attachNum = attachs.length;
|
||||
console.log(attachs);
|
||||
// console.log(attachs);
|
||||
for(var i = 0; i < attachNum; ++i) {
|
||||
var each = attachs[i];
|
||||
var path = each.Path;
|
||||
|
4
test.js
4
test.js
@@ -13,12 +13,12 @@ Notebook.addNotebook("3", "工作");
|
||||
Notebook.addNotebook("4", "life2", "1");
|
||||
|
||||
Api.addNotebook({
|
||||
Title: "哈哈"
|
||||
Title: "哈哈"54ce31fa99c37b1d5c00057e
|
||||
}, function() {});
|
||||
*/
|
||||
// Api.uploadImage();
|
||||
User.userId = '54bdc65599c37b0da9000002';
|
||||
Note.getNoteByServerNoteId('54ce29b399c37b1d5c000479', function(doc) {
|
||||
Note.getNoteByServerNoteId('54ce32fc99c37b1d5c0005a4', function(doc) {
|
||||
console.log(doc);
|
||||
});
|
||||
/*
|
||||
|
Reference in New Issue
Block a user