<commit_before>var express = require('express');
var schemas = require('../models/schemas');
var router = express.Router();

var User = schemas.User;
var File = schemas.File;

var authenticate = function(req, res, next) {
  if (req.session.currentUser) {
    next();
  } else {
    res.render('index', { message: 'Please log in!' });
  }
};

router.all('*', authenticate);

/* GET file page. */
router.get('/:filename', function(req, res, next) {
  var user = req.session.currentUser;
  var message = 'Logged in as: ' + user.username;

  var filename = req.params.filename;

  File.findOne({ 'username': user.username, 'filename': filename },
               function(err, file) {
    if (file == null) {
      var message = 'File not found!';
      res.render('file', { user: true,
                           filename: req.params.filename,
                           message: message });
      return;
    }

    res.render('file', { user: true,
                         filename: req.params.filename,
                         message: message });
  });
});

router.post('/:filename/query/1', function(req, res, next) {
  var user = req.session.currentUser;
  var filename = req.params.filename;
  File.findOne({ 'username': user.username, 'filename': filename },
               function(err, file) {
    if (err || file == null) {
      res.send({ success: false, message: 'File not found!' });
      return;
    }
    var T = req.body.T;
    var encryptedIndex = -1;
    var found = false;
    for (var i = T.length - 1; i >= 0; --i) {
      if (T[i] in file.D) {
        encryptedIndex = file.D[ T[i] ];
        found = true;
        break;
      }
    }
    if (found) {
      console.log('found!');
      res.send({ success: true, found: true,
                 message: 'Substring found :D',
                 encryptedIndex: encryptedIndex });
    } else {
      res.send({ success: true, found: false, message: 'Substring not found' });
    }
  });
});

router.post('/:filename/query/2', function(req, res, next) {
  var user = req.session.currentUser;
  console.log('got the request! (second round)');
  console.log(req.body.startIndex);
  console.log(req.body.size);
  res.send({ success: true, message: 'something something' });
});


module.exports = router;<commit_msg>server communication round 2<commit_after>var express = require('express');
var schemas = require('../models/schemas');
var router = express.Router();

var User = schemas.User;
var File = schemas.File;

var authenticate = function(req, res, next) {
  if (req.session.currentUser) {
    next();
  } else {
    res.render('index', { message: 'Please log in!' });
  }
};

router.all('*', authenticate);

/* GET file page. */
router.get('/:filename', function(req, res, next) {
  var user = req.session.currentUser;
  var message = 'Logged in as: ' + user.username;

  var filename = req.params.filename;

  File.findOne({ 'username': user.username, 'filename': filename },
               function(err, file) {
    if (file == null) {
      var message = 'File not found!';
      res.render('file', { user: true,
                           filename: req.params.filename,
                           message: message });
      return;
    }

    res.render('file', { user: true,
                         filename: req.params.filename,
                         message: message });
  });
});

router.post('/:filename/query/1', function(req, res, next) {
  var user = req.session.currentUser;
  var filename = req.params.filename;
  File.findOne({ 'username': user.username, 'filename': filename },
               function(err, file) {
    if (err || file == null) {
      res.send({ success: false, message: 'File not found!' });
      return;
    }
    var T = req.body.T;
    var encryptedIndex = -1;
    var found = false;
    for (var i = T.length - 1; i >= 0; --i) {
      if (T[i] in file.D) {
        encryptedIndex = file.D[ T[i] ];
        found = true;
        break;
      }
    }
    if (found) {
      console.log('found!');
      res.send({ success: true, found: true,
                 message: 'Substring found :D',
                 encryptedIndex: encryptedIndex });
    } else {
      res.send({ success: true, found: false, message: 'Substring not found' });
    }
  });
});

router.post('/:filename/query/2', function(req, res, next) {
  var user = req.session.currentUser;
  var filename = req.params.filename;
  var index = req.body.index;
  var length = req.body.length;
  File.findOne({ 'username': user.username, 'filename': filename },
               function(err, file) {
    if (err || file == null) {
      res.send({ success: false, message: 'File not found!' });
      return;
    }
    var C = [];
    for (var i = 0; i < length; ++i) {
      C.push(file.C[i + index]);
    }
    res.send({ success: true, message: 'Returning C', C: C });
  });
});


module.exports = router;
{'fraction_non_alphanumeric': 0.16396802623488418, 'fraction_numerical': 0.0024595203935232628, 'mean_word_length': 2.3219877467665078, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '2523954', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1500, 'n_words': 400}