<commit_before>Konnector = require '../models/konnector'
konnectorHash = require '../lib/konnector_hash'

module.exports =


    getKonnector: (req, res, next) ->
        Konnector.find req.params.konnectorId, (err, konnector) ->
            if err
                next err
            else if not konnector?
                res.send 404
            else
                konnector.injectEncryptedFields()
                req.konnector = konnector
                next()


    show: (req, res, next) ->
        res.send req.konnector


    import: (req, res, next) ->
        # Handle timeouts
        poller = require "../lib/konnector_poller"
        poller.handleTimeout req.body
        # Delete unused variable
        if req.body.fieldValues.date?
            delete req.body.fieldValues.date
        if req.konnector.isImporting
            setTimeout =>
                data =
                    isImporting: false
                    lastImport: new Date()
                req.konnector.updateAttributes data, (err) ->
            , 6
            res.send error: true, msg: 'konnector is already importing', 400
        else
            fields = konnectorHash[req.konnector.slug].fields
            req.konnector.import req.body, fields, (err) ->
                if err
                    #console.log res
                    res.send err, 400
                else
                    res.send success: true, 200
<commit_msg>send response before import<commit_after>Konnector = require '../models/konnector'
konnectorHash = require '../lib/konnector_hash'

module.exports =


    getKonnector: (req, res, next) ->
        Konnector.find req.params.konnectorId, (err, konnector) ->
            if err
                next err
            else if not konnector?
                res.send 404
            else
                konnector.injectEncryptedFields()
                req.konnector = konnector
                next()


    show: (req, res, next) ->
        res.send req.konnector


    import: (req, res, next) ->
        # Handle timeouts
        poller = require "../lib/konnector_poller"
        poller.handleTimeout req.body
        # Delete unused variable
        if req.body.fieldValues.date?
            delete req.body.fieldValues.date
        if req.konnector.isImporting
            setTimeout =>
                data =
                    isImporting: false
                    lastImport: new Date()
                req.konnector.updateAttributes data, (err) ->
            , 6
            res.send error: true, msg: 'konnector is already importing', 400
        else
            res.send success:true, 200
            fields = konnectorHash[req.konnector.slug].fields
            req.konnector.import req.body, fields, (err) ->
                if err
                    console.log err

{'fraction_non_alphanumeric': 0.08703374777975133, 'fraction_numerical': 0.008170515097690942, 'mean_word_length': 1.423407917383821, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '2347985', 'n_tokens_mistral': 806, 'n_tokens_neox': 747, 'n_words': 188}