const fs = require('fs'); const serverEnv = process.env['SERVER_ENV']; function rspErr(rsp, errCode, errMsg) { rsp.send(JSON.stringify({ 'errcode': errCode, 'errmsg': errMsg })); } function rspOk(rsp) { rsp.send(JSON.stringify({ 'errcode': 0, 'errmsg': '' })); } function rspData(rsp, data) { data['errcode'] = 0; data['errmsg'] = ''; rsp.send(JSON.stringify(data)); } function readJsonFromFile(url) { let jsondata = fs.readFileSync(url, "utf8"); let json = JSON.parse(jsondata); return json; } async function sleep(timeout) { return new Promise(function (resolve, reject) { setTimeout(function () { resolve(); }, timeout); }); } function emptyReplace(val, newVal) { return !val ? newVal : val; } function throwError(msg) { console.log(msg); throw msg; } function isOnlineEnv() { return !serverEnv; } function getUtcTime() { return Math.floor((new Date()).getTime() / 1000); } exports.rspErr = rspErr; exports.rspOk = rspOk; exports.rspData = rspData; exports.readJsonFromFile = readJsonFromFile; exports.sleep = sleep; exports.emptyReplace = emptyReplace; exports.throwError = throwError; exports.isOnlineEnv = isOnlineEnv; exports.getUtcTime = getUtcTime;