mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-15 07:31:33 +00:00
本地发送note带图片 ok
下一步, 修改笔记带图片
This commit is contained in:
32
node_modules/api.js
generated
vendored
32
node_modules/api.js
generated
vendored
@@ -350,35 +350,36 @@ var Api = {
|
|||||||
// note.NotebookId是本的, 要得到远程的
|
// note.NotebookId是本的, 要得到远程的
|
||||||
Notebook.getServerNotebookIdByNotebookId(note.NotebookId, function(serverNotebookId) {
|
Notebook.getServerNotebookIdByNotebookId(note.NotebookId, function(serverNotebookId) {
|
||||||
var data = {
|
var data = {
|
||||||
title: note.Title,
|
Title: note.Title,
|
||||||
notebookId: serverNotebookId,
|
NotebookId: serverNotebookId,
|
||||||
content: note.Content,
|
Content: note.Content,
|
||||||
isMarkdown: note.isMarkdown,
|
IsMarkdown: note.isMarkdown,
|
||||||
tags: note.Tags,
|
Tags: note.Tags,
|
||||||
isBlog: note.IsBlog,
|
IsBlog: note.IsBlog,
|
||||||
}
|
}
|
||||||
log('add note');
|
log('add note');
|
||||||
log(data);
|
// log(data);
|
||||||
|
|
||||||
// files处理
|
// files处理
|
||||||
var files = note.Files;
|
var files = note.Files;
|
||||||
var needTransferFiles = [];
|
var needTransferFiles = [];
|
||||||
var needPostFilesAttr = [];
|
var needPostFilesAttr = [];
|
||||||
async.eachSeries(files, function(file, cb) {
|
async.eachSeries(files, function(file, cb) {
|
||||||
var file = files[i];
|
// var file = files[i];
|
||||||
var needFile = {
|
var needFile = {
|
||||||
fileId: file.ServerFileId,
|
FileId: file.ServerFileId,
|
||||||
localFileId: file.FileId,
|
LocalFileId: file.FileId,
|
||||||
hasBody: false
|
HasBody: false
|
||||||
}
|
}
|
||||||
|
// console.log(file);
|
||||||
// 要传数据的
|
// 要传数据的
|
||||||
if(file.IsDirty) {
|
if(file.IsDirty) {
|
||||||
ifs.exists(file.Path, function(isExists) {
|
fs.exists(file.Path, function(isExists) {
|
||||||
needTransferFiles[file.ServerFileId] = {
|
needTransferFiles[file.FileId] = {
|
||||||
file: file.Path,
|
file: file.Path,
|
||||||
content_type: 'image/' + file.Type
|
content_type: 'image/' + file.Type
|
||||||
}
|
}
|
||||||
needFile.hasBody = true;
|
needFile.HasBody = true;
|
||||||
needPostFilesAttr.push(needFile);
|
needPostFilesAttr.push(needFile);
|
||||||
return cb();
|
return cb();
|
||||||
});
|
});
|
||||||
@@ -387,7 +388,7 @@ var Api = {
|
|||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
}, function() {
|
}, function() {
|
||||||
data.files = needPostFilesAttr;
|
data.Files = needPostFilesAttr;
|
||||||
var needMultiple = false;
|
var needMultiple = false;
|
||||||
for(var i in needTransferFiles) {
|
for(var i in needTransferFiles) {
|
||||||
needMultiple = true;
|
needMultiple = true;
|
||||||
@@ -405,6 +406,7 @@ var Api = {
|
|||||||
log('add note ret');
|
log('add note ret');
|
||||||
log(ret);
|
log(ret);
|
||||||
if(Common.isOk(ret)) {
|
if(Common.isOk(ret)) {
|
||||||
|
// 将serverId保存
|
||||||
callback(ret);
|
callback(ret);
|
||||||
} else {
|
} else {
|
||||||
callback(false);
|
callback(false);
|
||||||
|
1
node_modules/evt.js
generated
vendored
1
node_modules/evt.js
generated
vendored
@@ -3,6 +3,7 @@ var User = require('user');
|
|||||||
|
|
||||||
function log(o) {console.log(o)}
|
function log(o) {console.log(o)}
|
||||||
var Evt = {
|
var Evt = {
|
||||||
|
leanoteUrl: 'http://localhost:9000',
|
||||||
port: 8008,
|
port: 8008,
|
||||||
localUrl: 'http://127.0.0.1:8008',
|
localUrl: 'http://127.0.0.1:8008',
|
||||||
getImageLocalUrl: function(fileId) {
|
getImageLocalUrl: function(fileId) {
|
||||||
|
15
node_modules/file.js
generated
vendored
15
node_modules/file.js
generated
vendored
@@ -158,6 +158,21 @@ var File = {
|
|||||||
}
|
}
|
||||||
callback(images);
|
callback(images);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 笔记添加/修改后会有LocalFileId <=> FileId映射
|
||||||
|
updateFileForce(files) {
|
||||||
|
if(!files) {
|
||||||
|
// callback && callback(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(var i in files) {
|
||||||
|
var file = files[i];
|
||||||
|
if(!file.FileId || !file.LocalFileId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Images.update({FileId: file.LocalFileId}, {$set: {ServerFileId: file.FileId, IsDirty: false}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
63
node_modules/note.js
generated
vendored
63
node_modules/note.js
generated
vendored
@@ -169,19 +169,48 @@ var Note = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 远程修改本地内容
|
// 服务器上的数据到本地
|
||||||
updateNoteContentForce: function(noteId, content, callback) {
|
fixNoteContent: function(content) {
|
||||||
// <img src="http://localhost:9000/api/file/getImage?fileId=54c2083f99c37bea5f000001">
|
if(!content) {
|
||||||
// 改成<img src="http://localhost:3232/api/file/getImage?fileId=xxx"
|
return content;
|
||||||
if(!Api) {
|
|
||||||
Api = require('api');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var reg = new RegExp('src="' + Api.leanoteUrl + '/api/file/getImage', 'g');
|
var reg = new RegExp(Evt.leanoteUrl + '/api/file/getImage', 'g');
|
||||||
content = content.replace(reg, 'src="' + Server.localUrl + '/api/file/getImage');
|
content = content.replace(reg, Server.localUrl + '/api/file/getImage');
|
||||||
|
|
||||||
|
var reg2 = new RegExp(Evt.leanoteUrl + '/api/file/getAttach', 'g');
|
||||||
|
content = content.replace(reg, Evt.localUrl + '/api/file/getAttach');
|
||||||
|
|
||||||
|
var reg3 = new RegExp(Evt.leanoteUrl + '/api/file/getAllAttach', 'g');
|
||||||
|
content = content.replace(reg, Evt.localUrl + '/api/file/getAllAttach');
|
||||||
|
|
||||||
|
return content;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 将本地的url改下, 发送数据到服务器上
|
||||||
|
fixNoteContentForSend: function(content) {
|
||||||
|
if(!content) {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
console.log(Evt.localUrl + '/api/file/getImage');
|
||||||
|
var reg = new RegExp(Evt.localUrl + '/api/file/getImage', 'g');
|
||||||
|
content = content.replace(reg, Evt.leanoteUrl + '/api/file/getImage');
|
||||||
|
|
||||||
|
var reg2 = new RegExp(Evt.localUrl + '/api/file/getAttach', 'g');
|
||||||
|
content = content.replace(reg, Evt.leanoteUrl + '/api/file/getAttach');
|
||||||
|
|
||||||
|
var reg3 = new RegExp(Evt.localUrl + '/api/file/getAllAttach', 'g');
|
||||||
|
content = content.replace(reg, Evt.leanoteUrl + '/api/file/getAllAttach');
|
||||||
|
|
||||||
|
return content;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 远程修改本地内容
|
||||||
|
updateNoteContentForce: function(noteId, content, callback) {
|
||||||
|
var me = this;
|
||||||
|
|
||||||
|
content = me.fixNoteContent(content);
|
||||||
|
|
||||||
log("----<>");
|
|
||||||
log(content);
|
|
||||||
Notes.update({NoteId: noteId}, { $set: {Content: content, InitSync: false, IsContentDirty: false} }, {}, function (err, numReplaced) {
|
Notes.update({NoteId: noteId}, { $set: {Content: content, InitSync: false, IsContentDirty: false} }, {}, function (err, numReplaced) {
|
||||||
if(err) {
|
if(err) {
|
||||||
log(err);
|
log(err);
|
||||||
@@ -351,12 +380,21 @@ var Note = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// addNote, updateNote后的操作
|
||||||
// 添加修改ServerNoteId; 更新修改usn
|
// 添加修改ServerNoteId; 更新修改usn
|
||||||
updateNoteForceForSendChange: function(note, callback) {
|
updateNoteForceForSendChange: function(note, isAdd, callback) {
|
||||||
var me = this;
|
var me = this;
|
||||||
note.IsDirty = false;
|
note.IsDirty = false;
|
||||||
note.InitSync = false;
|
note.InitSync = false;
|
||||||
note.LocalIsNew = false;
|
note.LocalIsNew = false;
|
||||||
|
|
||||||
|
if(isAdd) {
|
||||||
|
delete note['content'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改LocalFileId <=> FileId的映射
|
||||||
|
File.updateFileForce(note.Files);
|
||||||
|
|
||||||
Notes.update({NoteId: note.NoteId}, {$set: note}, function(err, n) {
|
Notes.update({NoteId: note.NoteId}, {$set: note}, function(err, n) {
|
||||||
if(err || !n) {
|
if(err || !n) {
|
||||||
log('updateNoteForceForSendChange err');
|
log('updateNoteForceForSendChange err');
|
||||||
@@ -524,9 +562,10 @@ var Note = {
|
|||||||
// 每一个笔记得到图片, 附件信息和数据
|
// 每一个笔记得到图片, 附件信息和数据
|
||||||
async.eachSeries(notes, function(note, cb) {
|
async.eachSeries(notes, function(note, cb) {
|
||||||
me.getNoteFiles(note.NoteId, note.Content, function(files) {
|
me.getNoteFiles(note.NoteId, note.Content, function(files) {
|
||||||
|
note.Content = me.fixNoteContentForSend(note.Content);
|
||||||
note.Files = files || [];
|
note.Files = files || [];
|
||||||
cb();
|
cb();
|
||||||
})
|
});
|
||||||
}, function() {
|
}, function() {
|
||||||
callback(notes);
|
callback(notes);
|
||||||
})
|
})
|
||||||
|
5
node_modules/sync.js
generated
vendored
5
node_modules/sync.js
generated
vendored
@@ -539,7 +539,7 @@ var Sync = {
|
|||||||
newNote.NoteId = note.NoteId;
|
newNote.NoteId = note.NoteId;
|
||||||
me._syncInfo.note.changeAdds.push(newNote);
|
me._syncInfo.note.changeAdds.push(newNote);
|
||||||
|
|
||||||
Note.updateNoteForceForSendChange(newNote);
|
Note.updateNoteForceForSendChange(newNote, true);
|
||||||
|
|
||||||
me.checkNeedIncSyncAgain(newNote.Usn);
|
me.checkNeedIncSyncAgain(newNote.Usn);
|
||||||
|
|
||||||
@@ -570,7 +570,8 @@ var Sync = {
|
|||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
// 更新成功
|
// 更新成功
|
||||||
Note.updateNoteForceForSendChange({NoteId: note.NoteId, Usn: ret.Usn});
|
// TODO 返回是真note
|
||||||
|
Note.updateNoteForceForSendChange({NoteId: note.NoteId, Usn: ret.Usn}, false);
|
||||||
|
|
||||||
me.checkNeedIncSyncAgain(ret.Usn);
|
me.checkNeedIncSyncAgain(ret.Usn);
|
||||||
|
|
||||||
|
7
test.js
7
test.js
@@ -16,12 +16,13 @@ Api.addNotebook({
|
|||||||
Title: "哈哈"
|
Title: "哈哈"
|
||||||
}, function() {});
|
}, function() {});
|
||||||
*/
|
*/
|
||||||
Api.uploadImage();
|
// Api.uploadImage();
|
||||||
/*
|
|
||||||
User.userId = '54bdc65599c37b0da9000002';
|
User.userId = '54bdc65599c37b0da9000002';
|
||||||
// console.log(User.getCurActiveUserId());
|
// console.log(User.getCurActiveUserId());
|
||||||
Note.getDirtyNotes(function(ret) {
|
Note.getDirtyNotes(function(ret) {
|
||||||
console.log(ret);
|
Api.addNote(ret[0], function(ret2){
|
||||||
|
console.log(ret2);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
/*
|
/*
|
||||||
Note.getNoteByServerNoteId("54c6313799c37bdeec000008", function(ret){
|
Note.getNoteByServerNoteId("54c6313799c37bdeec000008", function(ret){
|
||||||
|
Reference in New Issue
Block a user