[undone] removed Ali-OSS related logic from irext console - 2
This commit is contained in:
@@ -23,6 +23,8 @@ exports.setupEnvironment = function () {
|
|||||||
REDIS_HOST = "localhost";
|
REDIS_HOST = "localhost";
|
||||||
REDIS_PORT = "6379";
|
REDIS_PORT = "6379";
|
||||||
REDIS_PASSWORD = "";
|
REDIS_PASSWORD = "";
|
||||||
|
PRIMARY_SERVER_ADDRESS = "irext.net"
|
||||||
|
PRIMARY_SERVER_PORT = "80"
|
||||||
} else if (enums.APP_DEVELOPMENT_MODE == env) {
|
} else if (enums.APP_DEVELOPMENT_MODE == env) {
|
||||||
MYSQL_DB_SERVER_ADDRESS = "localhost";
|
MYSQL_DB_SERVER_ADDRESS = "localhost";
|
||||||
MYSQL_DB_NAME = "irext";
|
MYSQL_DB_NAME = "irext";
|
||||||
@@ -36,6 +38,8 @@ exports.setupEnvironment = function () {
|
|||||||
REDIS_HOST = "localhost";
|
REDIS_HOST = "localhost";
|
||||||
REDIS_PORT = "6379";
|
REDIS_PORT = "6379";
|
||||||
REDIS_PASSWORD = "";
|
REDIS_PASSWORD = "";
|
||||||
|
PRIMARY_SERVER_ADDRESS = "irext.net"
|
||||||
|
PRIMARY_SERVER_PORT = "80"
|
||||||
} else if (enums.APP_USERDEBUG_MODE == env) {
|
} else if (enums.APP_USERDEBUG_MODE == env) {
|
||||||
MYSQL_DB_SERVER_ADDRESS = "localhost";
|
MYSQL_DB_SERVER_ADDRESS = "localhost";
|
||||||
MYSQL_DB_NAME = "irext";
|
MYSQL_DB_NAME = "irext";
|
||||||
@@ -49,5 +53,7 @@ exports.setupEnvironment = function () {
|
|||||||
REDIS_HOST = "localhost";
|
REDIS_HOST = "localhost";
|
||||||
REDIS_PORT = "6379";
|
REDIS_PORT = "6379";
|
||||||
REDIS_PASSWORD = "";
|
REDIS_PASSWORD = "";
|
||||||
|
PRIMARY_SERVER_ADDRESS = "irext.net"
|
||||||
|
PRIMARY_SERVER_PORT = "80"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -8,7 +8,6 @@ var queryString = require('querystring');
|
|||||||
var http = require('http');
|
var http = require('http');
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
|
|
||||||
|
|
||||||
// local inclusion
|
// local inclusion
|
||||||
var Map = require('../mem/map.js');
|
var Map = require('../mem/map.js');
|
||||||
var ErrorCode = require('../configuration/error_code.js');
|
var ErrorCode = require('../configuration/error_code.js');
|
||||||
@@ -62,8 +61,9 @@ Request.prototype.sendGetRequest = function(options, callback) {
|
|||||||
|
|
||||||
if(options.https) {
|
if(options.https) {
|
||||||
request(
|
request(
|
||||||
{ method: 'GET'
|
{
|
||||||
, uri: url
|
method: 'GET',
|
||||||
|
uri: url
|
||||||
}, function (error, response, body) {
|
}, function (error, response, body) {
|
||||||
if(!error && response.statusCode == '200') {
|
if(!error && response.statusCode == '200') {
|
||||||
callback(errorCode.SUCCESS, JSON.parse(body));
|
callback(errorCode.SUCCESS, JSON.parse(body));
|
||||||
@@ -129,4 +129,24 @@ Request.prototype.sendPostRequest = function(bodyData, callback) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// post simple file to HTTP server
|
||||||
|
Request.prototype.postSimpleFile = function(fileName, fileContent, contentType, options, callback) {
|
||||||
|
var httpTag = options.https ? "https://" : "http://";
|
||||||
|
var url = httpTag + this.host + ":" + this.port + this.service +
|
||||||
|
this.urlizeQueryParams();
|
||||||
|
|
||||||
|
var req = request.post(url, function (err, resp, body) {
|
||||||
|
if (err) {
|
||||||
|
callback(errorCode.FAILED, resp);
|
||||||
|
} else {
|
||||||
|
callback(errorCode.SUCCESS, resp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var form = req.form();
|
||||||
|
form.append('file', fileContent, {
|
||||||
|
filename: fileName,
|
||||||
|
contentType: contentType
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = Request;
|
module.exports = Request;
|
||||||
|
|||||||
7
src/web_console/package.json
Normal file
7
src/web_console/package.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"name": "application-name",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"dependencies": {
|
||||||
|
"orm": "latest"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,9 @@ npm install python-shell
|
|||||||
echo "npm install request"
|
echo "npm install request"
|
||||||
npm install request
|
npm install request
|
||||||
|
|
||||||
|
echo "npm install form-data"
|
||||||
|
npm install form-data
|
||||||
|
|
||||||
echo "npm install async"
|
echo "npm install async"
|
||||||
npm install async
|
npm install async
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ fs = require('fs');
|
|||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
|
|
||||||
// global inclusion
|
// global inclusion
|
||||||
|
require('../mini_poem/configuration/constants');
|
||||||
var orm = require('orm');
|
var orm = require('orm');
|
||||||
var Constants = require('../mini_poem/configuration/constants');
|
|
||||||
var PythonCaller = require('../mini_poem/external/python_caller');
|
var PythonCaller = require('../mini_poem/external/python_caller');
|
||||||
|
|
||||||
var Category = require('../model/category_dao.js');
|
var Category = require('../model/category_dao.js');
|
||||||
@@ -35,11 +35,6 @@ var async = require('async');
|
|||||||
// relative XML file path
|
// relative XML file path
|
||||||
var PROTOCOL_PATH = "protocol";
|
var PROTOCOL_PATH = "protocol";
|
||||||
|
|
||||||
var DEBUG_BUCKET_NAME = "irext-debug";
|
|
||||||
var USER_DEBUG_BUCKET_NAME = "irext-userdebug";
|
|
||||||
var RELEASE_BUCKET_NAME = "irext-release";
|
|
||||||
var PROTOCOL_BUCKET_NAME = "irext-protocol";
|
|
||||||
|
|
||||||
// out going HTTP request parameters
|
// out going HTTP request parameters
|
||||||
// var PRIMARY_SERVER_ADDRESS = "irext.net";
|
// var PRIMARY_SERVER_ADDRESS = "irext.net";
|
||||||
var PRIMARY_SERVER_ADDRESS = "127.0.0.1";
|
var PRIMARY_SERVER_ADDRESS = "127.0.0.1";
|
||||||
@@ -49,6 +44,7 @@ var REQUEST_APP_KEY = "d6119900556c4c1e629fd92d";
|
|||||||
var REQUEST_APP_TOKEN = "fcac5496cba7a12b3bae34abf061f526";
|
var REQUEST_APP_TOKEN = "fcac5496cba7a12b3bae34abf061f526";
|
||||||
|
|
||||||
var PUBLISH_BRAND_SERVICE = "/irext/remote/publish_brands";
|
var PUBLISH_BRAND_SERVICE = "/irext/remote/publish_brands";
|
||||||
|
var UPLOAD_BINARY_SERVICE = "/irext/remote/upload_binary";
|
||||||
var PUBLISH_REMOTE_INDEX_SERVICE = "/irext/remote/publish_remote_indexes";
|
var PUBLISH_REMOTE_INDEX_SERVICE = "/irext/remote/publish_remote_indexes";
|
||||||
var DELETE_REMOTE_INDEX_SERVICE = "/irext/remote/delete_remote_index";
|
var DELETE_REMOTE_INDEX_SERVICE = "/irext/remote/delete_remote_index";
|
||||||
|
|
||||||
@@ -212,7 +208,6 @@ exports.createRemoteIndexWorkUnit = function(remoteIndex, filePath, contentType,
|
|||||||
var protocolPath;
|
var protocolPath;
|
||||||
var outputPath;
|
var outputPath;
|
||||||
var outputFilePath;
|
var outputFilePath;
|
||||||
var outputFileName;
|
|
||||||
var newRemoteIndex;
|
var newRemoteIndex;
|
||||||
var newACRemoteNumber;
|
var newACRemoteNumber;
|
||||||
var tagType;
|
var tagType;
|
||||||
@@ -272,7 +267,7 @@ exports.createRemoteIndexWorkUnit = function(remoteIndex, filePath, contentType,
|
|||||||
userArgs.push(remoteXMLFilePath);
|
userArgs.push(remoteXMLFilePath);
|
||||||
// set the xml directory as output path
|
// set the xml directory as output path
|
||||||
userArgs.push(fileDir + "/");
|
userArgs.push(fileDir + "/");
|
||||||
var pythonCaller = new PythonCaller();
|
pythonCaller = new PythonCaller();
|
||||||
try {
|
try {
|
||||||
pythonCaller.call(pythonRuntimeDir, pythonFile, userArgs, function(remoteGenErr, genResult) {
|
pythonCaller.call(pythonRuntimeDir, pythonFile, userArgs, function(remoteGenErr, genResult) {
|
||||||
if (errorCode.SUCCESS.code == remoteGenErr) {
|
if (errorCode.SUCCESS.code == remoteGenErr) {
|
||||||
@@ -656,13 +651,12 @@ exports.publishRemoteIndexWorkUnit = function (callback) {
|
|||||||
async.eachSeries(remoteIndexes, function (remoteIndex, innerCallback) {
|
async.eachSeries(remoteIndexes, function (remoteIndex, innerCallback) {
|
||||||
var remoteName = remoteIndex.remote;
|
var remoteName = remoteIndex.remote;
|
||||||
var protocolName = remoteIndex.protocol;
|
var protocolName = remoteIndex.protocol;
|
||||||
var binFileName = fileDir + "/irda_" + protocolName + "_" + remoteName + ".bin";
|
var binFileName = "irda_" + protocolName + "_" + remoteName + ".bin";
|
||||||
logger.info("binary file name = " + binFileName);
|
logger.info("binary file name = " + binFileName);
|
||||||
|
|
||||||
// step 2, copy file to transfer path
|
// step 2, copy file to transfer path
|
||||||
sourceFileName = FILE_TEMP_PATH + "/irda_" + protocolName + "_" +
|
sourceFileName = fileDir + "/" + binFileName;
|
||||||
remoteName + ".bin";
|
targetFileName = fileDir + "/binary_transfer/" + binFileName;
|
||||||
targetFileName = FILE_TEMP_PATH + "/binary_transfer" + "/irda_" + protocolName + "_" +
|
|
||||||
remoteName + ".bin";
|
|
||||||
var readStream = fs.createReadStream(sourceFileName);
|
var readStream = fs.createReadStream(sourceFileName);
|
||||||
var writeStream = fs.createWriteStream(targetFileName);
|
var writeStream = fs.createWriteStream(targetFileName);
|
||||||
readStream.pipe(writeStream);
|
readStream.pipe(writeStream);
|
||||||
@@ -673,8 +667,28 @@ exports.publishRemoteIndexWorkUnit = function (callback) {
|
|||||||
innerCallback();
|
innerCallback();
|
||||||
} else {
|
} else {
|
||||||
logger.info("read remote binary file successfully, file size = " + fileData.length);
|
logger.info("read remote binary file successfully, file size = " + fileData.length);
|
||||||
// TODO: send HTTP post request to release server
|
var queryParams = new Map();
|
||||||
|
queryParams.put("app_key", REQUEST_APP_KEY);
|
||||||
|
queryParams.put("app_token", REQUEST_APP_TOKEN);
|
||||||
|
|
||||||
|
var requestSender =
|
||||||
|
new RequestSender(PRIMARY_SERVER_ADDRESS,
|
||||||
|
PRIMARY_SERVER_PORT,
|
||||||
|
UPLOAD_BINARY_SERVICE,
|
||||||
|
queryParams);
|
||||||
|
var options = {
|
||||||
|
https: false
|
||||||
|
};
|
||||||
|
requestSender.postSimpleFile(binFileName, fileData, 'application/octet-stream',
|
||||||
|
options, function(errorCode, response) {
|
||||||
|
if (errorCode.SUCCESS.code == errorCode.code) {
|
||||||
|
logger.info("upload file successfully to primary server");
|
||||||
|
uploadedRIIds.push(remoteIndex.id);
|
||||||
|
} else {
|
||||||
|
logger.info("upload file failed to primary server");
|
||||||
|
}
|
||||||
|
innerCallback();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
@@ -696,7 +710,6 @@ exports.publishRemoteIndexWorkUnit = function (callback) {
|
|||||||
if (errorCode.SUCCESS.code == findRemoteIndexesErr.code &&
|
if (errorCode.SUCCESS.code == findRemoteIndexesErr.code &&
|
||||||
undefined != remoteIndexes && null != remoteIndexes && remoteIndexes.length > 0) {
|
undefined != remoteIndexes && null != remoteIndexes && remoteIndexes.length > 0) {
|
||||||
// send out going HTTP request to primary server
|
// send out going HTTP request to primary server
|
||||||
|
|
||||||
var queryParams = new Map();
|
var queryParams = new Map();
|
||||||
queryParams.put("app_key", REQUEST_APP_KEY);
|
queryParams.put("app_key", REQUEST_APP_KEY);
|
||||||
queryParams.put("app_token", REQUEST_APP_TOKEN);
|
queryParams.put("app_token", REQUEST_APP_TOKEN);
|
||||||
@@ -872,43 +885,31 @@ exports.createProtocolWorkUnit = function(protocol, filePath, contentType, admin
|
|||||||
callback(errorCode.FAILED);
|
callback(errorCode.FAILED);
|
||||||
} else {
|
} else {
|
||||||
logger.info("read protocol binary successfully, file size = " + fileData.length);
|
logger.info("read protocol binary successfully, file size = " + fileData.length);
|
||||||
|
//////////////////////////////////////
|
||||||
|
// step 4, try register protocol to db
|
||||||
|
var newProtocol = {
|
||||||
|
name: protocolName,
|
||||||
|
status: enums.ITEM_VALID,
|
||||||
|
type: protocolType
|
||||||
|
};
|
||||||
|
|
||||||
var aliOss = new OSS(OSS_HOST, PROTOCOL_BUCKET_NAME, OSS_APP_ID, OSS_APP_SECRET);
|
var conditions = {
|
||||||
remoteProtocolFile = protocolName + ".bin";
|
name: protocolName
|
||||||
aliOss.saveObjectFromBinary(remoteProtocolFile, fileData,
|
};
|
||||||
"application/octet-stream",
|
|
||||||
function (createObjectErr, objectID) {
|
|
||||||
if (errorCode.SUCCESS.code == createObjectErr) {
|
|
||||||
//////////////////////////////////////
|
|
||||||
// step 4, try register protocol to db
|
|
||||||
var newProtocol = {
|
|
||||||
name: protocolName,
|
|
||||||
status: enums.ITEM_VALID,
|
|
||||||
type: protocolType
|
|
||||||
};
|
|
||||||
|
|
||||||
var conditions = {
|
logger.info("irda_tv_protocol.py called successfully, create protocol in DB");
|
||||||
name: protocolName
|
IRProtocol.findIRProtocolByConditions(conditions, function(findIRProtocolErr, IRProtocols) {
|
||||||
};
|
if(errorCode.SUCCESS.code == findIRProtocolErr.code &&
|
||||||
|
null != IRProtocols &&
|
||||||
logger.info("irda_tv_protocol.py called successfully, create protocol in DB");
|
IRProtocols.length > 0) {
|
||||||
IRProtocol.findIRProtocolByConditions(conditions, function(findIRProtocolErr, IRProtocols) {
|
logger.info("protocol " + protocolName + " already exists, nothing to be updated");
|
||||||
if(errorCode.SUCCESS.code == findIRProtocolErr.code &&
|
callback(errorCode.SUCCESS);
|
||||||
null != IRProtocols &&
|
} else {
|
||||||
IRProtocols.length > 0) {
|
IRProtocol.createIRProtocol(newProtocol, function(createIRProtocolErr, createdIRProtocol) {
|
||||||
logger.info("protocol " + protocolName + " already exists, nothing to be updated");
|
callback(createIRProtocolErr);
|
||||||
callback(errorCode.SUCCESS);
|
});
|
||||||
} else {
|
}
|
||||||
IRProtocol.createIRProtocol(newProtocol, function(createIRProtocolErr, createdIRProtocol) {
|
});
|
||||||
callback(createIRProtocolErr);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
logger.error("upload protocol binary file failed");
|
|
||||||
callback(errorCode.FAILED);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user