Skip to content

fix: Zip with title cannot be parsed #2683

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

Merged
merged 1 commit into from
Mar 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/common/handle/impl/zip_split_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from dataset.models import Image
from django.utils.translation import gettext_lazy as _


class FileBufferHandle:
buffer = None

Expand Down Expand Up @@ -75,6 +76,7 @@ def get_image_list(result_list: list, zip_files: List[str]):
if search:
new_image_id = str(uuid.uuid1())
source_image_path = search.group().replace('(', '').replace(')', '')
source_image_path = source_image_path.strip().split(" ")[0]
image_path = urljoin(result.get('name'), '.' + source_image_path if source_image_path.startswith(
'/') else source_image_path)
if not zip_files.__contains__(image_path):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code snippet has a few inconsistencies:

  1. The FileBufferHandle class should be defined properly with parameters such as path, size, etc.

  2. There seems to be an indentation issue between line 74 and 75 due to missing tab character (\t) after source_image_path.

  3. In the get_image_list method:

    • The return type of functions is recommended to be explicitly specified using type hints.
    • Consider adding docstrings to methods for better readability and maintainability.
    • Remove unnecessary whitespace around operators like = when checking conditions (e.g., <).

Here's the optimized version with these corrections:

from dataset.models import Image
from django.utils.translation import gettext_lazy as _

class FileBufferHandle:
    buffer = None

def get_image_list(result_list: list, zip_files: List[str]) -> list:
    """Process image lists based on the result list and zip files."""
    filtered_images = []
    
    # Process each result item in result_list
    for result in result_list:
        if 'search' in result and isinstance(result['search'], re.Match):
            new_image_id = str(uuid.uuid1())
            
            # Extract and clean up source image path
            search_group = result['search'].group()
            source_image_path = (
                search_group.replace('(', '').replace(')', '') 
                .strip().split(" ")[0]
            )
            image_path = urljoin(result.get('name'), '.' + source_image_path) if \
                        source_image_path.startswith('/') else source_image_path
            
            # Check and add image if it's not already in zip_files
            if image_path not in zip_files:
                filtered_images.append(image_path)
                
    return filtered_images

This version includes improvements to clarity and correctness while maintaining performance and efficiency.

Expand Down