<commit_before>var router = require('express').Router();
var CommentDao = require('../dao/CommentDao');
var filters = require('../filters');

router.get('/page/:topic_id', filters.crossOrigin, function(req, res, next) {
  var sortParams = {},
      queryParams = {
        topic_id: req.params.topic_id
      },
      pageSize = req.query.pagesize || 20,
      pageNum = req.query.pagenum || 0;
  var sortField = req.query.sortfield || 'create_at';
  var sortOrder = req.query.sortorder || 'desc';
  sortParams[sortField] = sortOrder === 'desc' ? -1 : 1;
  var _key = req.query._key || '';
  var s = req.query.s || '';
  if (_key && s) queryParams[_key] = eval('/' + s + '/i');
  CommentDao.page(queryParams, sortParams, pageNum, pageSize).then(function(comments) {
    res.status(200).json({ code: 0, result: comments });
  }).catch(function(error) {
    next(error);
  });
});

router.get('/get/:id', function(req, res, next) {
  var _id = req.params.id;
  CommentDao.getById(_id).then(function(comment) {
    res.status(200).json({ code: 0, result: comment });
  }).catch(function(error) {
    next(error);
  });
});

router.post('/new', filters.crossOrigin, function(req, res, next) {
  var params = req.body;
  params.zan_count = 0;
  params.cai_count = 0;
  params.children = [];
  params.author_ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress;
  params.create_at = new Date().getTime();
  CommentDao.save(params).then(function() {
    res.status(200).json({ code: 0, msg: '评论成功' });
  }).catch(function(error) {
    res.status(200).json({ code: -200, msg: '评论失败', error: error });
  });
});

router.post('/reply/:id', filters.crossOrigin, function(req, res, next) {
  var params = req.body;
  params.author_ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress;
  params.create_at = new Date().getTime();
  CommentDao.getById(_id).then(function(comment) {
    var children = comment.children || [];
    children.push(params);
    CommentDao.update({
      _id: req.params.id
    }, {
      $set: {
        children: children
      }
    }, {}).then(function() {
      res.status(200).json({ code: 0, msg: '评论成功' });
    }).catch(function(error) {
      res.status(200).json({ code: -200, msg: '评论失败', error: error });
    });<commit_msg>bugfix<commit_after>var router = require('express').Router();
var CommentDao = require('../dao/CommentDao');
var filters = require('../filters');

router.get('/page/:topic_id', filters.crossOrigin, function(req, res, next) {
  var sortParams = {},
      queryParams = {
        topic_id: req.params.topic_id
      },
      pageSize = req.query.pagesize || 20,
      pageNum = req.query.pagenum || 0;
  var sortField = req.query.sortfield || 'create_at';
  var sortOrder = req.query.sortorder || 'desc';
  sortParams[sortField] = sortOrder === 'desc' ? -1 : 1;
  var _key = req.query._key || '';
  var s = req.query.s || '';
  if (_key && s) queryParams[_key] = eval('/' + s + '/i');
  CommentDao.page(queryParams, sortParams, pageNum, pageSize).then(function(comments) {
    res.status(200).json({ code: 0, result: comments });
  }).catch(function(error) {
    next(error);
  });
});

router.get('/get/:id', function(req, res, next) {
  var _id = req.params.id;
  CommentDao.getById(_id).then(function(comment) {
    res.status(200).json({ code: 0, result: comment });
  }).catch(function(error) {
    next(error);
  });
});

router.post('/new', filters.crossOrigin, function(req, res, next) {
  var params = req.body;
  params.zan_count = 0;
  params.cai_count = 0;
  params.children = [];
  params.author_ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress;
  params.create_at = new Date().getTime();
  CommentDao.save(params).then(function() {
    res.status(200).json({ code: 0, msg: '评论成功' });
  }).catch(function(error) {
    res.status(200).json({ code: -200, msg: '评论失败', error: error });
  });
});

router.post('/reply/:id', filters.crossOrigin, function(req, res, next) {
  var params = req.body;
  params.author_ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress;
  params.create_at = new Date().getTime();
  CommentDao.getById(req.params.id).then(function(comment) {
    var children = comment.children || [];
    children.push(params);
    CommentDao.update({
      _id: req.params.id
    }, {
      $set: {
        children: children
      }
    }, {}).then(function() {
      res.status(200).json({ code: 0, msg: '评论成功' });
    }).catch(function(error) {
      res.status(200).json({ code: -200, msg: '评论失败', error: error });
    });
{'fraction_non_alphanumeric': 0.19349492438367516, 'fraction_numerical': 0.0145017609281127, 'mean_word_length': 3.6557377049180326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7128876', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1667, 'n_words': 306}