|
@@ -24,7 +24,7 @@ const loggers_1 = require("./loggers");
|
|
|
const utils_1 = require("./utils");
|
|
|
const webshot_1 = require("./webshot");
|
|
|
const parseLink = (link) => {
|
|
|
- let match = /instagram\.com\/(?:[^\/?#]+\/)?p\/([A-Za-z0-9\-_]+)/.exec(link);
|
|
|
+ let match = /instagram\.com\/(?:[^\/?#]+\/)?(?:p|tv)\/([A-Za-z0-9\-_]+)/.exec(link);
|
|
|
if (match)
|
|
|
return { postUrlSegment: match[1] };
|
|
|
match =
|
|
@@ -42,11 +42,10 @@ const linkBuilder = (config) => {
|
|
|
return `https://www.instagram.com/p/${config.postUrlSegment}/`;
|
|
|
};
|
|
|
exports.linkBuilder = linkBuilder;
|
|
|
-const graphqlLinkBuilder = ({ userId, first = '12', after }) => `https://www.instagram.com/graphql/query/\
|
|
|
-?query_id=17888483320059182&id=${userId}&first=${first}${after ? `&after=${after}` : ''}`;
|
|
|
+const graphqlLinkBuilder = ({ userId: id, first = '12', after }) => `https://www.instagram.com/graphql/query/?query_hash=8c2a529969ee035a5063f2fc8602a0fd&variables=${JSON.stringify({ id, first, after })}`;
|
|
|
exports.graphqlLinkBuilder = graphqlLinkBuilder;
|
|
|
const urlSegmentToId = (urlSegment) => urlSegment.length <= 28 ?
|
|
|
- instagram_id_to_url_segment_1.urlSegmentToInstagramId(urlSegment) : instagram_id_to_url_segment_1.urlSegmentToInstagramId(urlSegment.slice(0, -28));
|
|
|
+ (0, instagram_id_to_url_segment_1.urlSegmentToInstagramId)(urlSegment) : (0, instagram_id_to_url_segment_1.urlSegmentToInstagramId)(urlSegment.slice(0, -28));
|
|
|
exports.urlSegmentToId = urlSegmentToId;
|
|
|
class SessionManager {
|
|
|
constructor(client, file, credentials, codeServicePort) {
|
|
@@ -72,7 +71,7 @@ class SessionManager {
|
|
|
logger.warn('attempting to retry after 1 minute...');
|
|
|
if (fs.existsSync(filePath))
|
|
|
fs.unlinkSync(filePath);
|
|
|
- util_1.promisify(setTimeout)(60000).then(this.init);
|
|
|
+ (0, util_1.promisify)(setTimeout)(60000).then(this.init);
|
|
|
});
|
|
|
}
|
|
|
};
|
|
@@ -82,7 +81,7 @@ class SessionManager {
|
|
|
logger.info(`/confirm-2fa?code=<the code you received>&token=${token}`);
|
|
|
let working;
|
|
|
const server = http.createServer((req, res) => {
|
|
|
- const { pathname, query } = url_1.parse(req.url, true);
|
|
|
+ const { pathname, query } = (0, url_1.parse)(req.url, true);
|
|
|
if (!working && pathname === '/confirm-2fa' && query.token === token &&
|
|
|
typeof (query.code) === 'string' && /^\d{6}$/.test(query.code)) {
|
|
|
const code = query.code;
|
|
@@ -165,7 +164,7 @@ let sendPost = (segmentId, receiver) => {
|
|
|
throw Error();
|
|
|
};
|
|
|
exports.sendPost = sendPost;
|
|
|
-const logger = loggers_1.getLogger('instagram');
|
|
|
+const logger = (0, loggers_1.getLogger)('instagram');
|
|
|
const maxTrials = 3;
|
|
|
const retryInterval = 1500;
|
|
|
const ordinal = (n) => {
|
|
@@ -226,7 +225,7 @@ class default_1 {
|
|
|
.then(responseHandler);
|
|
|
const responseHandler = (res) => {
|
|
|
if (res.status() !== 200) {
|
|
|
- throw utils_1.customError('ResponseError')(`error navigating to user page, error was: ${res.status()} ${res.statusText()}`);
|
|
|
+ throw (0, utils_1.customError)('ResponseError')(`error navigating to user page, error was: ${res.status()} ${res.statusText()}`);
|
|
|
}
|
|
|
return res.json()
|
|
|
.catch(redirectionHandler)
|
|
@@ -235,7 +234,7 @@ class default_1 {
|
|
|
if (!json || !((_a = (json.graphql || json.data)) === null || _a === void 0 ? void 0 : _a.user)) {
|
|
|
logger.warn('error parsing graphql response, returning empty object...');
|
|
|
const data = { user: { edge_owner_to_timeline_media: { edges: [] } } };
|
|
|
- return { graphql: data, data };
|
|
|
+ return { data };
|
|
|
}
|
|
|
return json;
|
|
|
});
|
|
@@ -258,7 +257,7 @@ class default_1 {
|
|
|
url = graphqlLinkBuilder({ userId, after: pageInfo.end_cursor });
|
|
|
const nextPageDelay = this.webshotDelay * (0.4 + Math.random() * 0.1);
|
|
|
timeout += nextPageDelay;
|
|
|
- return util_1.promisify(setTimeout)(nextPageDelay)
|
|
|
+ return (0, util_1.promisify)(setTimeout)(nextPageDelay)
|
|
|
.then(() => page.goto(url, { waitUntil: 'load', timeout: getTimeout() }))
|
|
|
.then(responseHandler)
|
|
|
.then(({ data }) => jsonHandler(data));
|
|
@@ -275,7 +274,7 @@ class default_1 {
|
|
|
else
|
|
|
throw err;
|
|
|
return [];
|
|
|
- }).then(itemIds => util_1.promisify(setTimeout)(getTimeout()).then(() => itemIds.map(id => this.lazyGetMediaById(id))));
|
|
|
+ }).then(itemIds => (0, util_1.promisify)(setTimeout)(getTimeout()).then(() => itemIds.map(id => this.lazyGetMediaById(id))));
|
|
|
})).finally(() => { page.close(); });
|
|
|
});
|
|
|
setTimeout(this.work, this.workInterval * 1000 / this.lock.feed.length);
|
|
@@ -364,9 +363,9 @@ class default_1 {
|
|
|
}
|
|
|
});
|
|
|
const queuedFeeds = lock.feed.slice(0, (lock.workon + 1) || undefined).reverse();
|
|
|
- utils_1.chainPromises(utils_1.Arr.chunk(queuedFeeds, 5).map((arr, i) => () => Promise.all(arr.map((currentFeed, j) => {
|
|
|
+ (0, utils_1.chainPromises)(utils_1.Arr.chunk(queuedFeeds, 5).map((arr, i) => () => Promise.all(arr.map((currentFeed, j) => {
|
|
|
const promiseDelay = this.workInterval * (Math.random() + j + 10 - arr.length) * 125 / lock.feed.length;
|
|
|
- const wait = (ms) => isWaitingForLogin ? utils_1.neverResolves() : util_1.promisify(setTimeout)(ms);
|
|
|
+ const wait = (ms) => isWaitingForLogin ? (0, utils_1.neverResolves)() : (0, util_1.promisify)(setTimeout)(ms);
|
|
|
const startTime = new Date().getTime();
|
|
|
const getTimerTime = () => new Date().getTime() - startTime;
|
|
|
const workon = (queuedFeeds.length - 1) - (i * 5 + j);
|
|
@@ -375,7 +374,7 @@ class default_1 {
|
|
|
logger.info(`skipped feed #${workon}: ${currentFeed}, last updated within an hour`);
|
|
|
return wait(promiseDelay * 3);
|
|
|
}
|
|
|
- return util_1.promisify(setTimeout)(promiseDelay * 3).then(() => {
|
|
|
+ return (0, util_1.promisify)(setTimeout)(promiseDelay * 3).then(() => {
|
|
|
logger.info(`about to pull from feed #${workon}: ${currentFeed}`);
|
|
|
if (j === arr.length - 1)
|
|
|
logger.info(`timeout for this batch job: ${Math.trunc(promiseDelay)} ms`);
|
|
@@ -433,7 +432,7 @@ class default_1 {
|
|
|
if (isWaitingForLogin !== true)
|
|
|
return;
|
|
|
logger.warn('still waiting for login, pausing execution...');
|
|
|
- return utils_1.neverResolves();
|
|
|
+ return (0, utils_1.neverResolves)();
|
|
|
})
|
|
|
.then(() => { isWaitingForLogin = true; logger.warn('blocked by login dialog, trying to log in manually...'); })
|
|
|
.then(() => page.fill('input[name="password"]', opt.credentials[1], { timeout: 0 }))
|
|
@@ -481,7 +480,7 @@ class default_1 {
|
|
|
const lock = this.lock;
|
|
|
const feed = linkBuilder({ userName: mediaItem.user.username });
|
|
|
if (lock.feed.includes(feed) && lock.threads[feed].offset < mediaItem.pk) {
|
|
|
- logger.info(`post is newer than last offset of thread (${instagram_id_to_url_segment_1.instagramIdToUrlSegment(lock.threads[feed].offset)}), updating...`);
|
|
|
+ logger.info(`post is newer than last offset of thread (${(0, instagram_id_to_url_segment_1.instagramIdToUrlSegment)(lock.threads[feed].offset)}), updating...`);
|
|
|
this.workOnFeed(feed);
|
|
|
if (lock.threads[feed].subscribers.some(subscriber => subscriber.chatID.toString() === receiver.chatID.toString() &&
|
|
|
subscriber.chatType === receiver.chatType))
|
|
@@ -494,7 +493,7 @@ class default_1 {
|
|
|
if (err instanceof instagram_private_api_1.IgLoginRequiredError || err instanceof instagram_private_api_1.IgCookieNotFoundError) {
|
|
|
logger.warn('login required, awaiting login...');
|
|
|
this.bot.sendTo(receiver, '等待登录中,稍后会处理请求,请稍候……');
|
|
|
- return this.session.login().then(() => exports.sendPost(segmentId, receiver));
|
|
|
+ return this.session.login().then(() => (0, exports.sendPost)(segmentId, receiver));
|
|
|
}
|
|
|
;
|
|
|
});
|