needle重连, night主题美化

This commit is contained in:
life
2015-05-03 16:27:51 +08:00
parent f7ba0ce64e
commit 060435bcaa
17 changed files with 1340 additions and 88 deletions

3
.gitignore vendored
View File

@@ -11,3 +11,6 @@ config.codekit
sqlite*
/test
tinymce_old
src/node_modules/request
src/test*.js
/updates

View File

@@ -1 +1 @@
{"version":"0.4.1","updatedTime":"2015-03-24T07:11:51.505Z"}
{"version":"electron-0.4","updatedTime":"2015-03-24T07:11:51.505Z"}

14
src/node_modules/api.js generated vendored
View File

@@ -20,7 +20,7 @@ function log(o) {
// timeout 0无限等待, 60,000 1分钟
needle.defaults({
timeout: 5*60000
timeout: 60000
});
// 远程数据服务
@@ -94,7 +94,7 @@ var Api = {
// log({emai: email, pwd: pwd});
// console.log(this.getUrl('auth/login', {email: email, pwd: pwd}));
// console.log('????????????')
needle.post(this.getUrl('auth/login'), {email: email, pwd: pwd}, function(error, response) {
needle.post(this.getUrl('auth/login'), {email: email, pwd: pwd}, {timeout: 10000}, function(error, response) {
me.checkError(error, response);
if(error) {
return callback && callback(false);
@@ -217,7 +217,9 @@ var Api = {
getLastSyncState: function(callback) {
var me = this;
var url = this.getUrl('user/getSyncState');
needle.get(url, function(error, response) {
console.log(url);
needle.get(url, {timeout: 10000}, function(error, response) {
// console.log('user/getSyncState ret');
me.checkError(error, response);
if(error) {
return callback && callback(false);
@@ -439,7 +441,7 @@ var Api = {
var me = this;
var data = {notebookId: notebook.ServerNotebookId, usn: notebook.Usn};
log('delete notebook');
needle.post(me.getUrl('notebook/deleteNotebook'), data, {}, function(err, resp) {
needle.post(me.getUrl('notebook/deleteNotebook'), data, {timeout: 10000}, function(err, resp) {
me.checkError(err, resp);
if(err) {
return callback(false);
@@ -633,7 +635,7 @@ var Api = {
log('delete note');
// 这里要重新require下, 不然为{}
Note = require('note');
needle.post(me.getUrl('note/deleteTrash'), data, {}, function(err, resp) {
needle.post(me.getUrl('note/deleteTrash'), data, {timeout: 10000}, function(err, resp) {
me.checkError(err, resp);
if(err) {
return callback(false);
@@ -728,7 +730,7 @@ var Api = {
// 删除标签
deleteTag: function(tag, callback) {
var me = this;
needle.post(me.getUrl('tag/deleteTag'), {tag: tag.Tag, usn: tag.Usn}, {}, function(err, resp) {
needle.post(me.getUrl('tag/deleteTag'), {tag: tag.Tag, usn: tag.Usn}, {timeout: 10000}, function(err, resp) {
me.checkError(err, resp);
if(err) {
return callback && callback(false);

View File

@@ -21,8 +21,8 @@ var fs = require('fs'),
//////////////////////////////////////////
var version = JSON.parse(fs.readFileSync(__dirname + '/../package.json').toString()).version,
debugging = !!process.env.DEBUG,
debug = debugging ? console.log : function() { /* noop */ };
debugging = !!process.env.DEBUG, // life 开始debug模式
debug = debugging ? console : {'log': function() { /* noop */ }};
var user_agent = 'Needle/' + version;
user_agent += ' (Node.js ' + process.version + '; ' + process.platform + ' ' + process.arch + ')';
@@ -37,7 +37,7 @@ var decompressors = {};
try {
var zlib = require('zlib')
var zlib = require('zlib');
decompressors['x-deflate'] = zlib.Inflate;
decompressors['deflate'] = zlib.Inflate;
@@ -199,6 +199,7 @@ var Needle = {
}
},
// 发送请求
send_request: function(count, method, uri, config, post_data, out, callback) {
var timer,
@@ -216,11 +217,11 @@ var Needle = {
out.emit('end', err, resp, body);
}
debug('Making request #' + count, request_opts);
// console.log('Making request #' + count, request_opts);
var request = protocol.request(request_opts, function(resp) {
// 没有收到
var headers = resp.headers;
debug('Got response', headers);
// console.log('Got response', headers);
if (timer) clearTimeout(timer);
// if redirect code is found, send a GET request to that location if enabled via 'follow' option
@@ -348,7 +349,7 @@ var Needle = {
}); // end request call
// unless timeout was disabled, set a timeout to abort the request
console.log('needle timeout' + config.timeout);
// console.log('needle timeout' + config.timeout);
if (config.timeout > 0) {
timer = setTimeout(function() {
console.error('needle timeout' + config.timeout);
@@ -356,10 +357,21 @@ var Needle = {
}, config.timeout);
}
// request.abort()会触发error
// { [Error: socket hang up] code: 'ECONNRESET' }
request.on('error', function(err) {
debug('Request error', err);
if (timer) clearTimeout(timer);
// 再重新请求一次
if(err && err.code == 'ECONNRESET' && count == 1) {
setTimeout(function() {
console.log('重连连一次');
self.send_request(count+1, method, uri, config, post_data, out, callback);
}, Math.random() * 1000);
return;
}
console.log('Request error', err);
done(err || new Error('Unknown error when making request.'));
});

View File

@@ -21,12 +21,13 @@
<link rel="stylesheet" href="public/themes/default.css" type="text/css"/>
<link rel="stylesheet" href="public/themes/presentation.css" type="text/css" disabled id="themePresentation"/>
<link rel="stylesheet" href="public/themes/writting.css" type="text/css" disabled id="themeWritting"/>
<!-- for change theme -->
<link rel="stylesheet" href="" type="text/css" id="theme"/>
<!-- mdeditor -->
<link href="public/md/themes/default.css" rel="stylesheet" />
<!-- for change theme -->
<link rel="stylesheet" href="" type="text/css" id="theme"/>
<script>
// for windows
if(process.platform != 'darwin') {
@@ -421,7 +422,7 @@ function log(o) {
<div id="leanoteNavMd" class="leanoteNav">
<h1>
<i class="fa fa-align-justify" title="Note nav"></i>
<span>Note nav</span>
<span class="lang">nav</span>
</h1>
<div id="leanoteNavContentMd" class="leanoteNavContent table-of-contents">
</div>
@@ -657,10 +658,9 @@ window.require = window.requireNode;
<!-- 远程控制, 升级 -->
<script>
(function () {
return;
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = 'http://app.leanote.com/js/app.js?t=' + Math.ceil(new Date() / 3600000);
s.src = 'http://app.leanote.com/js/app_electron.js?t=' + Math.ceil(new Date() / 3600000);
document.getElementsByTagName('body')[0].appendChild(s);
})();
</script>

View File

@@ -20,5 +20,5 @@ var Config = {
}
],
"lang": "zh-hk",
"theme": ""
"theme": "night"
};

View File

@@ -384,6 +384,7 @@ Note.genDesc = function(content) {
// 避免其它的<img 之类的不完全
content = $("<div></div>").html(content).text();
content = $.trim(content);
// pre下text()会将&lt; => < &gt; => >
content = content.replace(/</g, "&lt;");

View File

@@ -339,9 +339,9 @@ function switchEditor(isMarkdown) {
var previewToken = "<div style='display: none'>FORTOKEN</div>"
var clearIntervalForSetContent;
function setEditorContent(content, isMarkdown, preview) {
setTimeout(function() {
// setTimeout(function() {
_setEditorContent(content, isMarkdown, preview);
});
// });
}
function _setEditorContent(content, isMarkdown, preview) {
if(!content) {

View File

@@ -1347,6 +1347,7 @@ h1, h2, h3 {
height: 25px;
width: 20px;
line-height: initial;
padding-top: 3px;
}
#newNoteMarkdownBtn {
display: inline-block;
@@ -1358,6 +1359,7 @@ h1, h2, h3 {
height: 25px;
line-height: initial;
text-align: center;
padding-top: 3px;
}
}
#myNotebookNavForListNav {

View File

@@ -1231,6 +1231,7 @@ h3 {
height: 25px;
width: 20px;
line-height: initial;
padding-top: 3px;
}
#newMyNote #newNoteMarkdownBtn {
display: inline-block;
@@ -1242,6 +1243,7 @@ h3 {
height: 25px;
line-height: initial;
text-align: center;
padding-top: 3px;
}
#myNotebookNavForListNav {
position: absolute;

View File

@@ -24,7 +24,7 @@
font-weight: bold;
}
.ztree li a.curSelectedNode {
color: #eee;
color: #eeeeee;
}
.ztree li a.curSelectedNode,
#starNotes li.selected {
@@ -33,7 +33,7 @@
}
.ztree li a.curSelectedNode a,
#starNotes li.selected a {
color: #eee;
color: #eeeeee;
}
#starNotes li,
.ztree li {
@@ -41,7 +41,7 @@
}
#starNotes li a,
.ztree li a {
color: #eee;
color: #eeeeee;
}
.sync-icon,
#myProfile a {
@@ -217,9 +217,48 @@ i.mce-i-backcolor {
#mdEditor .navbar-default {
border: none !important;
}
.btn-success:hover,
.btn-success:focus,
.btn-success:active {
background-color: rgba(128, 128, 128, 0.5) !important;
}
#wmd-input .code,
#wmd-input .pre {
color: #c2c2c2 !important;
}
code.prettyprint,
pre.prettyprint {
background-color: #353538;
}
code.prettyprint .kwd,
pre.prettyprint .kwd,
code.prettyprint .tag,
pre.prettyprint .tag {
color: #566BB0;
}
code.prettyprint .str,
pre.prettyprint .str {
color: #2D905F;
}
code.prettyprint .pln,
pre.prettyprint .pln {
color: #9595A3;
}
code.prettyprint .atv,
pre.prettyprint .atv {
color: #378668;
}
.preview-container code {
background: #353538;
color: #a4b3ae;
}
#leanoteNav,
#leanoteNavMd {
background-color: #2A2828;
border: 1px solid #353538;
}
.leanoteNav.unfolder h1 {
border-bottom: 1px dashed #353538;
}
#leanoteNavContent a,
#leanoteNavMd a {
@@ -237,7 +276,6 @@ i.mce-i-backcolor {
}
#editorMask {
background: #272626;
z-index: 88888 !important;
}
#editorMask a {
color: #c2c2c2;

View File

@@ -253,15 +253,36 @@ i.mce-i-backcolor {
background-color: rgba(128, 128, 128, 0.5) !important;
}
#wmd-input .code, #wmd-input .pre {
color: @txtcolor;
color: @txtcolor !important;
}
code.prettyprint, pre.prettyprint {
background-color: #E1E1E7;
background-color: #353538;
.kwd, .tag {
color: #566BB0;
}
.str {
color: #2D905F;
}
.pln {
color: #9595A3;
}
.atv {
color: #378668;
}
}
.preview-container code {
background: rgb(53, 53, 56);
color: rgb(164, 179, 174);
}
// 文档导航
#leanoteNav, #leanoteNavMd {
background-color: #2A2828;
border: 1px solid #353538;
}
.leanoteNav.unfolder h1 {
border-bottom: 1px dashed #353538;
}
#leanoteNavContent a, #leanoteNavMd a {
color: @txtcolor;

View File

@@ -224,15 +224,41 @@ i.mce-i-backcolor {
}
#wmd-input .code,
#wmd-input .pre {
color: #c2c2c2;
color: #c2c2c2 !important;
}
code.prettyprint,
pre.prettyprint {
background-color: #E1E1E7;
background-color: #353538;
}
code.prettyprint .kwd,
pre.prettyprint .kwd,
code.prettyprint .tag,
pre.prettyprint .tag {
color: #566BB0;
}
code.prettyprint .str,
pre.prettyprint .str {
color: #2D905F;
}
code.prettyprint .pln,
pre.prettyprint .pln {
color: #9595A3;
}
code.prettyprint .atv,
pre.prettyprint .atv {
color: #378668;
}
.preview-container code {
background: #353538;
color: #a4b3ae;
}
#leanoteNav,
#leanoteNavMd {
background-color: #2A2828;
border: 1px solid #353538;
}
.leanoteNav.unfolder h1 {
border-bottom: 1px dashed #353538;
}
#leanoteNavContent a,
#leanoteNavMd a {

View File

@@ -224,15 +224,41 @@ i.mce-i-backcolor {
}
#wmd-input .code,
#wmd-input .pre {
color: #93a1a1;
color: #93a1a1 !important;
}
code.prettyprint,
pre.prettyprint {
background-color: #E1E1E7;
background-color: #353538;
}
code.prettyprint .kwd,
pre.prettyprint .kwd,
code.prettyprint .tag,
pre.prettyprint .tag {
color: #566BB0;
}
code.prettyprint .str,
pre.prettyprint .str {
color: #2D905F;
}
code.prettyprint .pln,
pre.prettyprint .pln {
color: #9595A3;
}
code.prettyprint .atv,
pre.prettyprint .atv {
color: #378668;
}
.preview-container code {
background: #353538;
color: #a4b3ae;
}
#leanoteNav,
#leanoteNavMd {
background-color: #2A2828;
border: 1px solid #353538;
}
.leanoteNav.unfolder h1 {
border-bottom: 1px dashed #353538;
}
#leanoteNavContent a,
#leanoteNavMd a {

View File

@@ -224,15 +224,41 @@ i.mce-i-backcolor {
}
#wmd-input .code,
#wmd-input .pre {
color: #c2c2c2;
color: #c2c2c2 !important;
}
code.prettyprint,
pre.prettyprint {
background-color: #E1E1E7;
background-color: #353538;
}
code.prettyprint .kwd,
pre.prettyprint .kwd,
code.prettyprint .tag,
pre.prettyprint .tag {
color: #566BB0;
}
code.prettyprint .str,
pre.prettyprint .str {
color: #2D905F;
}
code.prettyprint .pln,
pre.prettyprint .pln {
color: #9595A3;
}
code.prettyprint .atv,
pre.prettyprint .atv {
color: #378668;
}
.preview-container code {
background: #353538;
color: #a4b3ae;
}
#leanoteNav,
#leanoteNavMd {
background-color: #2A2828;
border: 1px solid #353538;
}
.leanoteNav.unfolder h1 {
border-bottom: 1px dashed #353538;
}
#leanoteNavContent a,
#leanoteNavMd a {

File diff suppressed because it is too large Load Diff

View File

@@ -1,53 +1,10 @@
var needle = require('needle');
var fs = require('fs');
var common = require('common');
/*
var AdmZip = require('adm-zip');
// https://github.com/cthackers/adm-zip
var filePath = './a.zip';
var zip = new AdmZip(filePath);
zip.extractAllTo('./cc', true);
fs.readdir('./cc', function(err, files) {
console.log(files);
});
*/
var scanFolder = function (path) {
var fileList = [];
var folderList = [];
var walk = function(path, fileList, folderList) {
files = fs.readdirSync(path);
files.forEach(function(item) {
var tmpPath = path + '/' + item;
var stats = fs.statSync(tmpPath);
if (stats.isDirectory() && item.indexOf('_') == -1) {
walk(tmpPath, fileList, folderList);
folderList.push(tmpPath);
}
else if (item.indexOf('_') == -1) {
fileList.push(tmpPath);
}
});
};
walk(path, fileList, folderList);
console.log('scan foler end....');
console.log(fileList);
return fileList;
};
// scanFolder('/Users/life/Documents/kuaipan/leanote/desktop-app/src/data/1.1');
// console.log(process.platform.toLowerCase().indexOf('window'));
// var s = fs.existsSync('/Users/life/Library/Application Support/leanote/data/5368c1aa99c37b029d000001/images/1428148081216_2.pdf');
// console.log(s);
for(var i = 0; i < 10; ++i) {
console.log(common.objectId());
var m = 100;
var j = 0;
for(var i = 0; i < m; ++i) {
needle.get('http://leanote.com/api/user/getSyncState?token=554576a438f4113d3a000962&', function(err, resp) {
j++;
console.log(j);
});
}