Этап 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.
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package vkauth
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/cacggghp/vk-turn-proxy/client/internal/browserprofile"
|
|
"github.com/cacggghp/vk-turn-proxy/client/internal/captcha"
|
|
|
|
tlsclient "github.com/bogdanfinn/tls-client"
|
|
)
|
|
|
|
// DefaultAutoSolve drives the in-page widget flow. It loads a saved real
|
|
// browser profile when available so the captcha origin sees consistent
|
|
// fingerprints across the page load and the solve POST.
|
|
func DefaultAutoSolve(
|
|
ctx context.Context,
|
|
captchaErr *captcha.Error,
|
|
streamID int,
|
|
client tlsclient.HttpClient,
|
|
profile browserprofile.Profile,
|
|
) (string, error) {
|
|
log.Printf("[STREAM %d] [Captcha] Solving captcha...", streamID)
|
|
|
|
if captchaErr.SessionToken == "" {
|
|
return "", fmt.Errorf("no session_token in redirect_uri for auto-solve")
|
|
}
|
|
if captchaErr.RedirectURI == "" {
|
|
return "", fmt.Errorf("no redirect_uri for auto-solve")
|
|
}
|
|
|
|
var savedProfile *browserprofile.Saved
|
|
if sp, err := browserprofile.Load(); err == nil {
|
|
log.Printf("[STREAM %d] [Captcha] Using saved real browser profile", streamID)
|
|
savedProfile = sp
|
|
profile = sp.Profile
|
|
}
|
|
|
|
successToken, err := captcha.Solve(ctx, captchaErr, streamID, client, profile, savedProfile)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
log.Printf("[STREAM %d] [Captcha] solver succeeded", streamID)
|
|
return successToken, nil
|
|
}
|