Files
Sukka d82847f541 style/chore(eslint): enforce new rules (#8040)
* style: prefer object shorthand syntax
* refactor: prefer Array#map over Array#forEach
* style: prefer arrow callback
* chore(eslint): update rules
* style: auto fix by eslint
2021-08-17 22:23:23 +08:00

41 lines
959 B
JavaScript

const logger = require('@/utils/logger');
const config = require('@/config').value;
const Fanfou = require('fanfou-sdk');
const consumerKey = config.fanfou.consumer_key;
const consumerSecret = config.fanfou.consumer_secret;
const username = config.fanfou.username;
const password = config.fanfou.password;
let fanfou_client;
let authed = false;
const getFanfou = async () => {
if (authed === true) {
return fanfou_client;
} else {
fanfou_client = new Fanfou({
consumerKey,
consumerSecret,
username,
password,
protocol: 'https:',
hooks: {
baseString(str) {
return str.replace('https', 'http');
},
},
});
await fanfou_client.xauth();
logger.info('Fanfou login success.');
authed = true;
return fanfou_client;
}
};
module.exports = {
getFanfou,
};