<commit_before>let resource, CACHE

resource = require('vue-resource')

CACHE = []

function plugin(Vue, opts) {
    if(plugin.installed) {
        return
    }

    opts = Object.assign({}, {
        headers: {},
        timeout: 10000,
        duration: 1000,
        errorCallback(message) {alert(message)}
    }, opts)

    Vue.use(resource)
    Vue.http.options.root = opts.root
    Vue.http.options.credentials = true
    Vue.http.headers.common = opts.headers
    Vue.http.options.timeout = opts.timeout
    Vue.http.options.duration = opts.duration

    Vue.http.interceptors.push((request, next) => {
        let before, timeout

        before = request.before
        timeout = request.timeout

        delete request.timeout

        request.before = function(request) {
            if(before) {
                before.call(this, request)
            }

            request.timerId = setTimeout(() => {
                request.abort()
                delete request.timerId
                opts.errorCallback('Network error')
            }, timeout)
        }

        next((response) => {
            clearTimeout(request.timerId)
            delete request.timerId
        })
    })

    Vue.http.interceptors.push((request, next) => {
        if(request.duration === 0) {
            next()
        }else {
            request.loadingTimerId = setTimeout(() => {
                Vue.loading && Vue.loading(true)
                delete request.loadingTimerId
            }, request.duration)

            next((response) => {
                Vue.loading && Vue.loading(false)
                clearTimeout(request.loadingTimerId)
                delete request.loadingTimerId
            })
        }
    })

    Vue.http.interceptors.push((request, next) => {
        if(request.method.toLowerCase() === 'get') {
            request.url = `${request.url}${request.url.indexOf('?') < 0 ? '?' : '&'}t=${Date.now()}`
        }

        if(request.method.toLowerCase() === 'post'){
            request.emulateJSON = true
        }

        next()
    })

    Vue.http.interceptors.push((request, next) => {
        let uid = `${request.method.toLowerCase()}${request.url}${request.data ? JSON.stringify(request.data) : ''}`

        if (CACHE.indexOf(uid) < 0) {
            CACHE.push(uid)
        }else{
            next(request.respondWith(request.body, {
                status: 0,
                statusText: 'repeat request'
            }))
            return
        }

        next((response) => {
            CACHE.splice(CACHE.indexOf(uid), 1)
        })
    })

    Vue.http.interceptors.push((request, next) => {
        next((response) => {
            if(response.data) {
                response.message = response.data.message
                response.code = response.data.status
                response.data = response.data.data
            }
        })
    })

    Vue.http.interceptors.push((request, next) => {
        next((response) => {
            if(response.status === 0 && response.statusText === '') {
                opts.errorCallback('Network error')
            }

            if(response.status === 0 && response.statusText === 'repeat request') {
                console.error('The last request was in the pending state, not to send multiple requests')
                return new Vue.Promise(() => {})
            }

            if(response.status === 404) {
                return new Vue.Promise(() => {
                    opts.errorCallback('not found')
                })
            }

            if(response.status === 500) {
                return new Vue.Promise(() => {
                    opts.errorCallback(response.statusText)
                })
            }
        })
    })
}

if(typeof window !== 'undefined' && window.Vue){
    window.Vue.use(plugin)
}

module.exports = plugin<commit_msg>fixed bug<commit_after>let resource, CACHE

resource = require('vue-resource')

CACHE = []

function plugin(Vue, opts) {
    if(plugin.installed) {
        return
    }

    opts = Object.assign({}, {
        headers: {},
        timeout: 10000,
        duration: 1000,
        errorCallback(message) { alert(message) }
    }, opts)

    Vue.use(resource)
    Vue.http.options.root = opts.root
    Vue.http.options.credentials = true
    Vue.http.headers.common = opts.headers
    Vue.http.options.timeout = opts.timeout
    Vue.http.options.duration = opts.duration

    Vue.http.interceptors.push((request, next) => {
        let before, time, timeout

        time = request.timeout
        before = request.before

        delete request.timeout

        request.before = function(request) {
            if(before) {
                before.call(this, request)
            }

            timeout = setTimeout(() => {
                request.abort()

                next(request.respondWith(request.body, {
                    status: 0,
                    statusText: ''
                }))
            }, time)
        }

        next((response) => {
            clearTimeout(timeout)
        })
    })

    Vue.http.interceptors.push((request, next) => {
        if(request.duration === 0) {
            next()
        }else {
            let timeout = setTimeout(() => {
                Vue.loading && Vue.loading(true)
            }, request.duration)

            next((response) => {
                clearTimeout(timeout)
                Vue.loading && Vue.loading(false)
            })
        }
    })

    Vue.http.interceptors.push((request, next) => {
        if(request.method.toLowerCase() === 'get') {
            request.url = `${request.url}${request.url.indexOf('?') < 0 ? '?' : '&'}t=${Date.now()}`
        }

        if(request.method.toLowerCase() === 'post'){
            request.emulateJSON = true
        }

        next()
    })

    Vue.http.interceptors.push((request, next) => {
        let uid = ''

        if(request.method.toLowerCase() === 'get') {
            uid = `${request.method.toLowerCase()}${request.url}${request.params ? JSON.stringify(request.params) : ''}`
        }

        if(request.method.toLowerCase() === 'post'){
            uid = `${request.method.toLowerCase()}${request.url}${request.data ? JSON.stringify(request.data) : ''}`
        }

        if (CACHE.indexOf(uid) === -1) {
            CACHE.push(uid)

            next((response) => {
                CACHE.splice(CACHE.indexOf(uid), 1)
            })
        }else{
            next(request.respondWith(request.body, {
                status: 0,
                statusText: 'repeat request'
            }))
        }
    })

    Vue.http.interceptors.push((request, next) => {
        next((response) => {
            if(response.data) {
                response.message = response.data.message
                response.code = response.data.status
                response.data = response.data.data
            }
        })
    })

    Vue.http.interceptors.push((request, next) => {
        next((response) => {
            if(response.status === 0 && response.statusText === '') {
                return new Vue.Promise(opts.errorCallback.bind(null, 'Network error'))
            }

            if(response.status === 0 && response.statusText === 'repeat request') {
                return new Vue.Promise(() => console.error('The last request was in the pending state, not to send multiple requests'))
            }

            if(response.status === 404) {
                return new Vue.Promise(opts.errorCallback.bind(null, 'not found'))
            }

            if(response.status === 500) {
                return new Vue.Promise(opts.errorCallback.bind(null, response.statusText))
            }
        })
    })
}

if(typeof window !== 'undefined' && window.Vue){
    window.Vue.use(plugin)
}

module.exports = plugin
{'fraction_non_alphanumeric': 0.14163035119200204, 'fraction_numerical': 0.005767751858497821, 'mean_word_length': 1.6343686698176907, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 33, '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': '1403066', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2121, 'n_words': 350}