transplanted mini_poem to console
This commit is contained in:
@@ -3,15 +3,15 @@
|
||||
* 2015-01-24
|
||||
*/
|
||||
|
||||
require('../../../Infrastructure/BackEnd/configuration/constants');
|
||||
var Cache = require('../../../Infrastructure/BackEnd/cache/redis.js');
|
||||
require('../minipoem/configuration/constants');
|
||||
var Cache = require('../mini_poem/cache/redis.js');
|
||||
var Enums = require('../constants/enums');
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
|
||||
var enums = new Enums();
|
||||
var errorCode = new ErrorCode();
|
||||
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
var AdminAuth = function(_cacheHost, _cachePort, _cacheAdmin, _cachePassword) {
|
||||
this.cache = new Cache(_cacheHost, _cachePort, _cacheAdmin, _cachePassword);
|
||||
|
||||
@@ -10,8 +10,8 @@ var bodyParser = require('body-parser');
|
||||
var methodOverride = require('method-override');
|
||||
|
||||
// global inclusion
|
||||
require('../../Infrastructure/BackEnd/configuration/constants');
|
||||
var System = require('../../Infrastructure/BackEnd/utils/system_utils');
|
||||
require('./mini_poem/configuration/constants');
|
||||
var System = require('./mini_poem/utils/system_utils');
|
||||
var systemConfig = require('./configuration/system_configs');
|
||||
|
||||
// local inclusion
|
||||
@@ -35,7 +35,7 @@ app.use("/", express.static(__dirname + '/web/'));
|
||||
systemConfig.setupEnvironment();
|
||||
serverListenPort = LISTEN_PORT;
|
||||
|
||||
var dbConn = require('../../Infrastructure/BackEnd/db/mysql/mysql_connection');
|
||||
var dbConn = require('./mini_poem/db/mysql/mysql_connection');
|
||||
|
||||
console.log("initializing MySQL connection to : " + MYSQL_DB_SERVER_ADDRESS + ":" + MYSQL_DB_NAME);
|
||||
dbConn.setMySQLParameter(MYSQL_DB_SERVER_ADDRESS, MYSQL_DB_NAME, MYSQL_DB_USER, MYSQL_DB_PASSWORD);
|
||||
|
||||
22
src/web_console/mini_poem/cache/base_cache.js
vendored
Normal file
22
src/web_console/mini_poem/cache/base_cache.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2014-12-01.
|
||||
*/
|
||||
|
||||
var BaseCache = function(_cacheType, _host, _port, _user, _password) {
|
||||
throw new Error("Abstract class");
|
||||
};
|
||||
|
||||
BaseCache.prototype.set = function(key, value, ttl, callback) {
|
||||
throw new Error("Could not implemented");
|
||||
};
|
||||
|
||||
BaseCache.prototype.get = function(key, callback) {
|
||||
throw new Error("Could not implemented");
|
||||
};
|
||||
|
||||
BaseCache.prototype.delete = function(key, callback) {
|
||||
throw new Error("Could not implemented");
|
||||
};
|
||||
|
||||
module.exports = BaseCache;
|
||||
74
src/web_console/mini_poem/cache/redis.js
vendored
Normal file
74
src/web_console/mini_poem/cache/redis.js
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2015-06-24.
|
||||
*/
|
||||
|
||||
require('../configuration/constants');
|
||||
var ErrorCode = require('../configuration/error_code');
|
||||
var Enums = require('../configuration/enums');
|
||||
var BaseCache = require('./base_cache.js');
|
||||
|
||||
var redis = require("redis");
|
||||
|
||||
var logger = require('../logging/logger4js').helper;
|
||||
|
||||
var errorCode = new ErrorCode();
|
||||
var enums = new Enums();
|
||||
|
||||
var Cache = function(_host, _port, _user, _password) {
|
||||
this.redisClient = redis.createClient({detect_buffers: true});
|
||||
// initialize client according to run-time ENV
|
||||
// in _user indicates the redis instance:token pair value
|
||||
if(null != _user) {
|
||||
logger.info("Redis needs authorization");
|
||||
this.redisClient.auth(_user, redis.print);
|
||||
}
|
||||
logger.info("Redis client connected");
|
||||
};
|
||||
|
||||
Cache.prototype = Object.create(BaseCache.prototype);
|
||||
|
||||
Cache.prototype.set = function(key, value, ttl, callback) {
|
||||
this.redisClient.set(key, value, function(err) {
|
||||
if(err) {
|
||||
logger.error("Redis set value failed with key " + key);
|
||||
callback(errorCode.FAILED);
|
||||
} else {
|
||||
logger.info("Redis set value successfully");
|
||||
callback(errorCode.SUCCESS);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Cache.prototype.get = function(key, isBuffer, callback) {
|
||||
if(true == isBuffer) {
|
||||
this.redisClient.get(new Buffer(key), function (err, reply) {
|
||||
if(err) {
|
||||
logger.error("Redis get buffer failed with key " + key);
|
||||
this.redisClient.end();
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
logger.info("Redis get buffer successfully");
|
||||
this.redisClient.end();
|
||||
callback(errorCode.SUCCESS, reply);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.redisClient.get(key, function(err, reply) {
|
||||
if(err) {
|
||||
logger.error("Redis get value failed with key " + key);
|
||||
this.redisClient.end();
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
logger.info("Redis get value successfully");
|
||||
callback(errorCode.SUCCESS, reply);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Cache.prototype.delete = function(key, callback) {
|
||||
callback(errorCode.SUCCESS);
|
||||
};
|
||||
|
||||
module.exports = Cache;
|
||||
70
src/web_console/mini_poem/configuration/constants.js
Normal file
70
src/web_console/mini_poem/configuration/constants.js
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Created by Strawmanbobi
|
||||
* 2014-08-30
|
||||
*/
|
||||
|
||||
// global constants describes the ability sets of the POEM framework
|
||||
|
||||
global.VERSION = "0.0.4";
|
||||
global.ICODE = "PoEM~ V0.0.4";
|
||||
|
||||
// runtime environment
|
||||
global.ENV = "dev";
|
||||
global.SERVER = 0;
|
||||
global.LISTEN_PORT = "80";
|
||||
|
||||
// local environment
|
||||
global.FILE_TEMP_PATH = "";
|
||||
|
||||
// db : MySQL
|
||||
global.MYSQL_DB_SERVER_ADDRESS = "127.0.0.1";
|
||||
global.MYSQL_DB_NAME = "default_db";
|
||||
global.MYSQL_DB_USER = "root";
|
||||
global.MYSQL_DB_PASSWORD = "root";
|
||||
|
||||
// db : MongoDB
|
||||
global.MONGO_DB_URI = "";
|
||||
global.MONGO_DB_SERVER_ADDRESS = "127.0.0.1";
|
||||
global.MONGO_DB_NAME = "default_db";
|
||||
global.MONGO_DB_USER = null;
|
||||
global.MONGO_DB_PASSWORD = null;
|
||||
|
||||
// data_set : Aliyun-OSS
|
||||
global.OSS_HOST = "oss-cn-hangzhou.aliyuncs.com";
|
||||
global.OSS_PORT = "80";
|
||||
global.OSS_APP_ID = "T82nbipHSESmHzd8";
|
||||
global.OSS_APP_SECRET = "SOweQ8UVwCwPr2NC8EC89EOeKJc5Um";
|
||||
global.BUCKET_NAME = "strawmanbobi-beats";
|
||||
|
||||
// cache : memcached
|
||||
global.MEMCACHED_HOST = "";
|
||||
global.MEMCACHED_PORT = "";
|
||||
global.MEMCACHED_SASL_USER = "";
|
||||
global.MEMCACHED_SASL_PASSWORD = "";
|
||||
|
||||
// sns : Weixin
|
||||
global.WEIXIN_APP_ID = "";
|
||||
global.WEIXIN_APP_SECRET = "";
|
||||
global.WEIXIN_TOKEN = "";
|
||||
|
||||
// sns : facebook
|
||||
|
||||
// external : python path
|
||||
global.PYTHON_PATH = "";
|
||||
|
||||
// message : credential
|
||||
global.PUSH_APP_KEY = "";
|
||||
global.PUSH_APP_SECRET = "";
|
||||
|
||||
// generic server configuration
|
||||
global.SERVER_LISTEN_PORT = "8080";
|
||||
global.SERVER_ADDRESS = "127.0.0.1";
|
||||
|
||||
// OSS direct download bucket name
|
||||
global.OSS_DIR_DOWN_PATH = "";
|
||||
|
||||
// incoming request security configuration
|
||||
global.APP_ID = "";
|
||||
global.APP_TOKEN = "";
|
||||
|
||||
global.TOKEN_TTL = 60;
|
||||
36
src/web_console/mini_poem/configuration/enums.js
Normal file
36
src/web_console/mini_poem/configuration/enums.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Created by Strawmanbobi
|
||||
* 2014-08-30
|
||||
*/
|
||||
|
||||
function Enums() {
|
||||
this.APP_PRODUCTION_MODE = "production";
|
||||
this.APP_DEVELOPMENT_MODE = "development";
|
||||
this.APP_USERDEBUG_MODE = "userdebug";
|
||||
|
||||
this.SERVER_MAIN = 0;
|
||||
|
||||
this.SCHEDULER_PERIODICAL = 0;
|
||||
this.SCHEDULER_ONCE = 1;
|
||||
|
||||
this.JPUSH_DEVICE_TYPE_IOS = 0;
|
||||
this.JPUSH_DEVICE_TYPE_ANDROID = 1;
|
||||
this.JPUSH_DEVICE_TYPE_BOTH = 2;
|
||||
|
||||
this.JPUSH_DEST_TYPE_BROADCAST = 0;
|
||||
this.JPUSH_DEST_TYPE_PEER = 1;
|
||||
this.JPUSH_DEST_TYPE_GROUP = 2;
|
||||
|
||||
this.JPUSH_PUSH_TYPE_MESSAGE = 0;
|
||||
this.JPUSH_PUSH_TYPE_NOTIFICATION = 1;
|
||||
|
||||
this.BC_API_MESSAGE_TYPE_MESSAGE = 0;
|
||||
this.BC_API_MESSAGE_TYPE_NOTIFICATION = 1;
|
||||
|
||||
this.BC_API_PUSH_TYPE_PEER = 0;
|
||||
this.BC_API_PUSH_TYPE_BROADCAST = 1;
|
||||
|
||||
this.ANDROID_STYPE_0 = 1;
|
||||
}
|
||||
|
||||
module.exports = Enums;
|
||||
24
src/web_console/mini_poem/configuration/error_code.js
Normal file
24
src/web_console/mini_poem/configuration/error_code.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Created by Strawmanbobi
|
||||
* 2014-08-30
|
||||
*/
|
||||
|
||||
function ErrorCode() {
|
||||
this.SUCCESS = 0;
|
||||
this.FAILED = -1;
|
||||
|
||||
this.PYTHON_SCRIPT_SUCCESS = 0;
|
||||
this.PYTHON_ARGUMENTS_ERROR = -1;
|
||||
this.PYTHON_SCRIPT_PATH_NOT_SPECIFIED = -2;
|
||||
this.PYTHON_CALLBACK_NOT_SPECIFIED = -3;
|
||||
|
||||
this.WRONG_PUSH_DEVICE = -50;
|
||||
this.WRONG_PUSH_TYPE = -51;
|
||||
this.WRONG_PUSH_DESTINATION = -52;
|
||||
|
||||
this.SNS_WEIXIN_VALIDATION_SUCCESS = 0;
|
||||
this.SNS_WEIXIN_VALIDATION_FAILED = 1;
|
||||
|
||||
}
|
||||
|
||||
module.exports = ErrorCode;
|
||||
192
src/web_console/mini_poem/crypto/md5.js
Normal file
192
src/web_console/mini_poem/crypto/md5.js
Normal file
@@ -0,0 +1,192 @@
|
||||
/**
|
||||
* Created by Strawmanbobi
|
||||
* 2014-08-31
|
||||
*/
|
||||
|
||||
function MD5(sMessage, fullSize) {
|
||||
function RotateLeft(lValue, iShiftBits) {
|
||||
return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
|
||||
}
|
||||
|
||||
function AddUnsigned(lX, lY) {
|
||||
var lX4, lY4, lX8, lY8, lResult;
|
||||
lX8 = (lX & 0x80000000);
|
||||
lY8 = (lY & 0x80000000);
|
||||
lX4 = (lX & 0x40000000);
|
||||
lY4 = (lY & 0x40000000);
|
||||
lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
|
||||
if (lX4 & lY4) return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
|
||||
if (lX4 | lY4) {
|
||||
if (lResult & 0x40000000) return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
|
||||
else return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
|
||||
} else return (lResult ^ lX8 ^ lY8);
|
||||
}
|
||||
|
||||
function F(x, y, z) {
|
||||
return (x & y) | ((~x) & z);
|
||||
}
|
||||
|
||||
function G(x, y, z) {
|
||||
return (x & z) | (y & (~z));
|
||||
}
|
||||
|
||||
function H(x, y, z) {
|
||||
return (x ^ y ^ z);
|
||||
}
|
||||
|
||||
function I(x, y, z) {
|
||||
return (y ^ (x | (~z)));
|
||||
}
|
||||
|
||||
function FF(a, b, c, d, x, s, ac) {
|
||||
a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
|
||||
return AddUnsigned(RotateLeft(a, s), b);
|
||||
}
|
||||
|
||||
function GG(a, b, c, d, x, s, ac) {
|
||||
a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
|
||||
return AddUnsigned(RotateLeft(a, s), b);
|
||||
}
|
||||
|
||||
function HH(a, b, c, d, x, s, ac) {
|
||||
a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
|
||||
return AddUnsigned(RotateLeft(a, s), b);
|
||||
}
|
||||
|
||||
function II(a, b, c, d, x, s, ac) {
|
||||
a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
|
||||
return AddUnsigned(RotateLeft(a, s), b);
|
||||
}
|
||||
|
||||
function ConvertToWordArray(sMessage) {
|
||||
var lWordCount;
|
||||
var lMessageLength = sMessage.length;
|
||||
var lNumberOfWords_temp1 = lMessageLength + 8;
|
||||
var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
|
||||
var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
|
||||
var lWordArray = Array(lNumberOfWords - 1);
|
||||
var lBytePosition = 0;
|
||||
var lByteCount = 0;
|
||||
while (lByteCount < lMessageLength) {
|
||||
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
|
||||
lBytePosition = (lByteCount % 4) * 8;
|
||||
lWordArray[lWordCount] = (lWordArray[lWordCount] | (sMessage.charCodeAt(lByteCount) << lBytePosition));
|
||||
lByteCount++;
|
||||
}
|
||||
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
|
||||
lBytePosition = (lByteCount % 4) * 8;
|
||||
lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
|
||||
lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
|
||||
lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
|
||||
return lWordArray;
|
||||
}
|
||||
|
||||
function WordToHex(lValue) {
|
||||
var WordToHexValue = "", WordToHexValue_temp = "", lByte, lCount;
|
||||
for (lCount = 0; lCount <= 3; lCount++) {
|
||||
lByte = (lValue >>> (lCount * 8)) & 255;
|
||||
WordToHexValue_temp = "0" + lByte.toString(16);
|
||||
WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length - 2, 2);
|
||||
}
|
||||
return WordToHexValue;
|
||||
}
|
||||
|
||||
var x = Array();
|
||||
var k, AA, BB, CC, DD, a, b, c, d
|
||||
var S11 = 7, S12 = 12, S13 = 17, S14 = 22;
|
||||
var S21 = 5, S22 = 9 , S23 = 14, S24 = 20;
|
||||
var S31 = 4, S32 = 11, S33 = 16, S34 = 23;
|
||||
var S41 = 6, S42 = 10, S43 = 15, S44 = 21;
|
||||
// Steps 1 and 2. Append padding bits and length and convert to words
|
||||
x = ConvertToWordArray(sMessage);
|
||||
// Step 3. Initialise
|
||||
a = 0x67452301;
|
||||
b = 0xEFCDAB89;
|
||||
c = 0x98BADCFE;
|
||||
d = 0x10325476;
|
||||
// Step 4. Process the message in 16-word blocks
|
||||
for (k = 0; k < x.length; k += 16) {
|
||||
AA = a;
|
||||
BB = b;
|
||||
CC = c;
|
||||
DD = d;
|
||||
a = FF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
|
||||
d = FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
|
||||
c = FF(c, d, a, b, x[k + 2], S13, 0x242070DB);
|
||||
b = FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
|
||||
a = FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
|
||||
d = FF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
|
||||
c = FF(c, d, a, b, x[k + 6], S13, 0xA8304613);
|
||||
b = FF(b, c, d, a, x[k + 7], S14, 0xFD469501);
|
||||
a = FF(a, b, c, d, x[k + 8], S11, 0x698098D8);
|
||||
d = FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
|
||||
c = FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
|
||||
b = FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
|
||||
a = FF(a, b, c, d, x[k + 12], S11, 0x6B901122);
|
||||
d = FF(d, a, b, c, x[k + 13], S12, 0xFD987193);
|
||||
c = FF(c, d, a, b, x[k + 14], S13, 0xA679438E);
|
||||
b = FF(b, c, d, a, x[k + 15], S14, 0x49B40821);
|
||||
a = GG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
|
||||
d = GG(d, a, b, c, x[k + 6], S22, 0xC040B340);
|
||||
c = GG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
|
||||
b = GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
|
||||
a = GG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
|
||||
d = GG(d, a, b, c, x[k + 10], S22, 0x2441453);
|
||||
c = GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
|
||||
b = GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
|
||||
a = GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
|
||||
d = GG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
|
||||
c = GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
|
||||
b = GG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
|
||||
a = GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
|
||||
d = GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
|
||||
c = GG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
|
||||
b = GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
|
||||
a = HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
|
||||
d = HH(d, a, b, c, x[k + 8], S32, 0x8771F681);
|
||||
c = HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
|
||||
b = HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
|
||||
a = HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
|
||||
d = HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
|
||||
c = HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
|
||||
b = HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
|
||||
a = HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
|
||||
d = HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
|
||||
c = HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
|
||||
b = HH(b, c, d, a, x[k + 6], S34, 0x4881D05);
|
||||
a = HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
|
||||
d = HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
|
||||
c = HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
|
||||
b = HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
|
||||
a = II(a, b, c, d, x[k + 0], S41, 0xF4292244);
|
||||
d = II(d, a, b, c, x[k + 7], S42, 0x432AFF97);
|
||||
c = II(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
|
||||
b = II(b, c, d, a, x[k + 5], S44, 0xFC93A039);
|
||||
a = II(a, b, c, d, x[k + 12], S41, 0x655B59C3);
|
||||
d = II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
|
||||
c = II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
|
||||
b = II(b, c, d, a, x[k + 1], S44, 0x85845DD1);
|
||||
a = II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
|
||||
d = II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
|
||||
c = II(c, d, a, b, x[k + 6], S43, 0xA3014314);
|
||||
b = II(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
|
||||
a = II(a, b, c, d, x[k + 4], S41, 0xF7537E82);
|
||||
d = II(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
|
||||
c = II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
|
||||
b = II(b, c, d, a, x[k + 9], S44, 0xEB86D391);
|
||||
a = AddUnsigned(a, AA);
|
||||
b = AddUnsigned(b, BB);
|
||||
c = AddUnsigned(c, CC);
|
||||
d = AddUnsigned(d, DD);
|
||||
}
|
||||
// Step 5. Output the 128 bit digest
|
||||
var temp;
|
||||
if (undefined != fullSize && null != fullSize) {
|
||||
temp = WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d);
|
||||
} else {
|
||||
temp = WordToHex(a) + WordToHex(b) + WordToHex(c);
|
||||
}
|
||||
return temp.toLowerCase();
|
||||
}
|
||||
|
||||
exports.MD5 = MD5;
|
||||
71
src/web_console/mini_poem/data_set/ali_oss.js
Normal file
71
src/web_console/mini_poem/data_set/ali_oss.js
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Created by Strawmanbobi
|
||||
* 2014-08-30
|
||||
*/
|
||||
|
||||
// 'use strict';
|
||||
|
||||
require('../configuration/constants');
|
||||
var ErrorCode = require('../configuration/error_code');
|
||||
var Enums = require('../configuration/enums');
|
||||
|
||||
var stringUtils = require('../utils/string_utils');
|
||||
// deprecated
|
||||
// var AliOSS = require('oss-client');
|
||||
var AliOSS = require('ali-oss');
|
||||
var OssWrapper = require('ali-oss').Wrapper;
|
||||
var logger = require('../logging/logger4js').helper;
|
||||
|
||||
var errorCode = new ErrorCode();
|
||||
var enums = new Enums();
|
||||
|
||||
var OSS = function(_region, _bucket, _accessKey, _accessSecret) {
|
||||
this.option = {
|
||||
region: _region,
|
||||
bucket: _bucket,
|
||||
accessKeyId: _accessKey || OSS_APP_ID,
|
||||
accessKeySecret: _accessSecret,
|
||||
};
|
||||
this.client = new OssWrapper(this.option);
|
||||
}
|
||||
|
||||
OSS.prototype.saveObjectFromBinary = function(objectID, bufferContent, contentType, callback) {
|
||||
var randomID = stringUtils.randomChar(16);
|
||||
console.log("object ID = " + objectID);
|
||||
if(null == objectID) {
|
||||
objectID = objectID || (null != contentType &&
|
||||
'' != contentType &&
|
||||
contentType.indexOf("/") >= 0) ?
|
||||
randomID + '.' + contentType.substr(contentType.lastIndexOf('/') + 1) :
|
||||
randomID;
|
||||
}
|
||||
this.client.put(objectID, bufferContent).then(function (val) {
|
||||
console.log('result: %j', val);
|
||||
callback(errorCode.SUCCESS, objectID);
|
||||
}).catch (function (err) {
|
||||
console.log('error: %j', err);
|
||||
callback(errorCode.FAILED, null);
|
||||
});
|
||||
};
|
||||
|
||||
OSS.prototype.getObjectByID = function(objectID, filePath, callback) {
|
||||
this.client.get(objectID, filePath).then(function (val) {
|
||||
console.log('result: %j', val);
|
||||
callback(errorCode.SUCCESS, filePath);
|
||||
}).catch (function (err) {
|
||||
console.log('error: %j', err);
|
||||
callback(errorCode.FAILED, null);
|
||||
});
|
||||
};
|
||||
|
||||
OSS.prototype.serveObjectByID = function(objectID, filePath, callback) {
|
||||
this.client.get(objectID, filePath).then(function (val) {
|
||||
console.log('result: %j', val);
|
||||
callback(errorCode.SUCCESS, filePath);
|
||||
}).catch (function (err) {
|
||||
console.log('error: %j', err);
|
||||
callback(errorCode.FAILED, null);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = OSS;
|
||||
24
src/web_console/mini_poem/db/mysql/mysql_connection.js
Normal file
24
src/web_console/mini_poem/db/mysql/mysql_connection.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Created by Strawmanbobi
|
||||
* 2014-09-22
|
||||
*/
|
||||
|
||||
require('../../configuration/constants');
|
||||
var orm = require('orm');
|
||||
var logger = require('../../logging/logger4js').helper;
|
||||
|
||||
var ormOpt;
|
||||
|
||||
exports.setMySQLParameter = function(dbHost, dbName, dbUser, dbPassword) {
|
||||
logger.info("initialize mysql connection, user = " + dbUser);
|
||||
ormOpt = {
|
||||
protocol: "mysql",
|
||||
hostname: dbHost,
|
||||
database: dbName,
|
||||
user: dbUser,
|
||||
password: dbPassword,
|
||||
charset: 'utf8',
|
||||
query: { pool: false }
|
||||
};
|
||||
exports.mysqlDB = orm.connect(ormOpt);
|
||||
};
|
||||
83
src/web_console/mini_poem/external/python_caller.js
vendored
Normal file
83
src/web_console/mini_poem/external/python_caller.js
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2015-08-03.
|
||||
*/
|
||||
|
||||
var pythonShell = require('python-shell');
|
||||
|
||||
var constants = require('../configuration/constants.js');
|
||||
var logger = require('../logging/logger4js').helper;
|
||||
|
||||
var ErrorCode = require('../configuration/error_code.js');
|
||||
|
||||
var errorCode = new ErrorCode();
|
||||
|
||||
var PythonCaller = function() {
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Call python script from application
|
||||
*
|
||||
* input parameters : Script run-time base dir
|
||||
* Script script filename
|
||||
* User determined arguments ...
|
||||
* Call back function
|
||||
*
|
||||
* return : Error code of python caller
|
||||
*/
|
||||
PythonCaller.prototype.call = function() {
|
||||
var userArgIndex = 0;
|
||||
var numArgs = arguments.length;
|
||||
var callback = null;
|
||||
var scriptPath = null;
|
||||
var scriptName = null;
|
||||
var userArguments = [];
|
||||
if(numArgs < 3) {
|
||||
logger.error("internal error while calling python script from application : no script specified");
|
||||
// TODO: specify the error code for this type of error
|
||||
throw errorCode.PYTHON_ARGUMENTS_ERROR;
|
||||
} else {
|
||||
callback = arguments[numArgs - 1];
|
||||
if((typeof callback != 'function')) {
|
||||
logger.error('internal error while calling python script from application : no callback specified');
|
||||
throw errorCode.PYTHON_CALLBACK_NOT_SPECIFIED;
|
||||
} else {
|
||||
scriptPath = arguments[0];
|
||||
scriptName = arguments[1];
|
||||
if(null == scriptPath || 'undefined' == scriptPath || null == scriptName || 'undefined' == scriptName) {
|
||||
logger.error('internal error while calling python script from application : no script path specified');
|
||||
// TODO: specify the error code for this type of error
|
||||
throw errorCode.PYTHON_SCRIPT_PATH_NOT_SPECIFIED;
|
||||
} else {
|
||||
// parse user arguments from python caller
|
||||
var args = arguments[2];
|
||||
for(userArgIndex = 0; userArgIndex < args.length; userArgIndex++) {
|
||||
userArguments.push(args[userArgIndex]);
|
||||
}
|
||||
// logger.info("user arguments = " + userArguments);
|
||||
var options = {
|
||||
mode: 'text',
|
||||
pythonPath: PYTHON_PATH,
|
||||
pythonOptions: ['-u'],
|
||||
scriptPath: scriptPath, // the base path of python run-time
|
||||
args: userArguments
|
||||
};
|
||||
|
||||
pythonShell.run(scriptName, options, function (err, results) {
|
||||
if (err) {
|
||||
logger.error('python executing with error : ' + err);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
// results is an array consisting of messages collected during execution
|
||||
logger.info('python executed successfully, results = %j', results);
|
||||
callback(errorCode.SUCCESS, results);
|
||||
}
|
||||
});
|
||||
return errorCode.PYTHON_SCRIPT_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = PythonCaller;
|
||||
131
src/web_console/mini_poem/http/request.js
Normal file
131
src/web_console/mini_poem/http/request.js
Normal file
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* Created by Strawmanbobi
|
||||
* 2014-08-30
|
||||
*/
|
||||
|
||||
// system inclusion
|
||||
var queryString = require('querystring');
|
||||
var http = require('http');
|
||||
var request = require('request');
|
||||
|
||||
// local inclusion
|
||||
var Map = require('../mem/map.js');
|
||||
var ErrorCode = require('../configuration/error_code.js');
|
||||
|
||||
var errorCode = new ErrorCode();
|
||||
|
||||
var logger = require('../logging/logger4js').helper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param _host : host of service server
|
||||
* @param _port : port of service server
|
||||
* @param _service : service URL parameter
|
||||
* @param _queryParams : map of query parameters
|
||||
* @constructor
|
||||
*/
|
||||
var Request = function(_host, _port, _service, _queryParams) {
|
||||
this.host = _host;
|
||||
this.port = _port;
|
||||
this.service = _service;
|
||||
this.queryParams = _queryParams;
|
||||
};
|
||||
|
||||
Request.prototype.urlizeQueryParams = function() {
|
||||
var i = 0;
|
||||
var urlParams = "";
|
||||
var paramElement = null;
|
||||
if(undefined == this.queryParams || null == this.queryParams) {
|
||||
return "";
|
||||
}
|
||||
if(this.queryParams instanceof Map) {
|
||||
for(i = 0; i < this.queryParams.size(); i++) {
|
||||
paramElement = this.queryParams.element(i);
|
||||
if(0 == i) {
|
||||
urlParams += "?";
|
||||
} else {
|
||||
urlParams += "&";
|
||||
}
|
||||
urlParams += paramElement.key + "=" + paramElement.value;
|
||||
}
|
||||
return urlParams;
|
||||
}
|
||||
return "";
|
||||
};
|
||||
|
||||
Request.prototype.sendGetRequest = function(options, callback) {
|
||||
var data = "";
|
||||
var httpTag = options.https ? "https://" : "http://";
|
||||
var url = httpTag + this.host + ":" + this.port + this.service +
|
||||
this.urlizeQueryParams();
|
||||
|
||||
if(options.https) {
|
||||
request(
|
||||
{ method: 'GET'
|
||||
, uri: url
|
||||
}, function (error, response, body) {
|
||||
if(!error && response.statusCode == '200') {
|
||||
callback(errorCode.SUCCESS, JSON.parse(body));
|
||||
} else {
|
||||
callback(errorCode.FAILED, null);
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
http.get(url, function(res) {
|
||||
res.on('data', function (chunk) {
|
||||
data += chunk;
|
||||
});
|
||||
res.on('end', function() {
|
||||
if('200' == res.statusCode) {
|
||||
callback(errorCode.SUCCESS, data);
|
||||
} else {
|
||||
console.error('HTTP request fault !!');
|
||||
callback(errorCode.FAILED, null);
|
||||
}
|
||||
});
|
||||
res.on('error', function(e) {
|
||||
console.error("error occurred when handling response : " + e);
|
||||
callback(errorCode.FAILED, null);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Request.prototype.sendPostRequest = function(bodyData, callback) {
|
||||
var requestData = JSON.stringify(bodyData);
|
||||
var url = this.service +
|
||||
this.urlizeQueryParams();
|
||||
var options = {
|
||||
host: this.host,
|
||||
port: this.port,
|
||||
path: url,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
var req = http.request(options, function(res) {
|
||||
var data = '';
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', function (chunk) {
|
||||
data += chunk;
|
||||
});
|
||||
res.on('end', function() {
|
||||
if('200' == res.statusCode) {
|
||||
callback(errorCode.SUCCESS, data);
|
||||
} else {
|
||||
callback(errorCode.FAILED, null);
|
||||
}
|
||||
});
|
||||
});
|
||||
try {
|
||||
req.write(requestData);
|
||||
req.end();
|
||||
} catch(e) {
|
||||
console.error("exception occurred in http request : " + e);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Request;
|
||||
121
src/web_console/mini_poem/logging/logger4js.js
Normal file
121
src/web_console/mini_poem/logging/logger4js.js
Normal file
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* Created by donna
|
||||
* 2014-08-30
|
||||
*/
|
||||
|
||||
require('../configuration/constants');
|
||||
var Enums = require('../configuration/enums');
|
||||
var log4js = require('log4js');
|
||||
var enums = new Enums();
|
||||
|
||||
var helper = helper || {};
|
||||
exports.helper = helper;
|
||||
|
||||
var logRoot = "./logs/";
|
||||
var userDebugLogFolder = "user_debug/";
|
||||
var devLogFolder = "dev/";
|
||||
var productionLogFolder = "production/";
|
||||
var logFile = "common.log";
|
||||
|
||||
log4js.configure({
|
||||
"appenders": [
|
||||
{
|
||||
type: 'console',
|
||||
category: "console"
|
||||
},
|
||||
{
|
||||
type: "dateFile",
|
||||
filename: logRoot + productionLogFolder + logFile,
|
||||
pattern: "-yyyy-MM-dd",
|
||||
alwaysIncludePattern: false,
|
||||
maxLogSize: 1024,
|
||||
category: 'userProductionLog'
|
||||
},
|
||||
{
|
||||
type: "dateFile",
|
||||
filename: logRoot + userDebugLogFolder + logFile,
|
||||
pattern: "-yyyy-MM-dd",
|
||||
alwaysIncludePattern: false,
|
||||
maxLogSize: 1024,
|
||||
category: 'userDebugLog'
|
||||
},
|
||||
{
|
||||
type: "dateFile",
|
||||
filename: logRoot + devLogFolder + logFile,
|
||||
pattern: "-yyyy-MM-dd",
|
||||
alwaysIncludePattern: false,
|
||||
maxLogSize: 1024,
|
||||
category: 'userDevelopmentLog'
|
||||
}
|
||||
],
|
||||
replaceConsole: true,
|
||||
levels: {
|
||||
userProductionLog: 'INFO',
|
||||
userDebugLog: 'INFO',
|
||||
userDevelopmentLog: 'INFO'
|
||||
}
|
||||
});
|
||||
|
||||
var userProductionLog = log4js.getLogger('userProductionLog');
|
||||
var userDebugLog = log4js.getLogger('userDebugLog');
|
||||
var userDevelopmentLog = log4js.getLogger('userDevelopmentLog');
|
||||
|
||||
helper.info = function (msg) {
|
||||
if(enums.APP_DEVELOPMENT_MODE == ENV) {
|
||||
console.log(msg);
|
||||
} else if(enums.APP_PRODUCTION_MODE == ENV) {
|
||||
userProductionLog.info(msg);
|
||||
} else {
|
||||
userDebugLog.info(msg);
|
||||
}
|
||||
};
|
||||
|
||||
helper.error = function (msg) {
|
||||
if(enums.APP_DEVELOPMENT_MODE == ENV) {
|
||||
console.log(msg);
|
||||
} else if(enums.APP_PRODUCTION_MODE == ENV) {
|
||||
userProductionLog.error(msg);
|
||||
} else {
|
||||
userDebugLog.error(msg);
|
||||
}
|
||||
};
|
||||
|
||||
helper.warn = function (msg) {
|
||||
if(enums.APP_DEVELOPMENT_MODE == ENV) {
|
||||
console.log(msg);
|
||||
} else if(enums.APP_PRODUCTION_MODE == ENV) {
|
||||
userProductionLog.warn(msg);
|
||||
} else {
|
||||
userDebugLog.warn(msg);
|
||||
}
|
||||
};
|
||||
|
||||
helper.debug = function (msg) {
|
||||
if(enums.APP_DEVELOPMENT_MODE == ENV) {
|
||||
console.log(msg);
|
||||
} else if(enums.APP_PRODUCTION_MODE == ENV) {
|
||||
userProductionLog.debug(msg);
|
||||
} else {
|
||||
userDebugLog.debug(msg);
|
||||
}
|
||||
};
|
||||
|
||||
helper.trace = function (msg) {
|
||||
if(enums.APP_DEVELOPMENT_MODE == ENV) {
|
||||
console.log(msg);
|
||||
} else if(enums.APP_PRODUCTION_MODE == ENV) {
|
||||
userProductionLog.trace(msg);
|
||||
} else {
|
||||
userDebugLog.trace(msg);
|
||||
}
|
||||
};
|
||||
|
||||
helper.fatal = function (msg) {
|
||||
if(enums.APP_DEVELOPMENT_MODE == ENV) {
|
||||
console.log(msg);
|
||||
} else if(enums.APP_PRODUCTION_MODE == ENV) {
|
||||
userProductionLog.fatal(msg);
|
||||
} else {
|
||||
userDebugLog.fatal(msg);
|
||||
}
|
||||
};
|
||||
111
src/web_console/mini_poem/utils/date_utils.js
Normal file
111
src/web_console/mini_poem/utils/date_utils.js
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Created by Strawmanbobi
|
||||
* 2014-08-30
|
||||
*/
|
||||
|
||||
function formatDate(date, fmt) {
|
||||
var o = {
|
||||
"M+" : date.getMonth() + 1,
|
||||
"d+" : date.getDate(),
|
||||
"h+" : date.getHours(),
|
||||
"m+" : date.getMinutes(),
|
||||
"s+" : date.getSeconds(),
|
||||
"q+" : Math.floor((date.getMonth() + 3) / 3),
|
||||
"S" : date.getMilliseconds()
|
||||
};
|
||||
if(/(y+)/.test(fmt))
|
||||
fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
|
||||
for(var k in o)
|
||||
if(new RegExp("("+ k +")").test(fmt))
|
||||
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
|
||||
return fmt;
|
||||
}
|
||||
|
||||
function getNextDay(dateString) {
|
||||
var nextDayStr;
|
||||
var nextMonthStr;
|
||||
var nextYearStr;
|
||||
var currentDate = new Date(dateString);
|
||||
var nextDate = new Date(currentDate.getTime() + 24 * 60 * 60 * 1000);
|
||||
var nextDay = nextDate.getDate();
|
||||
if(nextDay < 10) {
|
||||
nextDayStr = "0" + nextDay;
|
||||
} else {
|
||||
nextDayStr = nextDay;
|
||||
}
|
||||
var nextMonth = nextDate.getMonth() + 1;
|
||||
if(nextMonth < 10) {
|
||||
nextMonthStr = "0" + nextMonth;
|
||||
} else {
|
||||
nextMonthStr = nextMonth;
|
||||
}
|
||||
nextYearStr = nextDate.getFullYear();
|
||||
return nextYearStr + "-" + nextMonthStr + "-" + nextDayStr;
|
||||
}
|
||||
|
||||
function getPreviousDay(dateString) {
|
||||
var lastDayStr;
|
||||
var lastMonthStr;
|
||||
var lastYearStr;
|
||||
var currentDate = new Date(dateString);
|
||||
var lastDate = new Date(currentDate.getTime() - 24 * 60 * 60 * 1000);
|
||||
var lastDay = lastDate.getDate();
|
||||
if(lastDay < 10) {
|
||||
lastDayStr = "0" + lastDay;
|
||||
} else {
|
||||
lastDayStr = lastDay;
|
||||
}
|
||||
var lastMonth = lastDate.getMonth() + 1;
|
||||
if(lastMonth < 10) {
|
||||
lastMonthStr = "0" + lastMonth;
|
||||
} else {
|
||||
lastMonthStr = lastMonth;
|
||||
}
|
||||
lastYearStr = lastDate.getFullYear();
|
||||
return lastYearStr + "-" + lastMonthStr + "-" + lastDayStr;
|
||||
}
|
||||
|
||||
function getDateDiffer(startTime, endTime, diffType) {
|
||||
startTime = startTime.replace(/\-/g, "/");
|
||||
endTime = endTime.replace(/\-/g, "/");
|
||||
|
||||
diffType = diffType.toLowerCase();
|
||||
var sTime = new Date(startTime);
|
||||
var eTime = new Date(endTime);
|
||||
var divNum = 1;
|
||||
switch (diffType) {
|
||||
case "second":
|
||||
divNum = 1000;
|
||||
break;
|
||||
case "minute":
|
||||
divNum = 1000 * 60;
|
||||
break;
|
||||
case "hour":
|
||||
divNum = 1000 * 3600;
|
||||
break;
|
||||
case "day":
|
||||
divNum = 1000 * 3600 * 24;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return parseInt((eTime.getTime() - sTime.getTime()) / parseInt(divNum));
|
||||
}
|
||||
|
||||
function dateDiff(sDate1, sDate2) {
|
||||
|
||||
var aDate, oDate1, oDate2, iDays;
|
||||
aDate = sDate1.split("-");
|
||||
oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]); //转换为yyyy-MM-dd格式
|
||||
aDate = sDate2.split("-");
|
||||
oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
|
||||
iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24); //把相差的毫秒数转换为天数
|
||||
|
||||
return iDays;
|
||||
}
|
||||
|
||||
exports.getNextDay = getNextDay;
|
||||
exports.getPreviousDay = getPreviousDay;
|
||||
exports.getDateDiffer = getDateDiffer;
|
||||
exports.formatDate = formatDate;
|
||||
exports.dateDiff = dateDiff;
|
||||
120
src/web_console/mini_poem/utils/map.js
Normal file
120
src/web_console/mini_poem/utils/map.js
Normal file
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* Created by Strawmanbobi
|
||||
* 2014-03-14
|
||||
*/
|
||||
|
||||
var Map = function() {
|
||||
this.elements = [];
|
||||
};
|
||||
|
||||
Map.prototype.size = function() {
|
||||
return this.elements.length;
|
||||
};
|
||||
|
||||
Map.prototype.isEmpty = function() {
|
||||
return (this.elements.length < 1);
|
||||
};
|
||||
|
||||
Map.prototype.clear = function() {
|
||||
this.elements = [];
|
||||
};
|
||||
|
||||
Map.prototype.put = function(_key, _value) {
|
||||
this.elements.push( {
|
||||
key : _key,
|
||||
value : _value
|
||||
});
|
||||
};
|
||||
|
||||
Map.prototype.remove = function(_key) {
|
||||
var bln = false;
|
||||
try {
|
||||
for (i = 0; i < this.elements.length; i++) {
|
||||
if (this.elements[i].key == _key) {
|
||||
this.elements.splice(i, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
bln = false;
|
||||
}
|
||||
return bln;
|
||||
};
|
||||
|
||||
Map.prototype.get = function(_key) {
|
||||
try {
|
||||
for (i = 0; i < this.elements.length; i++) {
|
||||
if (this.elements[i].key == _key) {
|
||||
return this.elements[i].value;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
Map.prototype.set = function(_key, _value) {
|
||||
for(i = 0; i < this.elements.length; i++) {
|
||||
if (this.elements[i].key == _key) {
|
||||
this.elements[i].value = _value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.elements.push({
|
||||
key : _key,
|
||||
value : _value
|
||||
});
|
||||
};
|
||||
|
||||
Map.prototype.element = function(_index) {
|
||||
if (_index < 0 || _index >= this.elements.length) {
|
||||
return null;
|
||||
}
|
||||
return this.elements[_index];
|
||||
};
|
||||
|
||||
Map.prototype.containsKey = function(_key) {
|
||||
var bln = false;
|
||||
try {
|
||||
for (i = 0; i < this.elements.length; i++) {
|
||||
if (this.elements[i].key == _key) {
|
||||
bln = true;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
bln = false;
|
||||
}
|
||||
return bln;
|
||||
};
|
||||
|
||||
Map.prototype.containsValue = function(_value) {
|
||||
var bln = false;
|
||||
try {
|
||||
for (i = 0; i < this.elements.length; i++) {
|
||||
if (this.elements[i].value == _value) {
|
||||
bln = true;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
bln = false;
|
||||
}
|
||||
return bln;
|
||||
};
|
||||
|
||||
Map.prototype.values = function() {
|
||||
var arr = [];
|
||||
for (i = 0; i < this.elements.length; i++) {
|
||||
arr.push(this.elements[i].value);
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
Map.prototype.keys = function() {
|
||||
var arr = [];
|
||||
for (i = 0; i < this.elements.length; i++) {
|
||||
arr.push(this.elements[i].key);
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
module.exports = Map;
|
||||
22
src/web_console/mini_poem/utils/object_reflection.js
Normal file
22
src/web_console/mini_poem/utils/object_reflection.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Created by Strawmanbobi
|
||||
* 2014-08-30
|
||||
*/
|
||||
|
||||
function objectMemberCount(conditions) {
|
||||
var memberCount = 0;
|
||||
for(var f in conditions) {
|
||||
memberCount++;
|
||||
}
|
||||
var whereClause = "";
|
||||
var index = 0;
|
||||
for(var field in conditions) {
|
||||
whereClause += field + " = '" + conditions[field] + "'";
|
||||
if(index < memberCount - 1) {
|
||||
whereClause += " AND ";
|
||||
}
|
||||
}
|
||||
return whereClause;
|
||||
}
|
||||
|
||||
module.exports = objectMemberCount;
|
||||
38
src/web_console/mini_poem/utils/string_utils.js
Normal file
38
src/web_console/mini_poem/utils/string_utils.js
Normal file
@@ -0,0 +1,38 @@
|
||||
exports.randomChar = function(l) {
|
||||
var x = "0123456789qwertyuioplkjhgfdsazxcvbnm";
|
||||
var tmp = "";
|
||||
for(var i = 0;i < l; i++) {
|
||||
tmp += x.charAt(Math.ceil(Math.random()*100000000)%x.length);
|
||||
}
|
||||
return tmp;
|
||||
};
|
||||
|
||||
exports.randomNumber = function(l) {
|
||||
var x = "0123456789";
|
||||
var tmp = "";
|
||||
for(var i = 0;i < l; i++) {
|
||||
tmp += x.charAt(Math.ceil(Math.random()*100000000)%x.length);
|
||||
}
|
||||
return tmp;
|
||||
};
|
||||
|
||||
exports.validateEmail = function (email) {
|
||||
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
return re.test(email);
|
||||
};
|
||||
|
||||
function rnd() {
|
||||
var today = new Date();
|
||||
var seed = today.getTime();
|
||||
seed = (seed * 9301 + 49297) % 233280;
|
||||
return seed / (233280.0);
|
||||
}
|
||||
|
||||
function cr(number) {
|
||||
return Math.ceil(rnd() * number);
|
||||
}
|
||||
|
||||
function isNumber() {
|
||||
var r = /^[0-9]*[1-9][0-9]*$/;
|
||||
return r.test(str);
|
||||
}
|
||||
32
src/web_console/mini_poem/utils/system_utils.js
Normal file
32
src/web_console/mini_poem/utils/system_utils.js
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Created by Strawmanbobi
|
||||
* 2015-03-02
|
||||
*/
|
||||
|
||||
var dateUtils = require('./date_utils');
|
||||
var platform = require('platform');
|
||||
var UAParser = require('ua-parser-js');
|
||||
|
||||
function startup(expressApp, port, serverName) {
|
||||
if(expressApp && expressApp.listen && typeof(expressApp.listen) == "function") {
|
||||
expressApp.listen(port);
|
||||
|
||||
console.log(serverName +' restful webservice server is listening at port : ' +
|
||||
port + " //" + dateUtils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss"));
|
||||
console.log("driven by " + ICODE);
|
||||
}
|
||||
}
|
||||
|
||||
function getOS() {
|
||||
return platform.os;
|
||||
}
|
||||
|
||||
function getUAInfo(ua) {
|
||||
var parser = new UAParser();
|
||||
var result = parser.setUA(ua).getResult();
|
||||
return result;
|
||||
}
|
||||
|
||||
exports.startup = startup;
|
||||
exports.getOS = getOS;
|
||||
exports.getUAInfo = getUAInfo;
|
||||
@@ -4,9 +4,9 @@
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var orm = require('../../../Infrastructure/BackEnd/node_modules/orm');
|
||||
var dbOrm = require('../../../Infrastructure/BackEnd/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var orm = require('../mini_poem/node_modules/orm');
|
||||
var dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var orm = require('../../../Infrastructure/BackEnd/node_modules/orm');
|
||||
var dbOrm = require('../../../Infrastructure/BackEnd/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var dateUtils = require('../../../Infrastructure/BackEnd/utils/date_utils.js');
|
||||
var orm = require('../mini_poem/node_modules/orm');
|
||||
var dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
var dateUtils = require('../mini_poem/utils/date_utils.js');
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var orm = require('../../../Infrastructure/BackEnd/node_modules/orm');
|
||||
var dbOrm = require('../../../Infrastructure/BackEnd/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var dateUtils = require('../../../Infrastructure/BackEnd/utils/date_utils.js');
|
||||
var orm = require('../mini_poem/node_modules/orm');
|
||||
var dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
var dateUtils = require('../mini_poem/utils/date_utils.js');
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var orm = require('../../../Infrastructure/BackEnd/node_modules/orm');
|
||||
var dbOrm = require('../../../Infrastructure/BackEnd/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var orm = require('../mini_poem/node_modules/orm');
|
||||
var dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var orm = require('../../../Infrastructure/BackEnd/node_modules/orm');
|
||||
var dbOrm = require('../../../Infrastructure/BackEnd/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var dateUtils = require('../../../Infrastructure/BackEnd/utils/date_utils.js');
|
||||
var orm = require('../mini_poem/node_modules/orm');
|
||||
var dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
var dateUtils = require('../mini_poem/utils/date_utils.js');
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var orm = require('../../../Infrastructure/BackEnd/node_modules/orm');
|
||||
var dbOrm = require('../../../Infrastructure/BackEnd/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var dateUtils = require('../../../Infrastructure/BackEnd/utils/date_utils.js');
|
||||
var orm = require('../mini_poem/node_modules/orm');
|
||||
var dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
var dateUtils = require('../mini_poem/utils/date_utils.js');
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var orm = require('../../../Infrastructure/BackEnd/node_modules/orm');
|
||||
var dbOrm = require('../../../Infrastructure/BackEnd/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var orm = require('../mini_poem/node_modules/orm');
|
||||
var dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var kvConn = require('../../../Infrastructure/BackEnd/db/mongodb/mongodb_connection');
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var Map = require('../../../Infrastructure/BackEnd/mem/map');
|
||||
var kvConn = require('../mini_poem/db/mongodb/mongodb_connection');
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
var Map = require('../mini_poem/mem/map');
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
*/
|
||||
|
||||
// system inclusion
|
||||
var constants = require('../../../Infrastructure/BackEnd/configuration/constants');
|
||||
var constants = require('../mini_poem/configuration/constants');
|
||||
|
||||
// local inclusion
|
||||
var ServiceResponse = require('../response/service_response.js');
|
||||
var LoginResponse = require('../response/login_response.js');
|
||||
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
var certificateLogic = require('../work_unit/certificate_logic.js');
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
// system inclusion
|
||||
var constants = require('../../../Infrastructure/BackEnd/configuration/constants');
|
||||
var constants = require('../mini_poem/configuration/constants');
|
||||
var formidable = require('formidable');
|
||||
var fs = require('fs');
|
||||
|
||||
@@ -17,7 +17,7 @@ var CityResponse = require('../response/city_response.js');
|
||||
var OperatorResponse = require('../response/operator_response.js');
|
||||
var RemoteIndexResponse = require('../response/remote_index_response.js');
|
||||
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
var internalLogic = require('../work_unit/internal_logic.js');
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
// system inclusion
|
||||
var constants = require('../../../Infrastructure/BackEnd/configuration/constants');
|
||||
var constants = require('../mini_poem/configuration/constants');
|
||||
var formidable = require('formidable');
|
||||
var fs = require('fs');
|
||||
|
||||
@@ -13,7 +13,7 @@ var ServiceResponse = require('../response/service_response.js');
|
||||
var StatResponse = require('../response/stat_response.js');
|
||||
var IntegerResponse = require('../response/integer_response');
|
||||
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
var statLogic = require('../work_unit/stat_logic.js');
|
||||
|
||||
|
||||
@@ -3,17 +3,17 @@
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
var Constants = require('../../../Infrastructure/BackEnd/configuration/constants');
|
||||
var Constants = require('../mini_poem/configuration/constants');
|
||||
|
||||
var Admin = require('../model/admin_dao.js');
|
||||
var AdminAuth = require('../authority/admin_auth.js');
|
||||
var MD5 = require('../../../Infrastructure/BackEnd/security/md5.js');
|
||||
var StringUtils = require('../../../Infrastructure/BackEnd/utils/string_utils.js');
|
||||
var MD5 = require('../mini_poem/security/md5.js');
|
||||
var StringUtils = require('../mini_poem/utils/string_utils.js');
|
||||
var nodemailer = require('nodemailer');
|
||||
|
||||
var Enums = require('../constants/enums.js');
|
||||
var ErrorCode = require('../constants/error_code.js');
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
var enums = new Enums();
|
||||
var errorCode = new ErrorCode();
|
||||
|
||||
@@ -8,10 +8,10 @@ fs = require('fs');
|
||||
var crypto = require('crypto');
|
||||
|
||||
// global inclusion
|
||||
var orm = require('../../../Infrastructure/BackEnd/node_modules/orm');
|
||||
var Constants = require('../../../Infrastructure/BackEnd/configuration/constants');
|
||||
var PythonCaller = require('../../../Infrastructure/BackEnd/external/python_caller');
|
||||
var OSS = require('../../../Infrastructure/BackEnd/data_set/ali_oss.js');
|
||||
var orm = require('../mini_poem/node_modules/orm');
|
||||
var Constants = require('../mini_poem/configuration/constants');
|
||||
var PythonCaller = require('../mini_poem/external/python_caller');
|
||||
var OSS = require('../mini_poem/data_set/ali_oss.js');
|
||||
|
||||
var Category = require('../model/category_dao.js');
|
||||
var Brand = require('../model/brand_dao.js');
|
||||
@@ -21,12 +21,12 @@ var RemoteIndex = require('../model/remote_index_dao.js');
|
||||
var StbOperator = require('../model/stb_operator_dao.js');
|
||||
var Admin = require('../model/admin_dao.js');
|
||||
|
||||
var RequestSender = require('../../../Infrastructure/BackEnd/http/request.js');
|
||||
var Map = require('../../../Infrastructure/BackEnd/mem/map.js');
|
||||
var RequestSender = require('../mini_poem/http/request.js');
|
||||
var Map = require('../mini_poem/mem/map.js');
|
||||
|
||||
var Enums = require('../constants/enums.js');
|
||||
var ErrorCode = require('../constants/error_code.js');
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
var enums = new Enums();
|
||||
var errorCode = new ErrorCode();
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
require('../../../Infrastructure/BackEnd/configuration/constants');
|
||||
var RequestSender = require('../../../Infrastructure/BackEnd/http/request.js');
|
||||
var Map = require('../../../Infrastructure/BackEnd/mem/map.js');
|
||||
require('../mini_poem/configuration/constants');
|
||||
var RequestSender = require('../mini_poem/http/request.js');
|
||||
var Map = require('../mini_poem/mem/map.js');
|
||||
|
||||
// local inclusion
|
||||
|
||||
var Enums = require('../constants/enums.js');
|
||||
var ErrorCode = require('../constants/error_code.js');
|
||||
var logger = require('../../../Infrastructure/BackEnd/logging/logger4js').helper;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
var enums = new Enums();
|
||||
var errorCode = new ErrorCode();
|
||||
|
||||
Reference in New Issue
Block a user