|
@@ -8,6 +8,7 @@ import {
|
|
ReelsMediaFeedResponseItem, UserFeedResponseUser
|
|
ReelsMediaFeedResponseItem, UserFeedResponseUser
|
|
} from 'instagram-private-api';
|
|
} from 'instagram-private-api';
|
|
import { RequestError } from 'request-promise/errors';
|
|
import { RequestError } from 'request-promise/errors';
|
|
|
|
+import { SocksProxyAgent } from 'socks-proxy-agent';
|
|
|
|
|
|
import { getLogger } from './loggers';
|
|
import { getLogger } from './loggers';
|
|
import QQBot, { Message } from './koishi';
|
|
import QQBot, { Message } from './koishi';
|
|
@@ -36,6 +37,7 @@ export {linkBuilder, parseLink};
|
|
interface IWorkerOption {
|
|
interface IWorkerOption {
|
|
sessionLockfile: string;
|
|
sessionLockfile: string;
|
|
credentials: [string, string];
|
|
credentials: [string, string];
|
|
|
|
+ proxyUrl: string;
|
|
lock: ILock;
|
|
lock: ILock;
|
|
lockfile: string;
|
|
lockfile: string;
|
|
webshotCookiesLockfile: string;
|
|
webshotCookiesLockfile: string;
|
|
@@ -164,6 +166,21 @@ export default class {
|
|
|
|
|
|
constructor(opt: IWorkerOption) {
|
|
constructor(opt: IWorkerOption) {
|
|
this.client = new IgApiClient();
|
|
this.client = new IgApiClient();
|
|
|
|
+ if (opt.proxyUrl) {
|
|
|
|
+ try {
|
|
|
|
+ const url = new URL(opt.proxyUrl);
|
|
|
|
+ if (!/^socks(?:4a?|5h?)?:$/.test(url.protocol)) throw Error();
|
|
|
|
+ if (!url.port) url.port = '1080';
|
|
|
|
+ this.client.request.defaults.agent = new SocksProxyAgent({
|
|
|
|
+ hostname: url.hostname,
|
|
|
|
+ port: url.port,
|
|
|
|
+ userId: url.username,
|
|
|
|
+ password: url.password,
|
|
|
|
+ });
|
|
|
|
+ } catch (e) {
|
|
|
|
+ logger.warn(`invalid socks proxy url: ${opt.proxyUrl}, ignoring`);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
this.session = new SessionManager(this.client, opt.sessionLockfile, opt.credentials);
|
|
this.session = new SessionManager(this.client, opt.sessionLockfile, opt.credentials);
|
|
this.lockfile = opt.lockfile;
|
|
this.lockfile = opt.lockfile;
|
|
this.lock = opt.lock;
|
|
this.lock = opt.lock;
|