src/api/instagram.js
/**
     * Process the responses in the response buffer
     */
Process the responses in the response buffer
Process the responses in the response buffer
async processResponses() {
        await this.responseBufferLock.acquireAsync();
        for (const res of this.responseBuffer) {
            if (!this.matchURL(res.url())) {
                continue;
            }
            this.responseFromAPI = true;
            let data;
            try {
                data = await res.json();
            }
            catch (e) {
                this.logger.error("Error processing response JSON");
                this.logger.error(e);
            }
            this.executePlugins("response", res, data);
            if (data && "status" in data && data["status"] === "fail") {
                this.logger.info("Rate limited");
                this.hibernate = true;
                continue;
            }
            if (!(_.get(data, this.pageQuery + ".has_next_page", false) &&
                _.get(data, this.pageQuery + ".end_cursor", false))) {
                this.logger.info("No posts remaining", { data });
                this.finished = true;
            }
            await this.processResponseData(data);
        }
        this.responseBuffer = [];
        this.responseBufferLock.release();
    }
async processResponses ( ) { await this . responseBufferLock . acquireAsync ( ) ; for ( const res of this . responseBuffer ) { if ( ! this . matchURL ( res . url ( ) ) ) { continue ; } this . responseFromAPI = true ; let data ; try { data = await res . json ( ) ; } catch ( e ) { this . logger . error ( "Error processing response JSON" ) ; this . logger . error ( e ) ; } this . executePlugins ( "response" , res , data ) ; if ( data && "status" in data && data [ "status" ] === "fail" ) { this . logger . info ( "Rate limited" ) ; this . hibernate = true ; continue ; } if ( ! ( _ . get ( data , this . pageQuery + ".has_next_page" , false ) && _ . get ( data , this . pageQuery + ".end_cursor" , false ) ) ) { this . logger . info ( "No posts remaining" , { data } ) ; this . finished = true ; } await this . processResponseData ( data ) ; } this . responseBuffer = [ ] ; this . responseBufferLock . release ( ) ; }
Process the responses in the response buffer
Process the responses in the response buffer
// Match url // Acknowlege receipt of response // Get JSON data // Emit event // Check for rate limiting // Check for next page // Clear buffer and release