mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-14 15:11:24 +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是本的, 要得到远程的
|
||||
Notebook.getServerNotebookIdByNotebookId(note.NotebookId, function(serverNotebookId) {
|
||||
var data = {
|
||||
title: note.Title,
|
||||
notebookId: serverNotebookId,
|
||||
content: note.Content,
|
||||
isMarkdown: note.isMarkdown,
|
||||
tags: note.Tags,
|
||||
isBlog: note.IsBlog,
|
||||
Title: note.Title,
|
||||
NotebookId: serverNotebookId,
|
||||
Content: note.Content,
|
||||
IsMarkdown: note.isMarkdown,
|
||||
Tags: note.Tags,
|
||||
IsBlog: note.IsBlog,
|
||||
}
|
||||
log('add note');
|
||||
log(data);
|
||||
// log(data);
|
||||
|
||||
// files处理
|
||||
var files = note.Files;
|
||||
var needTransferFiles = [];
|
||||
var needPostFilesAttr = [];
|
||||
async.eachSeries(files, function(file, cb) {
|
||||
var file = files[i];
|
||||
// var file = files[i];
|
||||
var needFile = {
|
||||
fileId: file.ServerFileId,
|
||||
localFileId: file.FileId,
|
||||
hasBody: false
|
||||
FileId: file.ServerFileId,
|
||||
LocalFileId: file.FileId,
|
||||
HasBody: false
|
||||
}
|
||||
// console.log(file);
|
||||
// 要传数据的
|
||||
if(file.IsDirty) {
|
||||
ifs.exists(file.Path, function(isExists) {
|
||||
needTransferFiles[file.ServerFileId] = {
|
||||
fs.exists(file.Path, function(isExists) {
|
||||
needTransferFiles[file.FileId] = {
|
||||
file: file.Path,
|
||||
content_type: 'image/' + file.Type
|
||||
}
|
||||
needFile.hasBody = true;
|
||||
needFile.HasBody = true;
|
||||
needPostFilesAttr.push(needFile);
|
||||
return cb();
|
||||
});
|
||||
@@ -387,7 +388,7 @@ var Api = {
|
||||
return cb();
|
||||
}
|
||||
}, function() {
|
||||
data.files = needPostFilesAttr;
|
||||
data.Files = needPostFilesAttr;
|
||||
var needMultiple = false;
|
||||
for(var i in needTransferFiles) {
|
||||
needMultiple = true;
|
||||
@@ -405,6 +406,7 @@ var Api = {
|
||||
log('add note ret');
|
||||
log(ret);
|
||||
if(Common.isOk(ret)) {
|
||||
// 将serverId保存
|
||||
callback(ret);
|
||||
} else {
|
||||
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)}
|
||||
var Evt = {
|
||||
leanoteUrl: 'http://localhost:9000',
|
||||
port: 8008,
|
||||
localUrl: 'http://127.0.0.1:8008',
|
||||
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);
|
||||
});
|
||||
},
|
||||
|
||||
// 笔记添加/修改后会有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) {
|
||||
// <img src="http://localhost:9000/api/file/getImage?fileId=54c2083f99c37bea5f000001">
|
||||
// 改成<img src="http://localhost:3232/api/file/getImage?fileId=xxx"
|
||||
if(!Api) {
|
||||
Api = require('api');
|
||||
// 服务器上的数据到本地
|
||||
fixNoteContent: function(content) {
|
||||
if(!content) {
|
||||
return content;
|
||||
}
|
||||
|
||||
var reg = new RegExp('src="' + Api.leanoteUrl + '/api/file/getImage', 'g');
|
||||
content = content.replace(reg, 'src="' + Server.localUrl + '/api/file/getImage');
|
||||
var reg = new RegExp(Evt.leanoteUrl + '/api/file/getImage', 'g');
|
||||
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) {
|
||||
if(err) {
|
||||
log(err);
|
||||
@@ -351,12 +380,21 @@ var Note = {
|
||||
});
|
||||
},
|
||||
|
||||
// addNote, updateNote后的操作
|
||||
// 添加修改ServerNoteId; 更新修改usn
|
||||
updateNoteForceForSendChange: function(note, callback) {
|
||||
updateNoteForceForSendChange: function(note, isAdd, callback) {
|
||||
var me = this;
|
||||
note.IsDirty = false;
|
||||
note.InitSync = 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) {
|
||||
if(err || !n) {
|
||||
log('updateNoteForceForSendChange err');
|
||||
@@ -524,9 +562,10 @@ var Note = {
|
||||
// 每一个笔记得到图片, 附件信息和数据
|
||||
async.eachSeries(notes, function(note, cb) {
|
||||
me.getNoteFiles(note.NoteId, note.Content, function(files) {
|
||||
note.Content = me.fixNoteContentForSend(note.Content);
|
||||
note.Files = files || [];
|
||||
cb();
|
||||
})
|
||||
});
|
||||
}, function() {
|
||||
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;
|
||||
me._syncInfo.note.changeAdds.push(newNote);
|
||||
|
||||
Note.updateNoteForceForSendChange(newNote);
|
||||
Note.updateNoteForceForSendChange(newNote, true);
|
||||
|
||||
me.checkNeedIncSyncAgain(newNote.Usn);
|
||||
|
||||
@@ -570,7 +570,8 @@ var Sync = {
|
||||
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);
|
||||
|
||||
|
7
test.js
7
test.js
@@ -16,12 +16,13 @@ Api.addNotebook({
|
||||
Title: "哈哈"
|
||||
}, function() {});
|
||||
*/
|
||||
Api.uploadImage();
|
||||
/*
|
||||
// Api.uploadImage();
|
||||
User.userId = '54bdc65599c37b0da9000002';
|
||||
// console.log(User.getCurActiveUserId());
|
||||
Note.getDirtyNotes(function(ret) {
|
||||
console.log(ret);
|
||||
Api.addNote(ret[0], function(ret2){
|
||||
console.log(ret2);
|
||||
})
|
||||
});
|
||||
/*
|
||||
Note.getNoteByServerNoteId("54c6313799c37bdeec000008", function(ret){
|
||||
|
Reference in New Issue
Block a user