From b0601eeb53108105ff13768a9e25156adaabfeb3 Mon Sep 17 00:00:00 2001 From: life Date: Mon, 6 Apr 2015 18:22:55 +0800 Subject: [PATCH] v0.3.4 --- src/data/version | 2 +- src/node_modules/common.js | 24 +++++++++++++++++------- src/node_modules/file.js | 25 +++++++++++++++++-------- src/node_modules/import.js | 5 ++++- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/data/version b/src/data/version index ecfcc2b5..1716550b 100644 --- a/src/data/version +++ b/src/data/version @@ -1 +1 @@ -{"version":"0.3.3","updatedTime":"2015-03-24T07:11:51.505Z"} \ No newline at end of file +{"version":"0.3.4","updatedTime":"2015-03-24T07:11:51.505Z"} \ No newline at end of file diff --git a/src/node_modules/common.js b/src/node_modules/common.js index 5a8f8b0a..a9eed390 100644 --- a/src/node_modules/common.js +++ b/src/node_modules/common.js @@ -164,18 +164,28 @@ var Common = { // 执行命令 cmd: function(args, exitFunc) { var me = this; + var exec = require('child_process').exec; var binPath = process.cwd() + '/public/bin/leanote-mac'; if(me.isWin()) { var binPath = process.cwd() + '/public/bin/leanote.exe'; - } - var exec = require('child_process').exec; - var cmd = '"' + binPath + '"'; // "' + txtPath + '" "' + filePath + '"' - for(var i in args) { - cmd += ' "' + args[i] + '"'; + go(); + } else { + // 先chmod +x + var chmod = exec('chmod +x "' + binPath + '"'); + chmod.on('exit', function(code) { + go(); + }); } - last = exec(cmd); - last.on('exit', exitFunc); + function go() { + var cmd = '"' + binPath + '"'; // "' + txtPath + '" "' + filePath + '"' + for(var i in args) { + cmd += ' "' + args[i] + '"'; + } + + last = exec(cmd); + last.on('exit', exitFunc); + } } }; module.exports = Common; diff --git a/src/node_modules/file.js b/src/node_modules/file.js index b48d5391..3d90e8f8 100644 --- a/src/node_modules/file.js +++ b/src/node_modules/file.js @@ -91,13 +91,17 @@ var File = { console.log('子进程已关闭,代码:' + code); fs.unlink(txtPath); if(!code) { - if(isImage) { - me._addImage(Common.objectId(), filePath, function(newImg) { - newImg.IsImage = true; - callback && callback(newImg); - }); - } else { - me._addAttach(filePath, fileTitle, callback) + try { + if(isImage) { + me._addImage(Common.objectId(), filePath, function(newImg) { + newImg.IsImage = true; + callback && callback(newImg); + }); + } else { + me._addAttach(filePath, fileTitle, callback) + } + } catch(e) { + callback(false); } } else { callback(false); @@ -112,7 +116,12 @@ var File = { } }, _addAttach: function(filePath, fileTitle, callback) { - var fileStat = fs.statSync(filePath); + try { + var fileStat = fs.statSync(filePath); + } catch(e) { + callback(false); + return; + } var paths = filePath.split(Common.getPathSep()); // windows的filePath不同 var name = paths[paths.length-1]; // Web.alertWeb(name); diff --git a/src/node_modules/import.js b/src/node_modules/import.js index 89c47bb6..9b7c9b41 100755 --- a/src/node_modules/import.js +++ b/src/node_modules/import.js @@ -111,7 +111,10 @@ var Import = { var mime = res['mime'][0].toLowerCase(); if(mime.indexOf('image') == 0) { isImage = true; - type = mime.split('/').pop(); + } + type = mime.split('/').pop(); + if(type == '') { + type = 'raw'; } // console.log(base64Str);