feat: support multiple twitter key

This commit is contained in:
DIYgod
2019-06-10 19:23:25 +08:00
parent d7f9c5cc0e
commit a002648819
9 changed files with 34 additions and 36 deletions

View File

@@ -1,4 +1,6 @@
const URL = require('url');
const config = require('@/config');
const Twit = require('twit');
const ProcessFeed = ({ data = [] }) => {
const getQueryParams = (url) => URL.parse(url, true).query;
@@ -106,6 +108,30 @@ const ProcessFeed = ({ data = [] }) => {
});
};
const consumer_keys = config.twitter.consumer_key.split(',');
const consumer_secrets = config.twitter.consumer_secret.split(',');
const T = {};
let count = 0;
let index = -1;
consumer_keys.forEach((consumer_key, index) => {
const consumer_secret = consumer_secrets[index];
if (consumer_key && consumer_secret) {
T[index] = new Twit({
consumer_key,
consumer_secret,
app_only_auth: true,
});
count = index + 1;
}
});
const getTwit = () => {
index++;
return T[index % count];
};
module.exports = {
ProcessFeed,
getTwit,
};