Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughReplaced the requests-based HTTP layer with a curl_cffi-backed BrowserSession that applies browser impersonation, default headers, configurable retries with exponential backoff and jitter, and changes call sites to use BrowserSession and BrowserRequestException; added related config constants and cookie/session typing protocols. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
api/base.py (1)
406-406:⚠️ Potential issue | 🟡 MinorFix string formatting syntax error.
Line 406 uses
%formatting but the logger expects{}placeholders (loguru style), causing the status code to not be interpolated correctly.🐛 Proposed fix
- logger.debug("刷新视频状态返回码异常: {}"% resp.status_code) + logger.debug("刷新视频状态返回码异常: {}", resp.status_code)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@api/base.py` at line 406, The logger.debug call that currently uses "%" interpolation is incorrect for the logging API being used; update the logger.debug invocation (the line calling logger.debug with resp.status_code) to use the logger's placeholder style by passing the message with a {} placeholder and the resp.status_code as an argument (or alternatively use an f-string), so the status code is interpolated correctly.
🧹 Nitpick comments (1)
api/cookies.py (1)
7-7: Consider adding a Protocol type hint for better documentation.The type annotation was removed to decouple from
requests.Session. While this works via duck typing, consider adding aProtocoltype or a union type hint to document the expected interface (session.cookies.items()).💡 Optional: Add type hint for clarity
+from typing import Protocol + +class CookieSession(Protocol): + `@property` + def cookies(self): ... + -def save_cookies(session): +def save_cookies(session: CookieSession):Alternatively, use a simple comment or
Anytype if Protocol feels heavy.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@api/cookies.py` at line 7, Add a lightweight Protocol to document the expected interface for the save_cookies(session) parameter: define a CookieSession Protocol (import Protocol from typing) that requires a cookies attribute exposing an items() method returning an iterable of (str, str) (or use typing.Iterable[tuple[str, str]]), then type the function as def save_cookies(session: CookieSession) to make the duck-typed expectation explicit; alternatively, if you prefer minimal change, annotate session as Any or include a one-line comment referencing the required session.cookies.items() behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@api/http.py`:
- Around line 32-46: The final "raise last_exc" in the request method is
unreachable because the except block re-raises when attempts exhausted; remove
the dead code at the end of request in api/http.py (the unreachable "raise
last_exc") so control flow is clear; reference: method request, exception
BrowserRequestException, constants SAFE_RETRY_METHODS, and attributes _retries
and _retry_backoff when locating the logic to edit.
---
Outside diff comments:
In `@api/base.py`:
- Line 406: The logger.debug call that currently uses "%" interpolation is
incorrect for the logging API being used; update the logger.debug invocation
(the line calling logger.debug with resp.status_code) to use the logger's
placeholder style by passing the message with a {} placeholder and the
resp.status_code as an argument (or alternatively use an f-string), so the
status code is interpolated correctly.
---
Nitpick comments:
In `@api/cookies.py`:
- Line 7: Add a lightweight Protocol to document the expected interface for the
save_cookies(session) parameter: define a CookieSession Protocol (import
Protocol from typing) that requires a cookies attribute exposing an items()
method returning an iterable of (str, str) (or use typing.Iterable[tuple[str,
str]]), then type the function as def save_cookies(session: CookieSession) to
make the duck-typed expectation explicit; alternatively, if you prefer minimal
change, annotate session as Any or include a one-line comment referencing the
required session.cookies.items() behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a789d625-924b-4a77-8eaa-4990ff53b11b
📒 Files selected for processing (6)
api/base.pyapi/captcha.pyapi/config.pyapi/cookies.pyapi/http.pyrequirements.txt
将超星核心请求链路切换为
curl_cffi浏览器仿真会话,减少默认requests指纹暴露。主要改动:
api/http.py统一创建浏览器会话curl_cffiapi/config.py中集中管理浏览器指纹、超时和重试参数requirements.txt,加入curl_cffi范围控制:
验证:
uv run main.py -c config.iniuv run python -m compileall api main.py app.pySummary by CodeRabbit
New Features
Bug Fixes
Chores