fix(route): Instagram route reads config from the config module (#9129)
* instagram route read config from the config module instead of directly from process.env * add IG_PROXY to config.js
This commit is contained in:
parent
1596a0cf15
commit
a42dce573c
|
|
@ -219,6 +219,11 @@ const calculateValue = () => {
|
|||
google: {
|
||||
fontsApiKey: envs.GOOGLE_FONTS_API_KEY,
|
||||
},
|
||||
instagram: {
|
||||
username: envs.IG_USERNAME,
|
||||
password: envs.IG_PASSWORD,
|
||||
proxy: envs.IG_PROXY,
|
||||
},
|
||||
};
|
||||
};
|
||||
calculateValue();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ const cheerio = require('cheerio');
|
|||
const { IgLoginRequiredError } = require('instagram-private-api');
|
||||
const { ig, login } = require('./utils');
|
||||
const logger = require('@/utils/logger');
|
||||
const config = require('@/config').value;
|
||||
|
||||
// loadContent pulls the desired user/tag/etc
|
||||
async function loadContent(category, nameOrId) {
|
||||
|
|
@ -66,8 +67,8 @@ module.exports = async (ctx) => {
|
|||
throw Error('Such feed is not supported.');
|
||||
}
|
||||
|
||||
if (process.env.IG_PROXY) {
|
||||
ig.state.proxyUrl = process.env.IG_PROXY;
|
||||
if (config.instagram && config.instagram.proxy) {
|
||||
ig.state.proxyUrl = config.instagram.proxy;
|
||||
}
|
||||
|
||||
// Unique key for a feed category
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
const { IgApiClient } = require('instagram-private-api');
|
||||
const logger = require('@/utils/logger');
|
||||
const config = require('@/config').value;
|
||||
|
||||
const ig = new IgApiClient();
|
||||
() => login(ig); // deepscan-disable-line UNUSED_EXPR
|
||||
|
||||
async function login(ig) {
|
||||
if (process.env.IG_USERNAME && process.env.IG_PASSWORD) {
|
||||
if (config.instagram && config.instagram.username && config.instagram.password) {
|
||||
try {
|
||||
ig.state.generateDevice(process.env.IG_USERNAME);
|
||||
ig.state.generateDevice(config.instagram.username);
|
||||
try {
|
||||
await ig.simulate.preLoginFlow();
|
||||
} catch (error) {
|
||||
logger.info('Instagram preLoginFlow fail: ' + error);
|
||||
}
|
||||
await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);
|
||||
await ig.account.login(config.instagram.username, config.instagram.password);
|
||||
process.nextTick(() => ig.simulate.postLoginFlow());
|
||||
logger.info('Instagram login success.');
|
||||
} catch (error) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue