<commit_before>/**
 * Created by raychen on 16/9/14.
 */

//config and test
import {SUCCESS, FAIL, getUser, setUser} from './servers/config'
//services
import {saveUser, login, register} from './servers/service/LoginService';
import {getFlowListData, getCountData, getLangListData, getCoverData} from './servers/service/HomeService'
import {addLang, getAllLanguage, deleteLanguage} from './servers/service/LanguageService'
import {evaluateRecommend, getUserFollowings, getUserFollowers, getUserFollowingsAndFollowersNum, addFeedback, getUserStarRepo, getBestSubRepo, isLanguist} from './servers/service/UserService'
import {addAReopSet, addARepoToSet, getRepoSet, getRepoSetList, getRelatedRecommend, getRepoInfos, addMore, addInfoToList, getRepoLanguage} from './servers/service/RepoService'
import {record_log, getLog} from './servers/service/LogService'
//others
import {starRepo, followUser,unfollowUser, unstarRepo} from './servers/api/github_user'
import {searchRepo} from './servers/api/github_search'

function addRepoAPI(server) {
  //star repo
  server.get('/api/repo/star', (req, res)=> {
    starRepo(req.query.user, req.query.repo, resa => {
      if (resa == SUCCESS) {
        record_log(getUser(), getUser() + ' star repo: ' + req.query.repo + ' SUCCESS!', 'add');
        res.send({res: SUCCESS});
      }
      else {
        record_log(getUser(), getUser() + ' star repo: ' + req.query.repo + ' FAIL!', 'error');
        res.send({res: FAIL});
      }
    });
  });
  //unstar repo
  server.get('/api/repo/star', (req, res)=> {
    unstarRepo(req.query.user, req.query.repo, resa => {
      if (resa == SUCCESS) {
        record_log(getUser(), getUser() + ' unstar repo: ' + req.query.repo + ' SUCCESS!', 'del');
        res.send({res: SUCCESS});
      }
      else {
        record_log(getUser(), getUser() + ' unstar repo: ' + req.query.repo + ' FAIL!', 'error');
        res.send({res: FAIL});
      }
    });
  });
  //add a repo to a repo set
  server.get('/api/repo/addToSet', (req, res) => {
    addARepoToSet(req.query.login, req.query.fullname, req.query.setname, (resa) => {
      if (resa == SUCCESS) {
        record_log(getUser(), getUser() + ' add: ' + req.query.fullname + ' to the set: ' + req.query.setname + ' SUCCESS!', 'add');
        res.send({res: SUCCESS});
      }
      else {
        record_log(getUser(), getUser() + ' add: ' + req.query.fullname + ' to the set: ' + req.query.setname + ' FAIL!', 'error');
        res.send({res: resa});
      }
    })
  });
  //add a repo set
  server.get('/api/repo/addSet', (req, res) => {
    addAReopSet(req.query.login, req.query.setname, (resa) => {
      if (resa == SUCCESS) {
        record_log(getUser(), getUser() + ' add set: ' + req.query.setname + ' SUCCESS!', 'add');
        res.send({res: SUCCESS});
      }
      else {
        record_log(getUser(), getUser() + ' add set: ' + req.query.setname + ' SUCCESS!', 'error');
        res.send({res: resa});
      }
    });
  });
  //search repo
  server.get('/api/search/repo', (req, res) => {
    searchRepo(req.query.q, req.query.sort, req.query.order, req.query.page, (resa) => {
      record_log(getUser(), getUser() + ' search repo: ' + req.query.q + ' and return: ' + resa.length + ' RECORDS', 'query');
      res.send(resa);
    })
  });
  //get set list
  server.get('/api/repo/setList', (req, res) => {
    getRepoSetList(req.query.user, (resa) => {
      record_log(getUser(), getUser() + ' get set list and return: ' + resa.length + ' RECORDS', 'query');
      res.send(resa);
    })
  });
  //get set
  server.get('/api/repo/set', (req, res) => {
    getRepoSet(req.query.user, req.query.setName, (resa) => {
      addInfoToList(req.query.user, resa, true, () => {
        record_log(getUser(), getUser() + ' get set: ' + req.query.setName + ' repos and return: ' + resa.length + ' RECORDS', 'query');
        res.send(resa);
      });
    })
  });
  //get recommend repo
  server.get('/api/repo/related', (req, res) => {
    getRelatedRecommend(req.query.fullName, (resa) => {
      addInfoToList(req.query.user, resa, true, () => {
        record_log(getUser(), getUser() + ' get repo: ' + req.query.fullName + ' related repo and return: ' + resa.length + ' RECORDS', 'query');
        res.send(resa);
      });
    })
  });
  //get repo infos
  server.get('/api/repo/info', (req, res) => {
    getRepoInfos(req.query.fullName, (resa) => {
      record_log(getUser(), getUser() + ' get repo: ' + req.query.fullName + ' info', 'query');
      res.send(resa);
    })
  });
  //get repo languages/tags
  server.get('/api/repo/languages', (req, res) => {
    getRepoLanguage(req.query.fullName, (resa) => {
      record_log(getUser(), getUser() + ' get repo: ' + req.query.fullName + ' languages and return: ' + resa.length + ' RECORDS', 'query');
      res.send(resa);
    })
  });
}

function addUserAPI(server) {
  //follow user
  server.get('/api/user/follow', (req, res)=> {
    followUser(req.query.user, req.query.follow, resa => {
      if (resa == SUCCESS) {
        record_log(getUser(), getUser() + ' follow user: ' + req.query.follow + ' SUCCESS!', 'add');
        res.send({res: SUCCESS});
      }
      else {
        record_log(getUser(), getUser() + ' follow user: ' + req.query.follow + ' SUCCESS!', 'error');
        res.send({res: FAIL});
      }
    });
  });
  //unfollow user
  server.get('/api/user/follow', (req, res)=> {
    unfollowUser(req.query.user, req.query.follow, resa => {
      if (resa == SUCCESS) {
        record_log(getUser(), getUser() + ' unfollow user: ' + req.query.follow + ' SUCCESS!', 'del');
        res.send({res: SUCCESS});
      }
      else {
        record_log(getUser(), getUser() + ' unfollow user: ' + req.query.follow + ' SUCCESS!', 'error');
        res.send({res: FAIL});
      }
    });
  });<commit_msg>fix a bug<commit_after>/**
 * Created by raychen on 16/9/14.
 */

//config and test
import {SUCCESS, FAIL, getUser, setUser} from './servers/config'
//services
import {saveUser, login, register} from './servers/service/LoginService';
import {getFlowListData, getCountData, getLangListData, getCoverData} from './servers/service/HomeService'
import {addLang, getAllLanguage, deleteLanguage} from './servers/service/LanguageService'
import {evaluateRecommend, getUserFollowings, getUserFollowers, getUserFollowingsAndFollowersNum, addFeedback, getUserStarRepo, getBestSubRepo, isLanguist} from './servers/service/UserService'
import {addAReopSet, addARepoToSet, getRepoSet, getRepoSetList, getRelatedRecommend, getRepoInfos, addMore, addInfoToList, getRepoLanguage} from './servers/service/RepoService'
import {record_log, getLog} from './servers/service/LogService'
//others
import {starRepo, followUser,unfollowUser, unstarRepo} from './servers/api/github_user'
import {searchRepo} from './servers/api/github_search'

function addRepoAPI(server) {
  //star repo
  server.get('/api/repo/star', (req, res)=> {
    starRepo(req.query.user, req.query.repo, resa => {
      if (resa == SUCCESS) {
        record_log(getUser(), getUser() + ' star repo: ' + req.query.repo + ' SUCCESS!', 'add');
        res.send({res: SUCCESS});
      }
      else {
        record_log(getUser(), getUser() + ' star repo: ' + req.query.repo + ' FAIL!', 'error');
        res.send({res: FAIL});
      }
    });
  });
  //unstar repo
  server.get('/api/repo/unstar', (req, res)=> {
    unstarRepo(req.query.user, req.query.repo, resa => {
      if (resa == SUCCESS) {
        record_log(getUser(), getUser() + ' unstar repo: ' + req.query.repo + ' SUCCESS!', 'del');
        res.send({res: SUCCESS});
      }
      else {
        record_log(getUser(), getUser() + ' unstar repo: ' + req.query.repo + ' FAIL!', 'error');
        res.send({res: FAIL});
      }
    });
  });
  //add a repo to a repo set
  server.get('/api/repo/addToSet', (req, res) => {
    addARepoToSet(req.query.login, req.query.fullname, req.query.setname, (resa) => {
      if (resa == SUCCESS) {
        record_log(getUser(), getUser() + ' add: ' + req.query.fullname + ' to the set: ' + req.query.setname + ' SUCCESS!', 'add');
        res.send({res: SUCCESS});
      }
      else {
        record_log(getUser(), getUser() + ' add: ' + req.query.fullname + ' to the set: ' + req.query.setname + ' FAIL!', 'error');
        res.send({res: resa});
      }
    })
  });
  //add a repo set
  server.get('/api/repo/addSet', (req, res) => {
    addAReopSet(req.query.login, req.query.setname, (resa) => {
      if (resa == SUCCESS) {
        record_log(getUser(), getUser() + ' add set: ' + req.query.setname + ' SUCCESS!', 'add');
        res.send({res: SUCCESS});
      }
      else {
        record_log(getUser(), getUser() + ' add set: ' + req.query.setname + ' SUCCESS!', 'error');
        res.send({res: resa});
      }
    });
  });
  //search repo
  server.get('/api/search/repo', (req, res) => {
    searchRepo(req.query.q, req.query.sort, req.query.order, req.query.page, (resa) => {
      record_log(getUser(), getUser() + ' search repo: ' + req.query.q + ' and return: ' + resa.length + ' RECORDS', 'query');
      res.send(resa);
    })
  });
  //get set list
  server.get('/api/repo/setList', (req, res) => {
    getRepoSetList(req.query.user, (resa) => {
      record_log(getUser(), getUser() + ' get set list and return: ' + resa.length + ' RECORDS', 'query');
      res.send(resa);
    })
  });
  //get set
  server.get('/api/repo/set', (req, res) => {
    getRepoSet(req.query.user, req.query.setName, (resa) => {
      addInfoToList(req.query.user, resa, true, () => {
        record_log(getUser(), getUser() + ' get set: ' + req.query.setName + ' repos and return: ' + resa.length + ' RECORDS', 'query');
        res.send(resa);
      });
    })
  });
  //get recommend repo
  server.get('/api/repo/related', (req, res) => {
    getRelatedRecommend(req.query.fullName, (resa) => {
      addInfoToList(req.query.user, resa, true, () => {
        record_log(getUser(), getUser() + ' get repo: ' + req.query.fullName + ' related repo and return: ' + resa.length + ' RECORDS', 'query');
        res.send(resa);
      });
    })
  });
  //get repo infos
  server.get('/api/repo/info', (req, res) => {
    getRepoInfos(req.query.fullName, (resa) => {
      record_log(getUser(), getUser() + ' get repo: ' + req.query.fullName + ' info', 'query');
      res.send(resa);
    })
  });
  //get repo languages/tags
  server.get('/api/repo/languages', (req, res) => {
    getRepoLanguage(req.query.fullName, (resa) => {
      record_log(getUser(), getUser() + ' get repo: ' + req.query.fullName + ' languages and return: ' + resa.length + ' RECORDS', 'query');
      res.send(resa);
    })
  });
}

function addUserAPI(server) {
  //follow user
  server.get('/api/user/follow', (req, res)=> {
    followUser(req.query.user, req.query.follow, resa => {
      if (resa == SUCCESS) {
        record_log(getUser(), getUser() + ' follow user: ' + req.query.follow + ' SUCCESS!', 'add');
        res.send({res: SUCCESS});
      }
      else {
        record_log(getUser(), getUser() + ' follow user: ' + req.query.follow + ' SUCCESS!', 'error');
        res.send({res: FAIL});
      }
    });
  });
  //unfollow user
  server.get('/api/user/unfollow', (req, res)=> {
    unfollowUser(req.query.user, req.query.follow, resa => {
      if (resa == SUCCESS) {
        record_log(getUser(), getUser() + ' unfollow user: ' + req.query.follow + ' SUCCESS!', 'del');
        res.send({res: SUCCESS});
      }
      else {
        record_log(getUser(), getUser() + ' unfollow user: ' + req.query.follow + ' SUCCESS!', 'error');
        res.send({res: FAIL});
      }
    });
  });
{'fraction_non_alphanumeric': 0.1939477303988996, 'fraction_numerical': 0.0008596973865199449, 'mean_word_length': 2.9234401349072514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 55, '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': '1593050', 'n_tokens_mistral': 4053, 'n_tokens_neox': 4058, 'n_words': 794}