diff --git a/lib/server/binom.js b/lib/server/binom.js new file mode 100644 index 00000000..ea71be70 --- /dev/null +++ b/lib/server/binom.js @@ -0,0 +1,27 @@ +(function() { + 'use strict'; + + module.exports = binom; + + function binom(name, array) { + var ret; + + if (typeof name !== 'string') + throw(Error('name should be string!')); + + if (!Array.isArray(array)) + throw(Error('array should be array!')); + + array.some(function(item) { + var is = item.name === name; + + if (is) + ret = item; + + return is; + }); + + return ret; + } + +})(); diff --git a/lib/server/rest.js b/lib/server/rest.js index 0679c7c1..38b33271 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -15,8 +15,8 @@ path = require('path'), root = require(DIR + 'root'), + binom = require(DIR + 'binom'), - Util = require(DIR_LIB + 'util'), CloudFunc = require(DIR_LIB + 'cloudfunc'), markdown = require(DIR + 'rest/markdown'), @@ -149,8 +149,8 @@ } function auth(code, callback) { - var storage = Util.findObjByNameInArr(Modules, 'storage'), - gh = Util.findObjByNameInArr(storage, 'GitHub'), + var storage = binom(Modules, 'storage'), + gh = binom(storage, 'GitHub'), env = process.env, key = env.github_key || gh.key,