Commit 18e7d196 authored by Leon Li's avatar Leon Li

Add new file

parent b8244fc6
var httpfunc = require('topsin.httpfunc');
var REQ = httpfunc.argv().request;
var RES = httpfunc.argv().response;
var SinEror = require('topsin.error');
var result = new (require('topsin.responsedata'))();
var DB = require('topsin.database');
var DBNAME = REQ.pathCapture('DBNAME');
var Crypto = require('topsin.crypto');
var _ = require('lodash');
try {
if (REQ.method() != "POST") throw "only support POST method!";
var body = JSON.parse(REQ.body());
var func = _.get(body, 'func');
var paras = _.get(body, 'paras');
if (!_.isString(func)) throw "func must be a string!";
if (!_.isArray(paras)) throw "paras must be an array!";
ver = DB.query(DBNAME, function (q) {
var para_count = paras.length;
if (para_count === 0) {
r = q[func]();
} else if (para_count === 1) {
r = q[func](paras[0]);
} else if (para_count === 2) {
r = q[func](paras[0], paras[1]);
} else if (para_count === 3) {
r = q[func](paras[0], paras[1], paras[2]);
} else {
throw "only support 3 paras.";
}
if (q.lastError().isValid()) throw q.lastError().text();
return r;
});
result.setData(r);
RES.body(result.toJson());
} catch (err) {
result.setErrText(CONFIG.tr(_.toString(err)));
RES.body(result.toJson());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment