-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Fix/p0 p3 code review fixes #552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
35c94bc
e960d4b
3717ed7
ffcb759
8c94be5
4398a0b
14550fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,10 @@ def run(self, option): | |
| from .api import download_album, download_photo | ||
| from common import MultiTaskLauncher | ||
|
|
||
| if len(self.album_id_list) == 0 and len(self.photo_id_list) == 0: | ||
| print('未指定任何 id,请提供 album 或 photo 的 id,例如: jmcomic 123') | ||
| return | ||
|
Comment on lines
+105
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Exit before constructing the option. This guard runs after 🧰 Tools🪛 Ruff (0.15.21)[warning] 106-106: String contains ambiguous (RUF001) [warning] 106-106: String contains ambiguous (RUF001) 🤖 Prompt for AI Agents |
||
|
|
||
| if len(self.album_id_list) == 0: | ||
| download_photo(self.photo_id_list, option) | ||
| elif len(self.photo_id_list) == 0: | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -437,13 +437,7 @@ def favorite_folder(self, | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return JmPageTool.parse_html_to_favorite_page(resp.text) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # noinspection PyTypeChecker | ||||||||||||||||||||||||||||||
| def get_username_from_cookies(self) -> str: | ||||||||||||||||||||||||||||||
| # cookies = self.get_meta_data('cookies', None) | ||||||||||||||||||||||||||||||
| # if not cookies: | ||||||||||||||||||||||||||||||
| # ExceptionTool.raises('未登录,无法获取到对应的用户名,请给favorite方法传入username参数') | ||||||||||||||||||||||||||||||
| # 解析cookies,可能需要用到 phpserialize,比较麻烦,暂不实现 | ||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def get_jm_html(self, url, require_200=True, **kwargs): | ||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
|
|
@@ -698,12 +692,23 @@ def get_scramble_id(self, photo_id, album_id=None): | |||||||||||||||||||||||||||||
| if album_id is not None and album_id in cache: | ||||||||||||||||||||||||||||||
| return cache[album_id] | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| scramble_id = self.fetch_scramble_id(photo_id) | ||||||||||||||||||||||||||||||
| cache[photo_id] = scramble_id | ||||||||||||||||||||||||||||||
| if album_id is not None: | ||||||||||||||||||||||||||||||
| cache[album_id] = scramble_id | ||||||||||||||||||||||||||||||
| if JmModuleConfig.SCRAMBLE_CACHE_LOCK is None: | ||||||||||||||||||||||||||||||
| from threading import Lock | ||||||||||||||||||||||||||||||
| JmModuleConfig.SCRAMBLE_CACHE_LOCK = Lock() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return scramble_id | ||||||||||||||||||||||||||||||
| with JmModuleConfig.SCRAMBLE_CACHE_LOCK: | ||||||||||||||||||||||||||||||
| # double-check after acquiring lock | ||||||||||||||||||||||||||||||
| if photo_id in cache: | ||||||||||||||||||||||||||||||
| return cache[photo_id] | ||||||||||||||||||||||||||||||
| if album_id is not None and album_id in cache: | ||||||||||||||||||||||||||||||
| return cache[album_id] | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| scramble_id = self.fetch_scramble_id(photo_id) | ||||||||||||||||||||||||||||||
| cache[photo_id] = scramble_id | ||||||||||||||||||||||||||||||
| if album_id is not None: | ||||||||||||||||||||||||||||||
| cache[album_id] = scramble_id | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return scramble_id | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def fetch_detail_entity(self, jmid, clazz: Type[DetailType]) -> DetailType: | ||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
|
|
@@ -963,16 +968,16 @@ def raise_if_resp_should_retry(self, resp, is_image): | |||||||||||||||||||||||||||||
| msg = JmModuleConfig.JM_ERROR_STATUS_CODE.get(code, f'HTTP状态码: {code}') | ||||||||||||||||||||||||||||||
| ExceptionTool.raises_resp(f"禁漫API异常响应, {msg}", resp) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| url = resp.request.url | ||||||||||||||||||||||||||||||
| url = getattr(resp, 'url', '') or getattr(getattr(resp, 'request', None), 'url', '') | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if self.API_SCRAMBLE in url: | ||||||||||||||||||||||||||||||
| # /chapter_view_template 这个接口不是返回json数据,不做检查 | ||||||||||||||||||||||||||||||
| return resp | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| text = resp.text | ||||||||||||||||||||||||||||||
| for char in text: | ||||||||||||||||||||||||||||||
| # 只检查前1024个字符,避免遍历大型HTML页面 | ||||||||||||||||||||||||||||||
| for char in text[:1024]: | ||||||||||||||||||||||||||||||
| if char not in (' ', '\n', '\t'): | ||||||||||||||||||||||||||||||
| # 找到第一个有效字符 | ||||||||||||||||||||||||||||||
| ExceptionTool.require_true( | ||||||||||||||||||||||||||||||
| char == '{', | ||||||||||||||||||||||||||||||
| f'请求不是json格式,强制重试!响应文本: [{JmcomicText.limit_text(text, 200)}]' | ||||||||||||||||||||||||||||||
|
|
@@ -1099,10 +1104,12 @@ def __init__(self, future, after_done_callback): | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def result(self): | ||||||||||||||||||||||||||||||
| if not self.done: | ||||||||||||||||||||||||||||||
| result = self.future.result() | ||||||||||||||||||||||||||||||
| self._result = result | ||||||||||||||||||||||||||||||
| self.done = True | ||||||||||||||||||||||||||||||
| self.future = None # help gc | ||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||
| result = self.future.result() | ||||||||||||||||||||||||||||||
| self._result = result | ||||||||||||||||||||||||||||||
| finally: | ||||||||||||||||||||||||||||||
| self.done = True | ||||||||||||||||||||||||||||||
| self.future = None # help gc | ||||||||||||||||||||||||||||||
| self.after_done_callback() | ||||||||||||||||||||||||||||||
|
Comment on lines
+1107
to
1113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Run the cache-removal callback in the If Proposed fix def result(self):
if not self.done:
try:
result = self.future.result()
self._result = result
finally:
self.done = True
self.future = None # help gc
- self.after_done_callback()
+ self.after_done_callback()
return self._result📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return self._result | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Avoid introducing RUF002 violations in these docstrings.
The newly added fullwidth punctuation is flagged by Ruff and can fail lint when
RUF002is enabled. Replace it with ASCII punctuation or deliberately suppress/configure this rule for Chinese documentation.Also applies to: 107-114, 190-192, 216-218
🧰 Tools
🪛 Ruff (0.15.21)
[warning] 81-81: Docstring contains ambiguous
,(FULLWIDTH COMMA). Did you mean,(COMMA)?(RUF002)
[warning] 85-85: Docstring contains ambiguous
,(FULLWIDTH COMMA). Did you mean,(COMMA)?(RUF002)
[warning] 87-87: Docstring contains ambiguous
((FULLWIDTH LEFT PARENTHESIS). Did you mean((LEFT PARENTHESIS)?(RUF002)
[warning] 87-87: Docstring contains ambiguous
)(FULLWIDTH RIGHT PARENTHESIS). Did you mean)(RIGHT PARENTHESIS)?(RUF002)
🤖 Prompt for AI Agents
Source: Linters/SAST tools