Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
clean up diff & update yarn
- whitepace magic to minimize diff
- update yarn.lock file
  • Loading branch information
cgdobre committed Jun 7, 2020
commit e032d1c8ad44b9341d6e966e48c5c500c013f6dc
68 changes: 31 additions & 37 deletions src/models/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const request = require('request-promise-native');
const url = require('url');
const async = require('async');
const crypto = require('crypto');
const throttledQueue = require('throttled-queue');

const throttle = throttledQueue(10, 1000);
const throttle = require('throttled-queue')(10, 1000);

/**
* base model
Expand Down Expand Up @@ -38,23 +36,21 @@ class base {

data.private_token = this.token;

return new Promise((resolve, reject) => {
throttle(() => {
request.post(`${this.url}${path}`, {
json: true,
body: data,
insecure: this._insecure,
proxy: this._proxy,
resolveWithFullResponse: true,
headers: {
'PRIVATE-TOKEN': this.token
}
}).then(response => {
if (this.config.get('_createDump')) this.setDump(response, key);
resolve(response);
}).catch(e => reject(e));
})
});
return new Promise((resolve, reject) => throttle(() => {
request.post(`${this.url}${path}`, {
json: true,
body: data,
insecure: this._insecure,
proxy: this._proxy,
resolveWithFullResponse: true,
headers: {
'PRIVATE-TOKEN': this.token
}
}).then(response => {
if (this.config.get('_createDump')) this.setDump(response, key);
resolve(response);
}).catch(e => reject(e));
}));
}

/**
Expand All @@ -71,22 +67,20 @@ class base {
path += (path.includes('?') ? '&' : '?') + `private_token=${this.token}`;
path += `&page=${page}&per_page=${perPage}`;

return new Promise((resolve, reject) => {
throttle(() => {
request(`${this.url}${path}`, {
json: true,
insecure: this._insecure,
proxy: this._proxy,
resolveWithFullResponse: true,
headers: {
'PRIVATE-TOKEN': this.token
}
}).then(response => {
if (this.config.get('_createDump')) this.setDump(response, key);
resolve(response);
}).catch(e => reject(e));
})
});
return new Promise((resolve, reject) => throttle(() => {
request(`${this.url}${path}`, {
json: true,
insecure: this._insecure,
proxy: this._proxy,
resolveWithFullResponse: true,
headers: {
'PRIVATE-TOKEN': this.token
}
}).then(response => {
if (this.config.get('_createDump')) this.setDump(response, key);
resolve(response);
}).catch(e => reject(e));
}));
}

/**
Expand Down Expand Up @@ -197,4 +191,4 @@ class base {
}
}

module.exports = base;
module.exports = base;
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,11 @@ [email protected], text-encoding@^0.6.4:
version "0.6.4"
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"

throttled-queue@^1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/throttled-queue/-/throttled-queue-1.0.7.tgz#da7ed6702941993044a1c5fd2ac3a58582dd2977"
integrity sha512-/HT49S7m+NvdyJMoMRzIYlawKjeHn8jEc8TZaGmFi5IBu09hIiU/QoP1zcrB9X2qsVC11PgfRfqd8zEQs7PlEA==

throttleit@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/throttleit/-/throttleit-1.0.0.tgz#9e785836daf46743145a5984b6268d828528ac6c"
Expand Down