Skip to content

修复JSON解析失败(替换2处解析逻辑 , 替换2处解析逻辑)#475

Closed
RSLN-creator wants to merge 11 commits into
hect0x7:masterfrom
RSLN-creator:master
Closed

修复JSON解析失败(替换2处解析逻辑 , 替换2处解析逻辑)#475
RSLN-creator wants to merge 11 commits into
hect0x7:masterfrom
RSLN-creator:master

Conversation

@RSLN-creator

@RSLN-creator RSLN-creator commented Sep 8, 2025

Copy link
Copy Markdown
Contributor
  1. jm_toolkit.py 中添加了 safe_parse_json 函数,自动清理响应文本中的多余内容。
  2. jm_client_impl.py 中替换了两处直接使用 json.loads 的代码,改用 safe_parse_json
  3. 解决了因服务器返回日志导致的 JSON 解析失败问题。
Snipaste_2025-09-08_23-14-27

Summary by CodeRabbit

  • Bug Fixes

    • Improved resilience when parsing API responses, preventing failures on malformed or wrapped JSON.
    • More reliable domain switching through refined header handling.
    • Stabilized add-to-favorites and API-domain retrieval by using safer response parsing.
    • Album comments now behave consistently when no parent comment is specified.
    • Reduced edge-case failures when loading images by improving fallback handling.
  • Documentation

    • Updated the example download workflow placeholder to be clearer for users configuring album IDs.

@github-actions

github-actions Bot commented Sep 8, 2025

Copy link
Copy Markdown

To prevent beginners from mistakenly submitting PRs,
if your PR only modifies the usage/workflow_download.py file,
it will be automatically closed.
If you really want to submit a PR, please reopen it yourself.
Make sure you know what you are doing!

@github-actions github-actions Bot closed this Sep 8, 2025
@coderabbitai

coderabbitai Bot commented Sep 8, 2025

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

Walkthrough

Adds safe JSON parsing utilities and updates multiple client methods to use them. Modifies header/domain update logic, adjusts default parameters in public methods/constructors, and changes several control-flow and literals to non-ASCII tokens. Updates a placeholder string in a workflow script. Minor caching list punctuation change.

Changes

Cohort / File(s) Summary
Parsing utilities (new)
src/jmcomic/jm_toolkit.py
Added clean_response_text(text) and safe_parse_json(text); imports json and JsonResolveFailException. These sanitize response text to extract/parse JSON and raise JsonResolveFailException on failure.
Client JSON handling and domain/header updates
src/jmcomic/jm_client_impl.py
Replaced direct JSON parsing with safe_parse_json in multiple paths (e.g., add_favorite_album, req_api_domain_server). Changed domain header assembly in update_request_with_specify_domain to merge with new_html_headers(domain) via kwargs.get(..., ...).
Public signatures and defaults
src/jmcomic/jm_client_impl.py
Changed defaults: album_comment(..., originator='', status='true', comment_id=无) and PhotoConcurrentFetcherProxy.__init__(..., max_workers=无, executors=无).
Control-flow and literals substitutions
src/jmcomic/jm_client_impl.py
Widespread substitutions of Python tokens/literals with non-ASCII tokens (e.g., , , ), affecting conditional checks, loops, defaults, attribute access (e.g., future。result(), dict。pop), and string punctuation. Updated decode condition and cache list punctuation in JmHtmlClient.func_to_cache. Modified fetch_scramble_id defaults and combined-condition syntax.
Workflow placeholder
usage/workflow_download.py
In the placeholder multiline string for jm_albums, a line changed from "-" to "id". No logic changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client as Jmcomic Client
  participant HTTP as HTTP Server
  participant TK as Toolkit (safe_parse_json)

  rect rgb(238,245,255)
    note right of Client: Add favorite album / fetch domain JSON
    Client->>HTTP: Send request
    HTTP-->>Client: Response (text)
  end

  alt Parse JSON (sanitized)
    Client->>TK: safe_parse_json(response.text)
    TK->>TK: clean_response_text(text)
    TK-->>Client: dict (parsed JSON)
    Client->>Client: Proceed with logic
  else Invalid/dirty JSON
    Client->>TK: safe_parse_json(response.text)
    TK-->>Client: JsonResolveFailException
    Client->>Client: Handle error path
  end
Loading
sequenceDiagram
  autonumber
  participant Client as Jmcomic Client
  participant Headers as Header Builder
  participant Domain as Domain Config

  rect rgb(245,255,245)
    note right of Client: Switch/request with specified domain
    Client->>Domain: Select target domain
    Client->>Headers: kwargs.get('headers', ...) + new_html_headers(domain)
    Headers-->>Client: Merged headers
    Client->>Client: Update request config
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

A rabbit taps keys with a careful grin,
Scrubs JSON crumbs, lets clean bytes in.
Domains realign, headers recombine,
Defaults hop to a different sign.
With whiskered wit and gentle cheer,
Ship it safe—carrots and caches near. 🥕


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 49c4891 and 232844d.

📒 Files selected for processing (3)
  • src/jmcomic/jm_client_impl.py (14 hunks)
  • src/jmcomic/jm_toolkit.py (1 hunks)
  • usage/workflow_download.py (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant