mirror of
https://github.com/hempyhemp/hh-auto-reply.git
synced 2026-07-24 21:04:58 +00:00
🔧 refactor(src/hh/scraper.ts): упрощает обработку OTP, удаляет лишний цикл и улучшает читаемость кода
All checks were successful
Deploy / deploy (push) Successful in 8m13s
All checks were successful
Deploy / deploy (push) Successful in 8m13s
This commit is contained in:
@@ -7,7 +7,7 @@ import prisma from '@prisma'
|
||||
import { createLogger } from '@/logger'
|
||||
import { createMessage } from '@/openai'
|
||||
import { loadSession, newStealthContext, randomDelay, randomScroll, withBrowser } from './browser.js'
|
||||
import { createStatusReporter, escapeHtml } from './ui.js'
|
||||
import { escapeHtml } from './ui.js'
|
||||
|
||||
const log = createLogger('scraper')
|
||||
|
||||
@@ -55,26 +55,34 @@ function waitForOtp(chatId: number): Promise<string> {
|
||||
async function handleOtpFlow(page: Page, context: BrowserContext, chatId: number, initialMessage: string): Promise<void> {
|
||||
await page.click('[data-qa="applicant-login-input-otp"]')
|
||||
|
||||
let message = initialMessage
|
||||
while (true) {
|
||||
await bot.sendMessage(chatId, message)
|
||||
const otp = await waitForOtp(chatId)
|
||||
const message = initialMessage
|
||||
|
||||
await page.fill('[data-qa="applicant-login-input-otp"] input', otp)
|
||||
await bot.sendMessage(chatId, message)
|
||||
const otp = await waitForOtp(chatId)
|
||||
|
||||
const outcome = await Promise.race([
|
||||
page.waitForSelector('[data-qa="profileAndResumes-button"]', { timeout: 15000 }).then(() => 'success' as const),
|
||||
page.waitForSelector('[data-qa="magritte-pincode-input-field"][aria-invalid="true"]', { timeout: 8000 }).then(() => 'error' as const),
|
||||
]).catch(() => 'timeout' as const)
|
||||
await page.fill('[data-qa="applicant-login-input-otp"] input', otp)
|
||||
|
||||
if (outcome === 'success')
|
||||
break
|
||||
if (outcome === 'error') {
|
||||
message = '❌ Неверный код. Введи код ещё раз:'
|
||||
continue
|
||||
}
|
||||
throw new Error('OTP verification timed out')
|
||||
}
|
||||
// while (true) {
|
||||
// await bot.sendMessage(chatId, message)
|
||||
// const otp = await waitForOtp(chatId)
|
||||
//
|
||||
// await page.fill('[data-qa="applicant-login-input-otp"] input', otp)
|
||||
//
|
||||
// const outcome = await Promise.race([
|
||||
// page.waitForSelector('[data-qa="profileAndResumes-button"]', { timeout: 15000 }).then(() => 'success' as const),
|
||||
// page.waitForSelector('[data-qa="magritte-pincode-input-field"][aria-invalid="true"]', { timeout: 8000 }).then(() => 'error' as const),
|
||||
// ]).catch(() => 'timeout' as const)
|
||||
//
|
||||
// if (outcome === 'success')
|
||||
// break
|
||||
// if (outcome === 'error') {
|
||||
// message = '❌ Неверный код. Введи код ещё раз:'
|
||||
// continue
|
||||
// }
|
||||
// throw new Error('OTP verification timed out')
|
||||
// }
|
||||
|
||||
await page.waitForLoadState('networkidle')
|
||||
|
||||
const cookies = await context.cookies()
|
||||
await prisma.user.upsert({
|
||||
|
||||
Reference in New Issue
Block a user