You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.8 KiB

4 years ago
import fetch from 'node-fetch';
const graphql_endpoint = 'https://www.facebook.com/api/graphql/';
4 years ago
import * as url from 'url';
import https_proxy_agent from 'https-proxy-agent';
5 years ago
const proxies = [
'176.112.80.253:12323:14ae0dc1e2459:4364101eab',
'176.112.83.69:12323:14ae0dc1e2459:4364101eab',
'176.112.83.203:12323:14ae0dc1e2459:4364101eab',
'176.112.80.150:12323:14ae0dc1e2459:4364101eab',
'176.112.82.121:12323:14ae0dc1e2459:4364101eab'
].map((proxy_str) => {
const [ip, port, user, password] = proxy_str.split(':');
return { ip, port, user, password };
});
const random_int = (max, min) => Math.floor(Math.random() * (max - min) + min);
4 years ago
export const do_request = async (doc_id, variables, parse = true) => {
const params = new URLSearchParams();
const { ip, port, user, password } = proxies[random_int(0, 4)];
let proxyOpts = url.parse(`http://${ip}:${port}`);
proxyOpts.auth = `${user}:${password}`;
4 years ago
const agent = new https_proxy_agent(proxyOpts);
params.append('doc_id', doc_id);
params.append('variables', JSON.stringify(variables));
const fetch_options = {
headers: {
4 years ago
'Content-Type': 'application/x-www-form-urlencoded'
},
body: params,
method: 'POST',
4 years ago
agent
};
let res = null;
try {
res = await fetch(graphql_endpoint, fetch_options);
} catch (e) {
console.error(e);
return null;
}
4 years ago
const txt = await res.text();
if (!res.ok) {
console.error(txt);
return null;
}
4 years ago
if (parse) {
try {
res = JSON.parse(txt);
if (res.errors != null) {
console.error(JSON.stringify(res.errors));
}
4 years ago
} catch (e) {
console.error(e);
return null;
}
} else {
if (txt.length == 0) {
return null;
} else {
return txt;
}
}
return res;
};