<commit_before>/**
 * SNS Client middleware
 * @author <NAME>
 */

var clientFactory = require('./clientFactory');

/**
 * get basic info from iframe query
 */
module.exports = function snsInfoMiddleware(snsClients){

  return function (req, res, next){
    var reqQuery = req.query;
    var snsInfo = {}, tmp;
    for(var key in reqQuery){
      tmp = decodeURI(key);
      if(tmp.indexOf("xn_sig_")>=0){ // for renren iframe
        if(snsClients.renren.checkSignature(reqQuery)){
          snsInfo.type = 'renren';
          snsInfo.snsid = reqQuery['xn_sig_user'] || "undefined";
          snsInfo.added = Boolean(reqQuery['xn_sig_added'] == 1);
        } else {
          return res.send('<h1>Bad request</h1>', 400);
        }
        break;
      }
      if(tmp.indexOf("wyx_")>=0){ // for wyx iframe
        snsInfo.type = 'wyx';
        snsInfo.snsid = reqQuery['wyx_user_id'] || "undefined";
        snsInfo.added = true;
        break;
      }
    }
    // if type exists, set a userid
    if(snsInfo.type) snsInfo.userid = snsInfo.type+'.'+snsInfo.snsid;

    // set to request object
    req.snsInfo = snsInfo;<commit_msg>* modify snsid -> snsId, userid -> userId<commit_after>/**
 * SNS Client middleware
 * @author <NAME>
 */

var clientFactory = require('./clientFactory');

/**
 * get basic info from iframe query
 */
module.exports = function snsInfoMiddleware(snsClients){

  return function (req, res, next){
    var reqQuery = req.query;
    var snsInfo = {}, tmp;
    for(var key in reqQuery){
      tmp = decodeURI(key);
      if(tmp.indexOf("xn_sig_")>=0){ // for renren iframe
        if(snsClients.renren.checkSignature(reqQuery)){
          snsInfo.type = 'renren';
          snsInfo.snsId = reqQuery['xn_sig_user'] || "undefined";
          snsInfo.added = Boolean(reqQuery['xn_sig_added'] == 1);
        } else {
          return res.send('<h1>Bad request</h1>', 400);
        }
        break;
      }
      if(tmp.indexOf("wyx_")>=0){ // for wyx iframe
        snsInfo.type = 'wyx';
        snsInfo.snsId = reqQuery['wyx_user_id'] || "undefined";
        snsInfo.added = true;
        break;
      }
    }
    // if type exists, set a userid
    if(snsInfo.type) snsInfo.userId = snsInfo.type+'.'+snsInfo.snsId;

    // set to request object
    req.snsInfo = snsInfo;
{'fraction_non_alphanumeric': 0.15056570931244562, 'fraction_numerical': 0.006962576153176675, 'mean_word_length': 2.4939209726443767, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '461940', 'n_tokens_mistral': 808, 'n_tokens_neox': 797, 'n_words': 166}