mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-15 14:51:19 -08:00
quote_url
This commit is contained in:
parent
b5b48ae75c
commit
2812c30987
3 changed files with 7 additions and 8 deletions
|
|
@ -422,7 +422,6 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
|
|||
nonlocal finished
|
||||
try:
|
||||
async with session.get(get_url_with_seed(i, seed), allow_redirects=False, headers=headers) as response:
|
||||
debug.log("GET", response.status, response.url)
|
||||
await raise_for_status(response)
|
||||
except Exception as e:
|
||||
responses.add(e)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ from ..typing import Optional, Cookies, Union
|
|||
from ..requests.aiohttp import get_connector
|
||||
from ..image import MEDIA_TYPE_MAP, EXTENSIONS_MAP
|
||||
from ..tools.files import secure_filename
|
||||
from ..providers.response import ImageResponse, AudioResponse, VideoResponse
|
||||
from ..providers.response import ImageResponse, AudioResponse, VideoResponse, quote_url
|
||||
from ..Provider.template import BackendApi
|
||||
from . import is_accepted_format, extract_data_uri
|
||||
from .. import debug
|
||||
|
|
@ -50,7 +50,7 @@ def ensure_media_dir():
|
|||
def get_source_url(image: str, default: str = None) -> str:
|
||||
"""Extract original URL from image parameter if present"""
|
||||
if "url=" in image:
|
||||
decoded_url = unquote(image.split("url=", 1)[1])
|
||||
decoded_url = quote_url(image.split("url=", 1)[1])
|
||||
if decoded_url.startswith(("http://", "https://")):
|
||||
return decoded_url
|
||||
return default
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import re
|
|||
import base64
|
||||
from typing import Union, Dict, List, Optional
|
||||
from abc import abstractmethod
|
||||
from urllib.parse import quote_plus, unquote_plus
|
||||
from urllib.parse import quote, unquote
|
||||
|
||||
def is_content(chunk):
|
||||
if isinstance(chunk, Reasoning):
|
||||
|
|
@ -25,12 +25,12 @@ def quote_url(url: str) -> str:
|
|||
"""
|
||||
# Only unquote if needed to avoid double-unquoting
|
||||
if '%' in url:
|
||||
url = unquote_plus(url)
|
||||
url = unquote(url)
|
||||
|
||||
url_parts = url.split("//", maxsplit=1)
|
||||
# If there is no "//" in the URL, then it is a relative URL
|
||||
if len(url_parts) == 1:
|
||||
return quote_plus(url_parts[0], '/?&=#')
|
||||
return quote(url_parts[0], '/?&=#')
|
||||
|
||||
protocol, rest = url_parts
|
||||
domain_parts = rest.split("/", maxsplit=1)
|
||||
|
|
@ -39,7 +39,7 @@ def quote_url(url: str) -> str:
|
|||
return f"{protocol}//{domain_parts[0]}"
|
||||
|
||||
domain, path = domain_parts
|
||||
return f"{protocol}//{domain}/{quote_plus(path, '/?&=#')}"
|
||||
return f"{protocol}//{domain}/{quote(path, '/?&=#')}"
|
||||
|
||||
def quote_title(title: str) -> str:
|
||||
"""
|
||||
|
|
@ -66,7 +66,7 @@ def format_link(url: str, title: Optional[str] = None) -> str:
|
|||
"""
|
||||
if title is None:
|
||||
try:
|
||||
title = unquote_plus(url.split("//", maxsplit=1)[1].split("?")[0].replace("www.", ""))
|
||||
title = unquote(url.split("//", maxsplit=1)[1].split("?")[0].replace("www.", ""))
|
||||
except IndexError:
|
||||
title = url
|
||||
return f"[{quote_title(title)}]({quote_url(url)})"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue