handler module acts as the main entry point for processing manga URLs. It parses incoming URLs and routes them to the appropriate site-specific handler based on the domain.
process_entry()
Main router function that redirects download requests to the appropriate site handler based on the URL domain.Parameters
The manga chapter or gallery URL submitted by the user.
Function to emit asynchronous log messages to the frontend. Accepts a string message as its parameter.
Function returning a boolean to determine if the user cancelled the process. Returns
True if cancelled.Optional function to emit progress updates to the frontend. Receives
(current, total) as parameters.Returns
This is a side-effect function that drives the download processing. It does not return a value.
Usage example
HANDLERS
List of instantiated site-specific handler objects. Each handler implements the same interface withget_supported_domains() and process() methods.
Routing logic
The handler uses a secure domain matching approach to route requests:- URL parsing: Extracts the hostname from the provided URL using
urlparse() - Domain validation: Iterates through
HANDLERSand checks if the hostname contains any supported domain - Handler delegation: Calls the first matching handler’s
process()method - Error handling: Returns an error message if no handler supports the domain
SSRF security validation
The routing logic includes protection against Server-Side Request Forgery (SSRF) attacks:hostname rather than performing a simple substring search on the full URL. This prevents attackers from injecting malicious URLs like:
Error handling
The module handles two main error scenarios:- Invalid URL: If the URL cannot be parsed, logs
[ERROR] Invalid URL provided. - Unsupported website: If no handler matches the domain, logs
[ERROR] Unsupported website.
log_callback function and cause the process to exit gracefully.