<commit_before>const path = require('path');
const bodyParser = require('body-parser');
const multer = require('multer')({dest: 'server/controllers/list/uploads/'});
const auth = require('./auth');
const parseJson = bodyParser.json();

// Campaigns
const getCampaigns = require('../controllers/campaign/get-campaigns');
const createCampaign = require('../controllers/campaign/create-campaign');
const deleteCampaigns = require('../controllers/campaign/delete-campaigns');
const exportSentUnsentCSV = require('../controllers/campaign/export-sent-unsent-csv');

// Send campaign
const sendCampaign = require('../controllers/campaign/send-campaign');
const sendTestEmail = require('../controllers/campaign/email/amazon-ses/send-test');

// Templates
const getTemplates = require('../controllers/template/get-templates');
const createTemplate = require('../controllers/template/create-template');
const deleteTemplates = require('../controllers/template/delete-templates');

// Lists
const getLists = require('../controllers/list/get-lists');
const getListSubscribers = require('../controllers/list/get-list-subscribers');
const exportListSubscribersCSV = require('../controllers/list/export-list-subscribers-csv');
const addSubscribers = require('../controllers/list/add-subscribers');
const importCSV = require('../controllers/list/import-csv');
const subscribeToList = require('../controllers/list/subscribe');
const deleteSubscribers = require('../controllers/list/delete-subscribers');
const deleteLists = require('../controllers/list/delete-lists');
const unsubscribe = require('../controllers/subscriber/unsubscribe');

// Analytics
const getClickthroughs = require('../controllers/analytics/get-clickthroughs');
const refresh = require('../controllers/analytics/refresh');
const open = require('../controllers/analytics/open');
const clickthrough = require('../controllers/analytics/clickthrough');

// Settings
const getSettings = require('../controllers/settings/get-settings');
const changeSettings = require('../controllers/settings/changesettings');

// Websocket notifications
const getProfile = require('../controllers/websockets/get-profile');

module.exports = (app, passport, io, redis) => {

  ////////////////////
  /* AUTHENTICATION */
  ////////////////////

  auth(app, passport, isAuth);

  app.get('/logout', isAuth, (req, res) => {
    req.logout();
    res.redirect('/login');
  });

  ////////////////////
  /*      API       */
  ////////////////////

  /* Campaigns */
  // Get a list of all campaigns
  app.get('/api/campaign', apiIsAuth, (req, res) => {
    getCampaigns(req, res);
  });
  // Post new campaign
  app.post('/api/campaign', apiIsAuth, parseJson, (req, res) => {
    createCampaign(req, res);
  });
  // Delete campaign(s)
  app.delete('/api/campaign', apiIsAuth, parseJson, (req, res) => {
    deleteCampaigns(req, res);
  });
  // Export subscribers that emails were not sent/sent to during a campaign
  app.get('/api/campaign/subscribers/csv', apiIsAuth, (req, res) => {
    exportSentUnsentCSV(req, res);
  });

  /* Send */
  // Post to send campaign
  app.post('/api/send', apiIsAuth, parseJson, (req, res) => {
    sendCampaign(req, res, io, redis);
  });
  // Post to send a test email
  app.post('/api/test', apiIsAuth, parseJson, (req, res) => {
    sendTestEmail(req, res);
  });

  /* Templates */
  // Get a list of all templates
  app.get('/api/template', apiIsAuth, (req, res) => {
    getTemplates(req, res);
  });
  // Post a new template
  app.post('/api/template', apiIsAuth, parseJson, (req, res) => {
    createTemplate(req, res);
  });
  // Delete template(s)
  app.delete('/api/template', apiIsAuth, parseJson, (req, res) => {
    deleteTemplates(req, res);
  });

  /* Lists */
  // Get all lists
  app.get('/api/list/manage', apiIsAuth, (req, res) => {
    getLists(req, res);<commit_msg>Add route to cancel campaign sending<commit_after>const path = require('path');
const bodyParser = require('body-parser');
const multer = require('multer')({dest: 'server/controllers/list/uploads/'});
const auth = require('./auth');
const parseJson = bodyParser.json();

// Campaigns
const getCampaigns = require('../controllers/campaign/get-campaigns');
const createCampaign = require('../controllers/campaign/create-campaign');
const deleteCampaigns = require('../controllers/campaign/delete-campaigns');
const exportSentUnsentCSV = require('../controllers/campaign/export-sent-unsent-csv');
const stopCampaignSending = require('../controllers/campaign/stop-campaign-sending');

// Send campaign
const sendCampaign = require('../controllers/campaign/send-campaign');
const sendTestEmail = require('../controllers/campaign/email/amazon-ses/send-test');

// Templates
const getTemplates = require('../controllers/template/get-templates');
const createTemplate = require('../controllers/template/create-template');
const deleteTemplates = require('../controllers/template/delete-templates');

// Lists
const getLists = require('../controllers/list/get-lists');
const getListSubscribers = require('../controllers/list/get-list-subscribers');
const exportListSubscribersCSV = require('../controllers/list/export-list-subscribers-csv');
const addSubscribers = require('../controllers/list/add-subscribers');
const importCSV = require('../controllers/list/import-csv');
const subscribeToList = require('../controllers/list/subscribe');
const deleteSubscribers = require('../controllers/list/delete-subscribers');
const deleteLists = require('../controllers/list/delete-lists');
const unsubscribe = require('../controllers/subscriber/unsubscribe');

// Analytics
const getClickthroughs = require('../controllers/analytics/get-clickthroughs');
const refresh = require('../controllers/analytics/refresh');
const open = require('../controllers/analytics/open');
const clickthrough = require('../controllers/analytics/clickthrough');

// Settings
const getSettings = require('../controllers/settings/get-settings');
const changeSettings = require('../controllers/settings/changesettings');

// Websocket notifications
const getProfile = require('../controllers/websockets/get-profile');

module.exports = (app, passport, io, redis) => {

  ////////////////////
  /* AUTHENTICATION */
  ////////////////////

  auth(app, passport, isAuth);

  app.get('/logout', isAuth, (req, res) => {
    req.logout();
    res.redirect('/login');
  });

  ////////////////////
  /*      API       */
  ////////////////////

  /* Campaigns */
  // Get a list of all campaigns
  app.get('/api/campaign', apiIsAuth, (req, res) => {
    getCampaigns(req, res);
  });
  // Post new campaign
  app.post('/api/campaign', apiIsAuth, parseJson, (req, res) => {
    createCampaign(req, res);
  });
  // Delete campaign(s)
  app.delete('/api/campaign', apiIsAuth, parseJson, (req, res) => {
    deleteCampaigns(req, res);
  });
  // Export subscribers that emails were not sent/sent to during a campaign
  app.get('/api/campaign/subscribers/csv', apiIsAuth, (req, res) => {
    exportSentUnsentCSV(req, res);
  });

  /* Send */
  // Post to send campaign
  app.post('/api/send', apiIsAuth, parseJson, (req, res) => {
    sendCampaign(req, res, io, redis);
  });
  // Stop sending a campaign
  app.post('/api/stop', apiIsAuth, parseJson, (req, res) => {
    stopCampaignSending(req, res, redis)
  });
  // Post to send a test email
  app.post('/api/test', apiIsAuth, parseJson, (req, res) => {
    sendTestEmail(req, res);
  });

  /* Templates */
  // Get a list of all templates
  app.get('/api/template', apiIsAuth, (req, res) => {
    getTemplates(req, res);
  });
  // Post a new template
  app.post('/api/template', apiIsAuth, parseJson, (req, res) => {
    createTemplate(req, res);
  });
  // Delete template(s)
  app.delete('/api/template', apiIsAuth, parseJson, (req, res) => {
    deleteTemplates(req, res);
  });

  /* Lists */
  // Get all lists
  app.get('/api/list/manage', apiIsAuth, (req, res) => {
    getLists(req, res);
{'fraction_non_alphanumeric': 0.19341460349377906, 'fraction_numerical': 0.0, 'mean_word_length': 3.7312722948870394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '4702192', 'n_tokens_mistral': 2458, 'n_tokens_neox': 2383, 'n_words': 489}