Skip to content

Commit

Permalink
Merge pull request #63 from timcui/dev
Browse files Browse the repository at this point in the history
use alloy eslint config
  • Loading branch information
timcui authored May 28, 2018
2 parents 42d6c3e + 222ee9d commit c9692c8
Show file tree
Hide file tree
Showing 142 changed files with 4,069 additions and 3,765 deletions.
42 changes: 41 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"commonjs": true,
"es6": true
},
"extends": "eslint:recommended",
"extends": "eslint-config-alloy",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2017
Expand Down Expand Up @@ -79,6 +79,39 @@
],
"prefer-const": [
"warn"
],
"no-param-reassign": [
"off"
],
"no-template-curly-in-string": [
"off"
],
"one-var": [
"off"
],
"guard-for-in": [
"off"
],
"no-undefined": [
"off"
],
"complexity": [
"off"
],
"max-nested-callbacks": [
"off"
],
"no-path-concat": [
"off"
],
"eqeqeq": [
"off"
],
"max-depth": [
"off"
],
"strict": [
"off"
]
},
"overrides": [
Expand All @@ -90,6 +123,13 @@
"globals": {
"define": true
}
}, {
"files": ["bin/tsw/util/auto-report/tmpl.js"],
"rules": {
"no-inner-declarations": [
"off"
]
}
}, {
"files": ["bin/lib/util/mail/tmpl.js", "bin/tsw/util/**/tmpl.js"],
"rules": {
Expand Down
3 changes: 2 additions & 1 deletion bin/lib/api/cmdb/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/* !
* Tencent is pleased to support the open source community by making Tencent Server Web available.
* Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Expand All @@ -7,6 +7,7 @@
*/
'use strict';


const Deferred = require('util/Deferred');


Expand Down
5 changes: 3 additions & 2 deletions bin/lib/api/code/watcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/* !
* Tencent is pleased to support the open source community by making Tencent Server Web available.
* Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Expand All @@ -7,7 +7,8 @@
*/
'use strict';


this.watch = function() {


};
3 changes: 2 additions & 1 deletion bin/lib/api/habo/habo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/* !
* Tencent is pleased to support the open source community by making Tencent Server Web available.
* Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Expand All @@ -7,6 +7,7 @@
*/
'use strict';


module.exports.report = function(obj, rate) {

};
83 changes: 42 additions & 41 deletions bin/lib/api/keyman/alphaMap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/* !
* Tencent is pleased to support the open source community by making Tencent Server Web available.
* Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Expand All @@ -7,6 +7,7 @@
*/
'use strict';


const Deferred = require('util/Deferred');
const logger = require('logger');
const config = require('config');
Expand All @@ -21,32 +22,32 @@ let cache = {
dataFile: {}
};

if(global[__filename]) {
if (global[__filename]) {
cache = global[__filename];
}else{
} else {
global[__filename] = cache;
isFirstLoad = true;
}


if(isFirstLoad) {
if(config.alphaFile) {
if (isFirstLoad) {
if (config.alphaFile) {

(function() {
//导入alphaFile
// 导入alphaFile
let text = '';

try{
try {
text = fs.readFileSync(config.alphaFile, 'UTF-8');
}catch(e) {
} catch (e) {
logger.warn(e.stack);
}

if(!text) {
if (!text) {
return;
}

if(text.length >= 2 * 1024 * 1024) {
if (text.length >= 2 * 1024 * 1024) {
logger.error('alpha file limit <=2M');
return;
}
Expand All @@ -55,7 +56,7 @@ if(isFirstLoad) {
updateMap();
})();

}else{
} else {
logger.debug('config.alphaFile is: ' + config.alphaFile);
}
}
Expand All @@ -78,7 +79,7 @@ function updateMap(text) {

const map = getMap(text);

//copy
// copy
Object.assign(map, cache.dataFile);

cache.data = map;
Expand All @@ -89,48 +90,48 @@ function updateMap(text) {

this.getSync = function() {
this.get();

return cache.data;
};

this.get = function() {

const defer = Deferred.create();
const delay = (process.serverInfo && process.serverInfo.cpu * 1000) || 0;
const l5api = config.tswL5api['alphaFileUrl'];

if(Date.now() - cache.timeUpdate < 60000 + delay) {
if (Date.now() - cache.timeUpdate < 60000 + delay) {
return defer.resolve(cache.data);
}

cache.timeUpdate = Date.now();

if(!fileUrl) {
if (!fileUrl) {
return defer.resolve(cache.data);
}

fileCache.getAsync(fileUrl).done(function(d) {

let lastModifyTime = 0;
let text = '';
if(d && d.stats) {

if (d && d.stats) {
lastModifyTime = d.stats.mtime.getTime();
}
if(d && d.data) {

if (d && d.data) {
text = d.data.toString('utf-8');
}
if(Date.now() - lastModifyTime < 60000) {

if (Date.now() - lastModifyTime < 60000) {
logger.debug('使用本地文件');

updateMap(text);

defer.resolve(cache.data);
return;
}

require('ajax').request({
url: fileUrl,
type: 'get',
Expand All @@ -146,29 +147,29 @@ this.get = function() {
}).fail(function(d) {
defer.resolve(cache.data);
}).done(function(d) {

let text = '';
if(d && d.result && typeof d.result === 'string') {

if (d && d.result && typeof d.result === 'string') {

text = d.result;
}

if(text.length >= 2 * 1024 * 1024) {
if (text.length >= 2 * 1024 * 1024) {
logger.error('alpha file limit <=2M');
return defer.resolve(cache.data);
}

updateMap(text);
//保存在本地

// 保存在本地
fileCache.set(fileUrl, Buffer.from(text, 'UTF-8'));

defer.resolve(cache.data);
});
});


return defer;
};

Expand All @@ -178,11 +179,11 @@ function init() {
let buffer = null;
let text = '';

if(fileUrl) {
if (fileUrl) {
buffer = fileCache.getSync(fileUrl).data;
}

if(buffer) {
if (buffer) {
text = buffer.toString('utf-8');
updateMap(text);
}
Expand Down
Loading

0 comments on commit c9692c8

Please sign in to comment.