图片同步成功

This commit is contained in:
life
2015-01-24 00:46:25 +08:00
parent 245bbb0236
commit 6aef83697c
4 changed files with 59 additions and 33 deletions

19
index.html Normal file
View File

@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>Leanote, Not Just A Notebook</title>
</head>
<body>
<h1>loading........</h1>
<script src="public/js/jquery-1.9.0.min.js"></script>
<script src="public/js/i18n/msg.en.js"></script>
<script src="public/js/app/service.js"></script>
<!-- <script src="public/js/common.js"></script> -->
<script src="public/js/app/launch.js"></script>
</body>
</html>

4
node_modules/note.js generated vendored
View File

@@ -154,8 +154,8 @@ var Note = {
var reg = new RegExp('<img *src="' + Api.leanoteUrl + '/api/file/getImage', 'g');
content = content.replace(reg, '<img src="' + Server.localUrl + '/api/file/getImage');
log("----<>");
log(content);
// log("----<>");
// log(content);
Notes.update({NoteId: noteId}, { $set: {Content: content, InitSync: false, IsContentDirty: false} }, {}, function (err, numReplaced) {
if(err) {
log(err);

37
node_modules/server.js generated vendored
View File

@@ -134,22 +134,10 @@ var Server = {
if(!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, 得到图片
function getImageFromApi() {
log('从远程得到图片 ' + fileId);
Api.getImage(fileId, function(fileLocalPath, filename) {
if(fileLocalPath) {
log('图片保存到本地成功');
@@ -170,6 +158,25 @@ var Server = {
}
});
}
// 先查看本地是否有该文件
// has表示本地数据库有记录
File.getImageLocalPath(fileId, function(has, fileLocalPath) {
// 本地有
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 {
getImageFromApi();
}
});
} else {
getImageFromApi();
}
});
}
};

6
node_modules/sync.js generated vendored
View File

@@ -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 {
// 服务器是最新的, 本地没动过, 则覆盖之