Files
free-turn-proxy-orig/client/internal/vkauth/solver.go
T
samosvalishe 5bf6dd0399 refactor: вынести VK-авторизацию в client/internal/vkauth
Этап 2 плана рефакторинга. Выносит слой VK credentials/captcha/throttle/
lockout из client/main.go в отдельный пакет с инжектируемым хуком token-chain
для тестов.

Интерфейс:
- vkauth.Client{GetCredentials, HandleAuthError, ResetErrors, LockoutUntilUnix}
- vkauth.IsAuthError (package-level)
- vkauth.DefaultAutoSolve / AutoSolveFunc / ManualSolveFunc

Wire-формат и флаги CLI не изменены. client/main.go: 1967 → 1380.
2026-05-19 09:48:55 +03:00

65 lines
1.7 KiB
Go

package vkauth
import (
"context"
"net"
"github.com/cacggghp/vk-turn-proxy/client/internal/browserprofile"
"github.com/cacggghp/vk-turn-proxy/client/internal/captcha"
tlsclient "github.com/bogdanfinn/tls-client"
)
// CaptchaSolveMode selects between auto-solving and manual-browser fallback.
type CaptchaSolveMode int
const (
CaptchaSolveModeAuto CaptchaSolveMode = iota
CaptchaSolveModeManual
)
// CaptchaSolveModeForAttempt picks the solver to use on a given retry attempt.
// Returns (mode, true) when a mode is available, (_, false) when exhausted.
func CaptchaSolveModeForAttempt(attempt int, manualOnly bool) (CaptchaSolveMode, bool) {
if manualOnly {
return CaptchaSolveModeManual, attempt == 0
}
switch attempt {
case 0:
return CaptchaSolveModeAuto, true
case 1:
return CaptchaSolveModeManual, true
}
return 0, false
}
func CaptchaSolveModeLabel(mode CaptchaSolveMode) string {
switch mode {
case CaptchaSolveModeAuto:
return "auto captcha"
case CaptchaSolveModeManual:
return "manual captcha"
default:
return "captcha"
}
}
// AutoSolveFunc returns a success_token for the captcha when solvable via the
// in-page widget flow. Implementations must respect ctx cancellation.
type AutoSolveFunc func(
ctx context.Context,
captchaErr *captcha.Error,
streamID int,
http tlsclient.HttpClient,
profile browserprofile.Profile,
) (token string, err error)
// ManualSolveFunc opens the local browser-based fallback. Returns either a
// success_token (token != "") or a captcha_key, depending on which path the
// VK error exposed.
type ManualSolveFunc func(
ctx context.Context,
captchaErr *captcha.Error,
dialer net.Dialer,
) (token, key string, err error)