<commit_before>'use strict';
require('./loadenv.js')();
var term = require('../drivers/'+process.env.NSTYPE+'.js');
var Primus = require('primus');
var express = require('express');
var http = require('http');

function Filibuster (services) {
  services = sanitizeInput(services);

  // add multiplex to Primus
  services.primus.use('substream', require('substream'));

  // handle connection
  services.primus.on('connection', function (socket) {
    if (socket.query.type !== 'filibuster') {
      return socket.end();
    }
    term.connect(
      getArgs(socket.query),
      getPtyOptions(socket.query),
      function(err, terminal) {
      if(err) {
        console.error("term returned err:", err);
        return socket.end();
      }
      connectStreams(socket, terminal);
    });
  });

  return services.httpServer;
}

function sanitizeInput (services) {
  // normilize inputs
  if (!services) {
    services = {};
  }
  // select what to add
  if (typeof services.express !== 'function') {
    services.express = express();
  }
  if (typeof services.httpServer !== 'object') {
    services.httpServer = http.createServer(services.express);
  }
  if (typeof services.primus !== 'object') {
    services.primus = new Primus(
      services.httpServer,
      {
        transformer: process.env.SOCKET_TYPE,
        parser: 'JSON'
      });
  }
  if (typeof services.middlewares === 'object') {
    for (var middleware in services.middlewares) {
      if (typeof services.middlewares[middleware] !== 'function') {
        throw new Error("invalid middleware");
      }
      services.primus.before(middleware, services.middlewares[middleware]);
    }
  }
  return services;
}
function connectStreams (socket, terminal) {
  // used for resize and ping events
  setupClientStream(socket.substream('clientEvents'), terminal);

  // used for terminal
  setupTerminalStream(socket.substream('terminal'), terminal);

  // cleanup terminal
  socket.on('end', function() {
    terminal.destroy();
  });<commit_msg>remove unused logic<commit_after>'use strict';
require('./loadenv.js')();
var term = require('../drivers/'+process.env.NSTYPE+'.js');
var Primus = require('primus');
var express = require('express');
var http = require('http');

function Filibuster (services) {
  services = sanitizeInput(services);

  // add multiplex to Primus
  services.primus.use('substream', require('substream'));

  // handle connection
  services.primus.on('connection', function (socket) {
    if (socket.query.type !== 'filibuster') {
      return socket.end();
    }
    term.connect(
      getArgs(socket.query),
      getPtyOptions(socket.query),
      function(err, terminal) {
      if(err) {
        console.error("term returned err:", err);
        return socket.end();
      }
      connectStreams(socket, terminal);
    });
  });

  return services.httpServer;
}

function sanitizeInput (services) {
  // normilize inputs
  if (!services) {
    services = {};
  }
  // select what to add
  if (typeof services.express !== 'function') {
    services.express = express();
  }
  if (typeof services.httpServer !== 'object') {
    services.httpServer = http.createServer(services.express);
  }
  if (typeof services.primus !== 'object') {
    services.primus = new Primus(
      services.httpServer,
      {
        transformer: process.env.SOCKET_TYPE,
        parser: 'JSON'
      });
  }

  return services;
}
function connectStreams (socket, terminal) {
  // used for resize and ping events
  setupClientStream(socket.substream('clientEvents'), terminal);

  // used for terminal
  setupTerminalStream(socket.substream('terminal'), terminal);

  // cleanup terminal
  socket.on('end', function() {
    terminal.destroy();
  });
{'fraction_non_alphanumeric': 0.15036183328866257, 'fraction_numerical': 0.0, 'mean_word_length': 3.324449594438007, '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': '2923880', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1087, 'n_words': 245}