|
@@ -9,6 +9,7 @@ import {
|
|
|
IgClientError, IgExactUserNotFoundError, IgResponseError,
|
|
|
MediaInfoResponseItemsItem, UserFeedResponseItemsItem
|
|
|
} from 'instagram-private-api';
|
|
|
+import { SocksProxyAgent } from 'socks-proxy-agent';
|
|
|
|
|
|
import { getLogger } from './loggers';
|
|
|
import QQBot, { Message } from './koishi';
|
|
@@ -38,6 +39,7 @@ export {linkBuilder, parseLink, isValidUrlSegment, idToUrlSegment, urlSegmentToI
|
|
|
interface IWorkerOption {
|
|
|
sessionLockfile: string;
|
|
|
credentials: [string, string];
|
|
|
+ proxyUrl: string;
|
|
|
lock: ILock;
|
|
|
lockfile: string;
|
|
|
webshotCookiesLockfile: string;
|
|
@@ -189,6 +191,21 @@ export default class {
|
|
|
|
|
|
constructor(opt: IWorkerOption) {
|
|
|
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.lockfile = opt.lockfile;
|
|
|
this.webshotCookiesLockfile = opt.webshotCookiesLockfile;
|