<commit_before>'use strict'

var express = require('express')
var compression = require('compression')
var bodyParser = require('body-parser')
var cookieParser = require('cookie-parser')
var Path = require('path')

var Log = require(Path.join(__base, 'src/worker/log.js'))
var LogWorker = new Log({
  module: 'Server'
})

/**
 * Deserve http requests.
 * @constructor
*/
function Server (Worker) {
  this.app = express()
  this.app.use(compression())
  this.app.use(cookieParser())
  this.app.use(bodyParser.json())
  this.app.use(bodyParser.urlencoded({
    extended: true
  }))
  this.app.use(function (req, res, next) {
    if (req.url === '/login.html' || req.url.match(/\/auth\?todo=.*/g) || req.url.match(/\/src\/.*/g)) {
      if (req.url === '/login.html' && req.cookies && Worker.Auth.checkLogged(req.cookies.user, req.cookies.token)) {
        res.redirect('/')
      } else {
        next()
      }
    } else {
      if (req.cookies && Worker.Auth.checkLogged(req.cookies.user, req.cookies.token)) {
        next()
      } else {
        res.redirect('/login.html')
      }
    }
  })
  this.app.use(express.static(Path.join(__base, 'src/public')))

  var port = process.env.PORT || __config.server.port
  this.app.listen(port, function () {
    LogWorker.info(`Server listening at port ${port}`)
  })

  // Client Download file
  this.app.get('/files', function (req, res) {
    if (req.query.f) {
      req.query.f = req.query.f.split('..').join('')
      LogWorker.info(`${req.cookies.user} download file: ${req.query.f}`)
      Worker.Directory.setDownloading(req.query.f)
      var transfert = new Worker.FileTransfert(req, res, function () {
        Worker.Directory.finishDownloading(req.query.f)
      })
    } else {
      res.end(JSON.stringify({
        err: 'File doesn\'t exist.'
      }))
    }
  })

  // client start torrent
  this.app.post('/download-t', function (req, res) {
    if (req.body.url) {
      LogWorker.info(`${req.cookies.user} download torrent: ${req.body.url}`)
      //Worker.Torrent.setDownloader(req.cookies.user, req.body.url)
      Worker.Torrent.start(req.body.url)
      res.end(JSON.stringify({}))
    } else {
      res.end(JSON.stringify({
        err: 'Wrong url.'
      }))
    }
  })

  // client ask list of torrent active
  this.app.post('/list-t', function (req, res) {<commit_msg>remove commentary<commit_after>'use strict'

var express = require('express')
var compression = require('compression')
var bodyParser = require('body-parser')
var cookieParser = require('cookie-parser')
var Path = require('path')

var Log = require(Path.join(__base, 'src/worker/log.js'))
var LogWorker = new Log({
  module: 'Server'
})

/**
 * Deserve http requests.
 * @constructor
*/
function Server (Worker) {
  this.app = express()
  this.app.use(compression())
  this.app.use(cookieParser())
  this.app.use(bodyParser.json())
  this.app.use(bodyParser.urlencoded({
    extended: true
  }))
  this.app.use(function (req, res, next) {
    if (req.url === '/login.html' || req.url.match(/\/auth\?todo=.*/g) || req.url.match(/\/src\/.*/g)) {
      if (req.url === '/login.html' && req.cookies && Worker.Auth.checkLogged(req.cookies.user, req.cookies.token)) {
        res.redirect('/')
      } else {
        next()
      }
    } else {
      if (req.cookies && Worker.Auth.checkLogged(req.cookies.user, req.cookies.token)) {
        next()
      } else {
        res.redirect('/login.html')
      }
    }
  })
  this.app.use(express.static(Path.join(__base, 'src/public')))

  var port = process.env.PORT || __config.server.port
  this.app.listen(port, function () {
    LogWorker.info(`Server listening at port ${port}`)
  })

  // Client Download file
  this.app.get('/files', function (req, res) {
    if (req.query.f) {
      req.query.f = req.query.f.split('..').join('')
      LogWorker.info(`${req.cookies.user} download file: ${req.query.f}`)
      Worker.Directory.setDownloading(req.query.f)
      var transfert = new Worker.FileTransfert(req, res, function () {
        Worker.Directory.finishDownloading(req.query.f)
      })
    } else {
      res.end(JSON.stringify({
        err: 'File doesn\'t exist.'
      }))
    }
  })

  // client start torrent
  this.app.post('/download-t', function (req, res) {
    if (req.body.url) {
      LogWorker.info(`${req.cookies.user} download torrent: ${req.body.url}`)
      Worker.Torrent.setDownloader(req.cookies.user, req.body.url)
      Worker.Torrent.start(req.body.url)
      res.end(JSON.stringify({}))
    } else {
      res.end(JSON.stringify({
        err: 'Wrong url.'
      }))
    }
  })

  // client ask list of torrent active
  this.app.post('/list-t', function (req, res) {
{'fraction_non_alphanumeric': 0.18472696245733788, 'fraction_numerical': 0.0, 'mean_word_length': 2.8121951219512193, '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': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4292820', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1594, 'n_words': 285}