Skip to content
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 #175

Closed
wants to merge 4 commits into from
Closed

Dev #175

wants to merge 4 commits into from

Conversation

hect0x7
Copy link
Owner

@hect0x7 hect0x7 commented Dec 7, 2023

Summary by CodeRabbit

  • New Features

    • Search functionality now available with a new search bar.
    • Users can now filter downloads with updated filtering methods.
    • Favorite albums can be added to collections.
  • Improvements

    • Enhanced clarity in workflow descriptions for better user understanding.
    • Improved error handling and retry logic in network requests.
    • Headers now include 'origin' field for improved request handling.
  • Bug Fixes

    • Fixed issues with domain handling in client requests.
    • Resolved incorrect type annotations in entity classes.
  • Documentation

    • Updated tutorial with new filtering method names and usage.
    • Added docstrings for page_count and page_size properties.
  • Refactor

    • Streamlined option construction by removing unused parameters.
    • Renamed filtering methods across various classes for consistency.
  • Style

    • Adjusted regular expression patterns for better matching.
  • Tests

    • Updated test cases to reflect changes in domain handling.
  • Chores

    • Bumped software version to '2.4.7'.
    • Cleaned up import statements for better code organization.
  • Revert

    • No reverts in this release.

Copy link

github-actions bot commented Dec 7, 2023

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 Dec 7, 2023
Copy link

coderabbitai bot commented Dec 7, 2023

Walkthrough

The changes across various files in the codebase primarily involve updates to workflow configurations, clearer descriptions in YAML files, renaming of methods and parameters in Python classes, addition of new methods and attributes, and updates to version numbers. The alterations enhance clarity, extend functionality, and improve the software's maintainability.

Changes

File Path Change Summary
.github/workflows/... Added branches-ignore key to workflow configurations.
assets/docs/sources/tutorial/...
src/jmcomic/jm_downloader.py
src/jmcomic/jm_plugin.py
Renamed filter_iter_objs to do_filter and updated related logic.
src/jmcomic/__init__.py
src/jmcomic/jm_client_impl.py
src/jmcomic/jm_entity.py
src/jmcomic/jm_option.py
src/jmcomic/jm_toolkit.py
tests/test_jmcomic/test_jm_custom.py
usage/workflow_download.py
Added new methods, attributes, and updated existing ones. Improved type annotations and docstrings.
src/jmcomic/jm_client_interface.py Added add_favorite_album method.
src/jmcomic/jm_config.py Added DEFAULT_CLIENT_CACHE attribute and updated HTTP headers logic.

🐇✨
In the code where rabbits hop,
Changes abound, they never stop.
Methods renamed, docs refined,
With every commit, the code does shine. 🌟
🐾


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a7e8ea2 and d9b16c9.
Files selected for processing (14)
  • .github/workflows/close_specific_pr.yml (1 hunks)
  • .github/workflows/download_dispatch.yml (1 hunks)
  • assets/docs/sources/tutorial/5_filter.md (3 hunks)
  • src/jmcomic/init.py (1 hunks)
  • src/jmcomic/jm_client_impl.py (22 hunks)
  • src/jmcomic/jm_client_interface.py (1 hunks)
  • src/jmcomic/jm_config.py (3 hunks)
  • src/jmcomic/jm_downloader.py (3 hunks)
  • src/jmcomic/jm_entity.py (5 hunks)
  • src/jmcomic/jm_option.py (5 hunks)
  • src/jmcomic/jm_plugin.py (1 hunks)
  • src/jmcomic/jm_toolkit.py (2 hunks)
  • tests/test_jmcomic/test_jm_custom.py (4 hunks)
  • usage/workflow_download.py (4 hunks)
Files skipped from review due to trivial changes (2)
  • .github/workflows/download_dispatch.yml
  • src/jmcomic/jm_entity.py
Additional comments: 39
assets/docs/sources/tutorial/5_filter.md (1)
  • 30-37: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [9-59]

The summary suggests that the logic inside the do_filter methods has been updated, but the hunks only show the renaming of the method and parameter. Please verify if the logic changes are correctly implemented and if they are not visible in the hunks provided.

src/jmcomic/__init__.py (2)
  • 5-5: Version number updated correctly.

  • 7-8: New imports added. Verify that these modules are used within the file and that there are no namespace conflicts due to the wildcard imports.


New imports for .api and .jm_plugin are confirmed to be present in src/jmcomic/__init__.py. No namespace conflicts were detected in the current file. Ensure that the imported modules are utilized and that their inclusion aligns with the project's import practices.

src/jmcomic/jm_client_impl.py (16)
  • 1-1: The addition of the Lock import is appropriate for the new usage of thread locking later in the code.

  • 30-30: The addition of the __username private attribute is consistent with the summary and is used to assist the favorite_folder method.

  • 64-75: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [58-119]

The modifications to the request_with_retry method to support retry and domain switching mechanisms are consistent with the summary and appear to be correctly implemented.

  • 121-125: The update_request_with_specify_domain method is added as a placeholder for subclasses to override, which is a common pattern in object-oriented design for providing hooks for customization.

  • 225-251: The addition of the add_favorite_album method in the JmHtmlClient class is consistent with the summary and provides new functionality for managing favorite albums.

  • 348-351: The modification of the login method to set the __username attribute is consistent with the summary and is a logical place to capture the username after a successful login.

  • 357-362: The modification of the favorite_folder method to use the __username attribute is consistent with the summary and ensures that the method has the necessary username information to function.

  • 375-380: The get_username_from_cookies method is added as a placeholder for future implementation, which is a common practice when preparing for future features.

  • 400-404: The modification of the update_request_with_specify_domain method to update request headers with a specific domain is consistent with the summary and is an important part of the domain switching mechanism.

  • 407-408: The addition of the raise_request_error method is consistent with the summary and provides a centralized way to handle request errors.

  • 445-451: The modification of the album_comment method to include logging is consistent with the summary and provides better traceability for comments.

  • 785-791: The addition of the require_resp_status_ok method in the JmApiClient class is consistent with the summary and is used to check the status field in the returned data.

  • 793-806: The modification of the req_api method to include a new parameter require_success is consistent with the summary and allows for handling the response based on the success of the API call.

  • 808-809: The update_request_with_specify_domain method in the JmApiClient class is added as a placeholder for subclasses to override, which is a common pattern in object-oriented design for providing hooks for customization.

  • 858-858: The addition of the ensure_have_cookies method in the JmApiClient class is consistent with the summary and ensures that the client has cookies set, which is necessary for the mobile API client.

  • 924-948: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [887-947]

The addition of the FutureClientProxy class is consistent with the summary and provides a way to wrap client calls in futures for asynchronous execution.

src/jmcomic/jm_client_interface.py (2)
  • 232-239: The addition of the add_favorite_album method to the JmUserClient class is consistent with the summary and the PR objectives. This method is designed to be overridden by subclasses, as indicated by the raise NotImplementedError. Ensure that subclasses of JmUserClient implement this method.

  • 232-239: Verify if the new method add_favorite_album has been implemented in subclasses of JmUserClient.


The verification process did not find any subclasses of JmUserClient that implement the new add_favorite_album method. This could mean that there are no subclasses in the codebase, or that the method has not been implemented yet in existing subclasses.

src/jmcomic/jm_config.py (3)
  • 260-266: The addition of the 'origin' field in the new_html_headers function is confirmed and aligns with the summary.

  • 297-305: The addition of the DEFAULT_CLIENT_CACHE attribute and its usage in the new_postman function is confirmed and aligns with the summary.

  • 359-362: The option_default_dict method has been modified to use the cls.DEFAULT_CLIENT_CACHE for setting the client cache, which was not mentioned in the summary.

src/jmcomic/jm_downloader.py (2)
  • 139-149: The summary indicates that the do_filter method should use detail.is_xxx for type checking, but the provided code does not reflect this change. Please verify if the summary is accurate or if the code change was omitted.

  • 115-121: The refactoring of the execute_by_condition method to include self.do_filter(iter_objs) aligns with the summary's description of changes.

src/jmcomic/jm_option.py (5)
  • 279-283: The default method has been correctly updated to no longer accept proxies and domain parameters, aligning with the summary.

  • 385-414: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [363-423]

The new_jm_client method has been updated to replace the domain parameter with domain_list, which is consistent with the summary.

  • 387-410: The logic for handling the domain_list parameter in the new_jm_client method has been updated to support different types (list, str, dict) and to provide a default value if none is provided. This is a good enhancement for flexibility and robustness.

  • 454-455: The decide_client_domain method is not shown in the provided hunks, but the removal of proxies and domain parameters in other methods suggests that similar changes would have been made here. It would be important to ensure that this method's logic is consistent with the new approach to domain handling.


The decide_client_domain method still exists in src/jmcomic/jm_option.py and appears to have been updated, as the parameters related to proxies and domain are no longer present in its signature. This aligns with the changes made to other methods in the same class, indicating a consistent update to domain handling.

  • 385-414: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-470]

The hunks include additional changes and logic not mentioned in the summary, such as CacheRegistry, DirRule, and various methods within JmOption. While these changes are not covered by the summary, they appear to be internal and not related to the exported entities, which is the focus of the summary.

src/jmcomic/jm_plugin.py (1)
  • 210-214: The method filter_iter_objs has been correctly renamed to do_filter in the FindUpdateDownloader class, aligning with the refactoring across the codebase.
src/jmcomic/jm_toolkit.py (2)
  • 55-59: The addition of the new regular expression pattern pattern_ajax_favorite_msg is correctly implemented and matches the summary.

  • 311-314: The modification in the require_match method to handle a None value for rindex is correctly implemented and matches the summary.

tests/test_jmcomic/test_jm_custom.py (4)
  • 77-77: The change in inheritance from JmcomicClient to AbstractJmClient for the MyClient class is noted and aligns with the summary provided.

  • 48-48: The update to the new_jm_client method call to use domain_list instead of domain is consistent with the changes described in the summary.

  • 62-62: The update to the new_jm_client method call to use domain_list instead of domain is consistent with the changes described in the summary.

  • 45-51: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [45-100]

No further issues or inconsistencies are found in the provided hunks. The changes appear to be consistent with the summary and the PR objectives.

usage/workflow_download.py (1)
  • 19-29: The env function is well-implemented and provides additional functionality to trim characters from environment variable values.

@@ -4,6 +4,7 @@ on:
pull_request:
paths:
- 'usage/workflow_download.py'
branches-ignore: [dev, ]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The branches-ignore entry has a trailing comma which is not necessary and could potentially cause issues with YAML parsing. It's best to remove it to avoid any ambiguity.

-    branches-ignore: [dev, ]
+    branches-ignore: [dev]

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
branches-ignore: [dev, ]
branches-ignore: [dev]

Comment on lines +203 to +215
class DoNotDownloadImage(JmDownloader):
"""
本类仅用于测试

用法:

JmModuleConfig.CLASS_DOWNLOADER = DoNotDownloadImage
"""

def download_by_image_detail(self, image: JmImageDetail, client: JmcomicClient):
# ensure make dir
self.option.decide_image_filepath(image)
pass
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DoNotDownloadImage class includes a download_by_image_detail method with a placeholder pass statement. If this method is intended for future implementation, consider adding a TODO comment or more descriptive documentation to clarify its purpose.

def filter_iter_objs(self, iter_objs: DownloadIterObjs):
if isinstance(iter_objs, JmPhotoDetail):
def do_filter(self, detail):
if detail.is_photo():
photo: JmPhotoDetail = iter_objs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable iter_objs is used within the method body but is not defined in the method signature. This should be updated to detail to match the method parameter.

-            photo: JmPhotoDetail = iter_objs
+            photo: JmPhotoDetail = detail

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
photo: JmPhotoDetail = iter_objs
photo: JmPhotoDetail = detail

def filter_iter_objs(self, iter_objs: DownloadIterObjs):
if not isinstance(iter_objs, JmAlbumDetail):
def do_filter(self, detail):
if not detail.is_album():
return iter_objs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable iter_objs is used within the method body but is not defined in the method signature. This should be updated to detail to match the method parameter.

-            return iter_objs
+            return detail

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return iter_objs
return detail

Comment on lines 69 to 82
def cover_option_config(option: JmOption):
dir_rule = get_env('DIR_RULE', None)
dir_rule = env('DIR_RULE', None)
if dir_rule is not None:
the_old = option.dir_rule
the_new = DirRule(dir_rule, base_dir=the_old.base_dir)
option.dir_rule = the_new

impl = get_env('CLIENT_IMPL', None)
impl = env('CLIENT_IMPL', None)
if impl is not None:
option.client.impl = impl

suffix = get_env('IMAGE_SUFFIX', None)
suffix = env('IMAGE_SUFFIX', None)
if suffix is not None:
option.download.image.suffix = fix_suffix(suffix)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 NOTE
Codebase verification is a beta feature.

The DirRule class is confirmed to exist in src/jmcomic/jm_option.py. However, the fix_suffix function could not be found in the codebase.

  • DirRule class is present and can be used as shown in the code snippet.
  • The fix_suffix function is not found and may need to be defined or imported to ensure the code works as intended.
Analysis chain

Verify that the DirRule and fix_suffix functions are defined and correctly handle the inputs provided by the env function.

Comment on lines 85 to 89
def log_before_raise():
jm_download_dir = get_env('JM_DOWNLOAD_DIR', workspace())
jm_download_dir = env('JM_DOWNLOAD_DIR', workspace())
mkdir_if_not_exists(jm_download_dir)

# 自定义异常抛出函数,在抛出前把HTML响应数据写到下载文件夹(日志留痕)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 NOTE
Codebase verification is a beta feature.

The mkdir_if_not_exists function is not found in the codebase, while the ExceptionTool class exists in src/jmcomic/jm_toolkit.py. The write_text function is also not found. The absence of mkdir_if_not_exists and write_text suggests that the code may fail if these functions are called without being defined elsewhere.

  • mkdir_if_not_exists: Function not found; code may fail if this function is called.
  • ExceptionTool: Class found in src/jmcomic/jm_toolkit.py.
  • write_text: Function not found; code may fail if this function is called.
Analysis chain

Verify that the mkdir_if_not_exists, ExceptionTool, and common.write_text functions are defined and correctly handle the inputs provided by the env function.

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