-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Dev #508
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
Dev #508
Changes from all commits
1493564
70dd24f
733b040
56997e8
73fe17e
8df9bb2
29ee70d
2018e41
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 |
|---|---|---|
|
|
@@ -414,6 +414,22 @@ def get_album_cover_url(cls, | |
| path = f'/media/albums/{cls.parse_to_jm_id(album_id)}{size}.jpg' | ||
| return cls.format_url(path, image_domain) | ||
|
|
||
| @classmethod | ||
| def compare_versions(cls, v1: str, v2: str) -> int: | ||
| parts1 = list(map(int, v1.split("."))) | ||
| parts2 = list(map(int, v2.split("."))) | ||
|
|
||
| # 补齐长度 | ||
| length = max(len(parts1), len(parts2)) | ||
| parts1 += [0] * (length - len(parts1)) | ||
| parts2 += [0] * (length - len(parts2)) | ||
|
|
||
| if parts1 > parts2: | ||
| return 1 # v1 大 | ||
| elif parts1 < parts2: | ||
| return -1 # v2 大 | ||
| else: | ||
| return 0 # 相等 | ||
|
Comment on lines
+417
to
+432
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. Add error handling for invalid version strings. The Consider adding defensive error handling: 🛡️ Proposed fix with error handling @classmethod
def compare_versions(cls, v1: str, v2: str) -> int:
+ try:
parts1 = list(map(int, v1.split(".")))
parts2 = list(map(int, v2.split(".")))
+ except (ValueError, AttributeError) as e:
+ jm_log('version.compare.error', f'Invalid version format: v1={v1}, v2={v2}, error={e}')
+ return 0 # Treat as equal if comparison fails
# 补齐长度
length = max(len(parts1), len(parts2))
parts1 += [0] * (length - len(parts1))
parts2 += [0] * (length - len(parts2))
if parts1 > parts2:
return 1 # v1 大
elif parts1 < parts2:
return -1 # v2 大
else:
return 0 # 相等🤖 Prompt for AI Agents |
||
|
|
||
| # 支持dsl: #{???} -> os.getenv(???) | ||
| JmcomicText.dsl_replacer.add_dsl_and_replacer(r'\$\{(.*?)\}', JmcomicText.match_os_env) | ||
|
|
||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: hect0x7/JMComic-Crawler-Python
Length of output: 538
🏁 Script executed:
Repository: hect0x7/JMComic-Crawler-Python
Length of output: 1020
🏁 Script executed:
Repository: hect0x7/JMComic-Crawler-Python
Length of output: 56
🏁 Script executed:
Repository: hect0x7/JMComic-Crawler-Python
Length of output: 1313
🏁 Script executed:
Repository: hect0x7/JMComic-Crawler-Python
Length of output: 358
🏁 Script executed:
Repository: hect0x7/JMComic-Crawler-Python
Length of output: 1189
🏁 Script executed:
Repository: hect0x7/JMComic-Crawler-Python
Length of output: 715
🏁 Script executed:
Repository: hect0x7/JMComic-Crawler-Python
Length of output: 164
🏁 Script executed:
Repository: hect0x7/JMComic-Crawler-Python
Length of output: 2749
🏁 Script executed:
Repository: hect0x7/JMComic-Crawler-Python
Length of output: 3887
🏁 Script executed:
Repository: hect0x7/JMComic-Crawler-Python
Length of output: 728
🏁 Script executed:
Repository: hect0x7/JMComic-Crawler-Python
Length of output: 1130
Add error handling for version comparison failures.
The
compare_versions()call at line 777 lacks defensive error handling. If the API response contains a malformedjm3_versionfield (non-numeric segments),compare_versions()will raise aValueErrorwhen attempting to parse version parts. Wrap the comparison in a try-catch block to handle version comparison failures gracefully and prevent crashes on unexpected API data.🧰 Tools
🪛 Ruff (0.14.10)
776-776:
JmModuleConfigmay be undefined, or defined from star imports(F405)
777-777:
JmcomicTextmay be undefined, or defined from star imports(F405)
777-777:
JmMagicConstantsmay be undefined, or defined from star imports(F405)
779-779:
jm_logmay be undefined, or defined from star imports(F405)
779-779:
JmMagicConstantsmay be undefined, or defined from star imports(F405)
780-780:
JmMagicConstantsmay be undefined, or defined from star imports(F405)
🤖 Prompt for AI Agents