diff --git a/index.html b/index.html
new file mode 100644
index 00000000..465f6355
--- /dev/null
+++ b/index.html
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+Leanote, Not Just A Notebook
+
+
+
+loading........
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/node_modules/note.js b/node_modules/note.js
index 641c541c..fa7193a7 100644
--- a/node_modules/note.js
+++ b/node_modules/note.js
@@ -154,8 +154,8 @@ var Note = {
var reg = new RegExp('
");
- log(content);
+ // log("----<>");
+ // log(content);
Notes.update({NoteId: noteId}, { $set: {Content: content, InitSync: false, IsContentDirty: false} }, {}, function (err, numReplaced) {
if(err) {
log(err);
diff --git a/node_modules/server.js b/node_modules/server.js
index f5529112..690a1367 100644
--- a/node_modules/server.js
+++ b/node_modules/server.js
@@ -134,41 +134,48 @@ var Server = {
if(!fileId) {
return me.e404(res);
}
+
+ // 访问api, 得到图片
+ function getImageFromApi() {
+ log('从远程得到图片 ' + fileId);
+ Api.getImage(fileId, function(fileLocalPath, filename) {
+ if(fileLocalPath) {
+ log('图片保存到本地成功');
+ // 保存到本地数据库中
+ File.addImageForce(fileId, fileLocalPath, function(doc) {
+ if(doc) {
+ log('保存到本地数据库成功');
+ } else {
+ log('保存到数据库失败');
+ }
+ return me.retImage(fileLocalPath, res);
+ });
+ } else {
+ // 远程取不到图片, 是没有网络? 还是远程真的没有了
+ // TODO
+ log('取不远程的图片' + fileId);
+ return me.e404(res);
+ }
+ });
+ }
// 先查看本地是否有该文件
// has表示本地数据库有记录
File.getImageLocalPath(fileId, function(has, fileLocalPath) {
// 本地有
- if(has && fileLocalPath && path.exists(fileLocalPath) ) {
- if(fileLocalPath) {
- me.retImage(fileLocalPath, res);
- // 本地没有路径
- } else {
- // 这里不会执行, 会执行下面的, 本地没有图片, 要从远程获取
- // 是否需要重新从远程获取呢?
- log('本地有数据, 但是图片找不到了, 可能自己删除了图片?');
- me.e404(res);
- }
- } else {
- // 访问api, 得到图片
- Api.getImage(fileId, function(fileLocalPath, filename) {
- if(fileLocalPath) {
- log('图片保存到本地成功');
- // 保存到本地数据库中
- File.addImageForce(fileId, fileLocalPath, function(doc) {
- if(doc) {
- log('保存到本地数据库成功');
- } else {
- log('保存到数据库失败');
- }
- return me.retImage(fileLocalPath, res);
- });
+ log('re img')
+ console.log(fileLocalPath);
+ // console.log(fs.exists(fileLocalPath));
+ if(has && fileLocalPath) {
+ fs.exists(fileLocalPath, function(exists) {
+ if(exists) {
+ log('本地存在')
+ me.retImage(fileLocalPath, res);
} else {
- // 远程取不到图片, 是没有网络? 还是远程真的没有了
- // TODO
- log('取不远程的图片' + fileId);
- return me.e404(res);
+ getImageFromApi();
}
});
+ } else {
+ getImageFromApi();
}
});
}
diff --git a/node_modules/sync.js b/node_modules/sync.js
index a4c4c656..7062a682 100644
--- a/node_modules/sync.js
+++ b/node_modules/sync.js
@@ -187,7 +187,7 @@ var Sync = {
function canCall() {
// 是最后一块, 且
me._addSyncNoteNum();
- log(me._totalHasSyncNoteNum + ' ' + me._totalSyncNoteNum);
+ log('notes: ' + me._totalHasSyncNoteNum + ' ' + me._totalSyncNoteNum + ' ' + me._syncNoteIsLastChunk);
if(me._syncNoteIsLastChunk && me._totalHasSyncNoteNum >= me._totalSyncNoteNum) {
me._syncInfo.note.ok = true;
callback && callback(true);
@@ -222,10 +222,9 @@ var Sync = {
// 2.1 本地没有, 表示是新建
if(!noteLocal) {
log('add: ...')
- // TODO
Note.addNoteForce(note, function(note) {
me._syncInfo.note.adds.push(note);
- canCall();
+ return canCall();
});
} else {
// 2.2 本地是否修改了, 冲突, 报告给前端, 前端处理
@@ -233,6 +232,7 @@ var Sync = {
if(note.IsDirty) {
log('冲突....')
me._syncInfo.note.conflicts.push(note);
+ return canCall();
// 2.3 服务器是最新的, 用服务器的
} else {
// 服务器是最新的, 本地没动过, 则覆盖之