refactor: fix linting issues

pull/166/head
Joel 2022-12-18 14:28:51 -08:00
rodzic b936a04bce
commit 39dc4de3b4
1 zmienionych plików z 15 dodań i 8 usunięć

Wyświetl plik

@ -56,7 +56,7 @@ export async function getOpenAIAuth({
captchaToken = process.env.CAPTCHA_TOKEN, captchaToken = process.env.CAPTCHA_TOKEN,
nopechaKey = process.env.NOPECHA_KEY, nopechaKey = process.env.NOPECHA_KEY,
executablePath, executablePath,
proxyServer = process.env.PROXY_SERVER, proxyServer = process.env.PROXY_SERVER
}: { }: {
email?: string email?: string
password?: string password?: string
@ -66,7 +66,7 @@ export async function getOpenAIAuth({
isGoogleLogin?: boolean isGoogleLogin?: boolean
captchaToken?: string captchaToken?: string
nopechaKey?: string nopechaKey?: string
executablePath?: string, executablePath?: string
proxyServer?: string proxyServer?: string
}): Promise<OpenAIAuth> { }): Promise<OpenAIAuth> {
const origBrowser = browser const origBrowser = browser
@ -74,7 +74,12 @@ export async function getOpenAIAuth({
try { try {
if (!browser) { if (!browser) {
browser = await getBrowser({ captchaToken, nopechaKey, executablePath, proxyServer }) browser = await getBrowser({
captchaToken,
nopechaKey,
executablePath,
proxyServer
})
} }
const userAgent = await browser.userAgent() const userAgent = await browser.userAgent()
@ -299,20 +304,22 @@ export async function getBrowser(
if (process.env.PROXY_VALIDATE_IP) { if (process.env.PROXY_VALIDATE_IP) {
const page = (await browser.pages())[0] || (await browser.newPage()) const page = (await browser.pages())[0] || (await browser.newPage())
// send a fetch request to https://ifconfig.co using page.evaluate() and verify the IP matches // send a fetch request to https://ifconfig.co using page.evaluate() and verify the IP matches
let ip; let ip
try { try {
({ ip } = await page.evaluate(() => { ;({ ip } = await page.evaluate(() => {
return fetch('https://ifconfig.co', { return fetch('https://ifconfig.co', {
headers: { headers: {
'Accept': 'application/json' Accept: 'application/json'
} }
}).then((res) => res.json()) }).then((res) => res.json())
})); }))
} catch (err) { } catch (err) {
throw new Error(`Proxy IP validation failed: ${err.message}`) throw new Error(`Proxy IP validation failed: ${err.message}`)
} }
if (ip !== process.env.PROXY_VALIDATE_IP) { if (ip !== process.env.PROXY_VALIDATE_IP) {
throw new Error(`Proxy IP mismatch: ${ip} !== ${process.env.PROXY_VALIDATE_IP}`) throw new Error(
`Proxy IP mismatch: ${ip} !== ${process.env.PROXY_VALIDATE_IP}`
)
} }
} }