|
1 | 1 | import httpx |
2 | 2 | from user_scanner.core.result import Result |
3 | 3 |
|
| 4 | + |
4 | 5 | async def _check(email: str) -> Result: |
| 6 | + url = "https://account.envato.com/api/public/validate_email" |
| 7 | + |
5 | 8 | headers = { |
6 | 9 | 'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", |
7 | | - 'Accept': 'application/json', |
8 | | - 'Accept-Language': 'en-US,en;q=0.9', |
9 | | - 'Content-Type': 'application/x-www-form-urlencoded', |
10 | | - 'Origin': 'https://account.envato.com', |
11 | | - 'Referer': 'https://account.envato.com/sign_up', |
| 10 | + 'Accept': "application/json", |
| 11 | + 'Content-Type': "application/json", |
| 12 | + 'x-client-version': "3.6.0", |
| 13 | + 'origin': "https://elements.envato.com", |
| 14 | + 'referer': "https://elements.envato.com/", |
| 15 | + 'accept-language': "en-US,en;q=0.9", |
12 | 16 | } |
13 | 17 |
|
14 | | - payload = {'email': email} |
| 18 | + payload = { |
| 19 | + "language_code": "en", |
| 20 | + "email": email |
| 21 | + } |
15 | 22 |
|
16 | 23 | try: |
17 | | - async with httpx.AsyncClient(timeout=10.0) as client: |
18 | | - response = await client.post( |
19 | | - 'https://account.envato.com/api/validate_email', |
20 | | - headers=headers, |
21 | | - data=payload |
22 | | - ) |
23 | | - |
24 | | - if 'Email is already in use' in response.text: |
25 | | - return Result.taken() |
26 | | - |
27 | | - if response.status_code == 200: |
| 24 | + async with httpx.AsyncClient(timeout=5.0) as client: |
| 25 | + response = await client.post(url, json=payload, headers=headers) |
| 26 | + |
| 27 | + if response.status_code == 204: |
28 | 28 | return Result.available() |
29 | | - |
30 | | - if "Page designed by Kotulsky" in response.text or response.status_code == 429: |
31 | | - return Result.error("Rate limit or Cloudflare challenge detected") |
32 | | - |
33 | | - return Result.error(f"Unexpected response: {response.status_code}") |
| 29 | + |
| 30 | + if response.status_code == 422: |
| 31 | + data = response.json() |
| 32 | + error_msg = data.get("error_message", "").lower() |
| 33 | + |
| 34 | + if "already in use" in error_msg: |
| 35 | + return Result.taken() |
| 36 | + |
| 37 | + return Result.error("Unexpected response body, report it via GitHub issues") |
| 38 | + |
| 39 | + return Result.error(f"HTTP {response.status_code}") |
34 | 40 |
|
35 | 41 | except httpx.TimeoutException: |
36 | 42 | return Result.error("Connection timed out") |
37 | 43 | except Exception as e: |
38 | | - return Result.error(str(e)) |
| 44 | + return Result.error(f"Unexpected Exception: {e}") |
| 45 | + |
39 | 46 |
|
40 | 47 | async def validate_envato(email: str) -> Result: |
41 | 48 | return await _check(email) |
0 commit comments