Skip to content

Commit a14d35b

Browse files
author
erkanrzgc
committed
update
1 parent aaf06d6 commit a14d35b

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

core/engine.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,16 @@ async def _check_platform(
246246
if platform.url_probe:
247247
probe_url = platform.url_probe.replace("{username}", username)
248248
try:
249-
_probe_status, _probe_data, _probe_elapsed = await client.get_json(
250-
probe_url, platform.headers
251-
)
249+
if platform.probe_method == "POST" and platform.probe_body:
250+
import json as _json
251+
_body_str = _json.dumps(platform.probe_body).replace("{username}", username)
252+
_probe_status, _probe_data, _probe_elapsed = await client.post_json(
253+
probe_url, _json.loads(_body_str), platform.headers
254+
)
255+
else:
256+
_probe_status, _probe_data, _probe_elapsed = await client.get_json(
257+
probe_url, platform.headers
258+
)
252259
except Exception:
253260
_probe_status, _probe_data, _probe_elapsed = -1, None, 0.0
254261
if _probe_status != 200:

core/platform_loader.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class Platform:
4040
presence_strings: tuple[str, ...] = ()
4141
url_probe: str | None = None
4242
check_method: str = "status"
43+
probe_method: str = "GET"
44+
probe_body: dict | None = None
4345

4446

4547
BUILTIN_YAML = Path(__file__).resolve().parent.parent / "modules" / "platforms.yaml"
@@ -84,6 +86,12 @@ def _coerce(entry: dict[str, Any]) -> Platform:
8486
check_method = entry.get("check_method", "status")
8587
if check_method not in ("status", "message", "response_url"):
8688
raise ValueError(f"platform {name!r} invalid check_method {check_method!r}")
89+
probe_method = entry.get("probe_method", "GET")
90+
if probe_method not in ("GET", "POST"):
91+
raise ValueError(f"platform {name!r} invalid probe_method {probe_method!r}")
92+
probe_body = entry.get("probe_body")
93+
if probe_body is not None and not isinstance(probe_body, dict):
94+
raise ValueError(f"platform {name!r} probe_body must be a mapping")
8795
return Platform(
8896
name=name,
8997
url=url,
@@ -100,6 +108,8 @@ def _coerce(entry: dict[str, Any]) -> Platform:
100108
presence_strings=tuple(str(s) for s in presence if str(s).strip()),
101109
url_probe=url_probe,
102110
check_method=check_method,
111+
probe_method=probe_method,
112+
probe_body=probe_body,
103113
)
104114

105115

modules/platforms.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ platforms:
171171
name: LeetCode
172172
presence_strings:
173173
- '"username":'
174+
probe_body:
175+
query: 'query getUserProfile($username: String!) { matchedUser(username: $username) { username } }'
176+
variables:
177+
username: '{username}'
178+
probe_method: POST
174179
url: https://leetcode.com/u/{username}/
175180
url_probe: https://leetcode.com/graphql/
176181
- absence_strings:

0 commit comments

Comments
 (0)