feat: add 'transparent' image model and refactor HAR provider auth flow

- Added "transparent" to `image_models` in `PollinationsAI` and mapped it to "gptimage"
- Modified transparent flag handling in `_generate_image` call in `PollinationsAI`
- Removed unused `cls.get_models()` call from image generation method in `PollinationsAI`
- Replaced `AsyncGeneratorProvider` with `AsyncAuthedProvider` in `HarProvider`
- Implemented `on_auth_async` in `HarProvider` to support browser-based auth via `nodriver`
- Replaced `create_async_generator` with `create_authed` in `HarProvider` to support `AuthResult`
- Removed custom `headers` in HAR post requests; used `auth_result.get_dict()` for `StreamSession`
- Refactored `Video` provider to support optional search in `get_response`
- Added `search` parameter to `RequestConfig.get_response` and `Video.create_async_generator`
- Improved browser automation and element interaction logic in `Video` provider
- Extracted video request interception to collect URLs using `nodriver`
- Reduced video polling loop timeout from 600 to 300 iterations in `Video`
- Updated CLI `client.py` to fix handling of `conversation.conversation` assignment
- Fixed argparse config: removed `nargs='?'` and added `metavar` for `--conversation-file`
- Improved image metadata extraction in API and backend when Pillow is available
- Modified `ImageResponse.__str__` to output HTML anchor/image tags with dimensions if present
- Added support for returning `target_path` from `copy_media` if `return_target` is True
- Changed default image processing size in `process_image` from 800x400 to 400x400
- Disabled RGBA-to-RGB flattening in `process_image`
- Improved `get_args_from_nodriver` to ensure proper referer and cookie handling
- Added helper `get_target_paths_and_urls` in `Api` to extract image dimensions from disk paths
This commit is contained in:
hlohaus 2025-07-11 01:46:32 +02:00
parent 48e3577033
commit 3c66fa114a
14 changed files with 207 additions and 127 deletions

View file

@ -127,7 +127,8 @@ async def copy_media(
target: str = None,
thumbnail: bool = False,
ssl: bool = None,
timeout: Optional[int] = None
timeout: Optional[int] = None,
return_target: bool = False
) -> list[str]:
"""
Download and store images locally with Unicode-safe filenames
@ -141,7 +142,8 @@ async def copy_media(
media_dir = os.path.join(media_dir, "thumbnails")
if not os.path.exists(media_dir):
os.makedirs(media_dir, exist_ok=True)
if headers is not None or cookies is not None:
add_url = False # Do not add URL if headers or cookies are provided
async with ClientSession(
connector=get_connector(proxy=proxy),
cookies=cookies,
@ -206,9 +208,12 @@ async def copy_media(
except ValueError:
pass
if thumbnail:
return "/thumbnail/" + os.path.basename(target_path)
# Build URL relative to media directory
return f"/media/{os.path.basename(target_path)}" + ('?' + (add_url if isinstance(add_url, str) else '' + 'url=' + quote(image)) if add_url and not image.startswith('data:') else '')
uri = "/thumbnail/" + os.path.basename(target_path)
else:
uri = f"/media/{os.path.basename(target_path)}" + ('?' + (add_url if isinstance(add_url, str) else '' + 'url=' + quote(image)) if add_url and not image.startswith('data:') else '')
if return_target:
return uri, target_path
return uri
except (ClientError, IOError, OSError, ValueError) as e:
debug.error(f"Image copying failed:", e)