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 { createLogger } from '@/logger'
|
||||||
import { createMessage } from '@/openai'
|
import { createMessage } from '@/openai'
|
||||||
import { loadSession, newStealthContext, randomDelay, randomScroll, withBrowser } from './browser.js'
|
import { loadSession, newStealthContext, randomDelay, randomScroll, withBrowser } from './browser.js'
|
||||||
import { createStatusReporter, escapeHtml } from './ui.js'
|
import { escapeHtml } from './ui.js'
|
||||||
|
|
||||||
const log = createLogger('scraper')
|
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> {
|
async function handleOtpFlow(page: Page, context: BrowserContext, chatId: number, initialMessage: string): Promise<void> {
|
||||||
await page.click('[data-qa="applicant-login-input-otp"]')
|
await page.click('[data-qa="applicant-login-input-otp"]')
|
||||||
|
|
||||||
let message = initialMessage
|
const message = initialMessage
|
||||||
while (true) {
|
|
||||||
await bot.sendMessage(chatId, message)
|
|
||||||
const otp = await waitForOtp(chatId)
|
|
||||||
|
|
||||||
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([
|
await page.fill('[data-qa="applicant-login-input-otp"] input', otp)
|
||||||
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')
|
// while (true) {
|
||||||
break
|
// await bot.sendMessage(chatId, message)
|
||||||
if (outcome === 'error') {
|
// const otp = await waitForOtp(chatId)
|
||||||
message = '❌ Неверный код. Введи код ещё раз:'
|
//
|
||||||
continue
|
// await page.fill('[data-qa="applicant-login-input-otp"] input', otp)
|
||||||
}
|
//
|
||||||
throw new Error('OTP verification timed out')
|
// 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()
|
const cookies = await context.cookies()
|
||||||
await prisma.user.upsert({
|
await prisma.user.upsert({
|
||||||
|
|||||||
Reference in New Issue
Block a user