<commit_before>/**
 * SocketController
 *
 * @description :: Server-side logic for managing sockets
 * @help        :: See http://sailsjs.org/#!/documentation/concepts/Controllers
 */

/* global SocketService, module */

module.exports = {
  getSockets: function(req, res) {
    SocketService.getSockets(function(sockets) {
      res.json(sockets);
    });
  },
  addSocket: function(req, res) {
    var socketVal = (req.body.value) ? req.body.value : undefined;
    SocketService.addSocket(socketVal, function(success) {
      res.json(success);
    });
  },
  removeSocket: function(req, res) {
    var socketVal = (req.body.value) ? req.body.value : undefined;
    SocketService.removeSocket(socketVal, function(success) {
      res.json(success);
    });
  },


  socketsPage: function(req, res) {

    function sendView(res) {
     SocketService.getSocketsForView(function(socketsForView) {
       res.view('sockets', {
         sockets: socketsForView
       });
     });
    }

    if (req.route.method === 'post') {
      // Either an existing socket was modified, or a new one was created
      if (req.body.id) {
        SocketService.modifySocketFromView(req.body, function(success) {
          if (!success) throw 'Failed to modify socket';
          sendView(res);
        });
      } else {
        if (req.body.delete_id) {
          SocketService.removeSocket(req.body.delete_id, function(success) {
            if (!success) throw 'Failed to delete socket';
            sendView(res);
          });
        } else {
          // Create a new socket
          SocketService.addSocketFromView(req.body, function(success) {
            if (!success) throw 'Failed to add socket';
            sendView(res);
          });
        }
      }
    } else {
      sendView(res);
    }
  }
};<commit_msg>Redirect after POST requests to prevent reload resends<commit_after>/**
 * SocketController
 *
 * @description :: Server-side logic for managing sockets
 * @help        :: See http://sailsjs.org/#!/documentation/concepts/Controllers
 */

/* global SocketService, module */

module.exports = {
  getSockets: function(req, res) {
    SocketService.getSockets(function(sockets) {
      res.json(sockets);
    });
  },
  addSocket: function(req, res) {
    var socketVal = (req.body.value) ? req.body.value : undefined;
    SocketService.addSocket(socketVal, function(success) {
      res.json(success);
    });
  },
  removeSocket: function(req, res) {
    var socketVal = (req.body.value) ? req.body.value : undefined;
    SocketService.removeSocket(socketVal, function(success) {
      res.json(success);
    });
  },


  socketsPage: function(req, res) {

    if (req.route.method === 'post') {
      if (req.body.id) {
        SocketService.modifySocketFromView(req.body, function(success) {
          if (!success) throw 'Failed to modify socket';
          res.redirect('/sockets/')
        });
      } else {
        if (req.body.delete_id) {
          SocketService.removeSocket(req.body.delete_id, function(success) {
            if (!success) throw 'Failed to delete socket';
            res.redirect('/sockets/')
          });
        } else {
          SocketService.addSocketFromView(req.body, function(success) {
            if (!success) throw 'Failed to add socket';
            res.redirect('/sockets/')
          });
        }
      }
    } else {
      SocketService.getSocketsForView(function(socketsForView) {
        res.view('sockets', {
          sockets: socketsForView
        });
      });
    }
  }
};
{'fraction_non_alphanumeric': 0.13627367825841108, 'fraction_numerical': 0.0, 'mean_word_length': 2.4084778420038537, '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': '6333921', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1047, 'n_words': 204}