|
@@ -18,7 +18,7 @@ import { SocksProxyAgent } from 'socks-proxy-agent';
|
|
|
|
|
|
import { getLogger } from './loggers';
|
|
|
import QQBot from './koishi';
|
|
|
-import { Arr, BigNumOps, chainPromises, neverResolves } from './utils';
|
|
|
+import { Arr, BigNumOps, chainPromises, customError, neverResolves } from './utils';
|
|
|
import Webshot, { Cookies, Page } from './webshot';
|
|
|
|
|
|
const parseLink = (link: string): { userName?: string, postUrlSegment?: string } => {
|
|
@@ -412,12 +412,9 @@ export default class {
|
|
|
.then(responseHandler);
|
|
|
const responseHandler = (res: typeof response): ReturnType<typeof response.json> => {
|
|
|
if (res.status() !== 200) {
|
|
|
- const err = new Error(
|
|
|
+ throw customError('ResponseError')(
|
|
|
`error navigating to user page, error was: ${res.status()} ${res.statusText()}`
|
|
|
);
|
|
|
- throw Object.defineProperty(err, 'name', {
|
|
|
- value: 'ResponseError',
|
|
|
- });
|
|
|
}
|
|
|
return res.json()
|
|
|
.catch(redirectionHandler)
|
|
@@ -544,13 +541,13 @@ export default class {
|
|
|
() => Promise.all(arr.map((currentFeed, j) => {
|
|
|
const workon = (queuedFeeds.length - 1) - (i * 5 + j);
|
|
|
fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
|
|
|
- const promiseDelay = this.workInterval * (Math.random() + j) * 500 / lock.feed.length;
|
|
|
+ const promiseDelay = this.workInterval * (Math.random() + j) * 250 / lock.feed.length;
|
|
|
const startTime = new Date().getTime();
|
|
|
const getTimerTime = () => new Date().getTime() - startTime;
|
|
|
|
|
|
- const promise = promisify(setTimeout)(promiseDelay).then(() => {
|
|
|
+ const promise = 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 * 2)} ms`);
|
|
|
+ if (j === arr.length - 1) logger.info(`timeout for this batch job: ${Math.trunc(promiseDelay)} ms`);
|
|
|
const match = /https:\/\/www\.instagram\.com\/([^\/]+)/.exec(currentFeed);
|
|
|
if (!match) {
|
|
|
logger.error(`current feed "${currentFeed}" is invalid, please remove this feed manually`);
|
|
@@ -582,16 +579,8 @@ export default class {
|
|
|
fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
|
|
|
});
|
|
|
|
|
|
- return Promise.race([promise, isWaitingForLogin ? neverResolves() : promisify(setTimeout)(promiseDelay * 3)]);
|
|
|
+ return Promise.race([promise, isWaitingForLogin ? neverResolves() : promisify(setTimeout)(promiseDelay * 4)]);
|
|
|
}))
|
|
|
- ))
|
|
|
- .then(() => {
|
|
|
- let timeout = this.workInterval * 500;
|
|
|
- if (timeout < 1000) timeout = 1000;
|
|
|
- fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
|
|
|
- setTimeout(() => {
|
|
|
- this.work();
|
|
|
- }, timeout);
|
|
|
- });
|
|
|
+ )).then(this.work);
|
|
|
};
|
|
|
}
|