返回提交历史
Modified
g4f/Provider/PollinationsAI.py
+0
-1
Modified
g4f/image/copy_images.py
+2
-2
Modified
g4f/providers/response.py
+5
-5
XFEstudio/gpt4free
quote_url
2812c309
代码差异
3 个文件
+7
-8
@@ -422,7 +422,6 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
422
422
nonlocal finished
423
423
try:
424
424
async with session.get(get_url_with_seed(i, seed), allow_redirects=False, headers=headers) as response:
425
debug.log("GET", response.status, response.url)
426
425
await raise_for_status(response)
427
426
except Exception as e:
428
427
responses.add(e)
@@ -15,7 +15,7 @@ from ..typing import Optional, Cookies, Union
15
15
from ..requests.aiohttp import get_connector
16
16
from ..image import MEDIA_TYPE_MAP, EXTENSIONS_MAP
17
17
from ..tools.files import secure_filename
18
from ..providers.response import ImageResponse, AudioResponse, VideoResponse
18
from ..providers.response import ImageResponse, AudioResponse, VideoResponse, quote_url
19
19
from ..Provider.template import BackendApi
20
20
from . import is_accepted_format, extract_data_uri
21
21
from .. import debug
@@ -50,7 +50,7 @@ def ensure_media_dir():
50
50
def get_source_url(image: str, default: str = None) -> str:
51
51
"""Extract original URL from image parameter if present"""
52
52
if "url=" in image:
53
decoded_url = unquote(image.split("url=", 1)[1])
53
decoded_url = quote_url(image.split("url=", 1)[1])
54
54
if decoded_url.startswith(("http://", "https://")):
55
55
return decoded_url
56
56
return default
@@ -4,7 +4,7 @@ import re
4
4
import base64
5
5
from typing import Union, Dict, List, Optional
6
6
from abc import abstractmethod
7
from urllib.parse import quote_plus, unquote_plus
7
from urllib.parse import quote, unquote
8
8
9
9
def is_content(chunk):
10
10
if isinstance(chunk, Reasoning):
@@ -25,12 +25,12 @@ def quote_url(url: str) -> str:
25
25
"""
26
26
# Only unquote if needed to avoid double-unquoting
27
27
if '%' in url:
28
url = unquote_plus(url)
28
url = unquote(url)
29
29
30
30
url_parts = url.split("//", maxsplit=1)
31
31
# If there is no "//" in the URL, then it is a relative URL
32
32
if len(url_parts) == 1:
33
return quote_plus(url_parts[0], '/?&=#')
33
return quote(url_parts[0], '/?&=#')
34
34
35
35
protocol, rest = url_parts
36
36
domain_parts = rest.split("/", maxsplit=1)
@@ -39,7 +39,7 @@ def quote_url(url: str) -> str:
39
39
return f"{protocol}//{domain_parts[0]}"
40
40
41
41
domain, path = domain_parts
42
return f"{protocol}//{domain}/{quote_plus(path, '/?&=#')}"
42
return f"{protocol}//{domain}/{quote(path, '/?&=#')}"
43
43
44
44
def quote_title(title: str) -> str:
45
45
"""
@@ -66,7 +66,7 @@ def format_link(url: str, title: Optional[str] = None) -> str:
66
66
"""
67
67
if title is None:
68
68
try:
69
title = unquote_plus(url.split("//", maxsplit=1)[1].split("?")[0].replace("www.", ""))
69
title = unquote(url.split("//", maxsplit=1)[1].split("?")[0].replace("www.", ""))
70
70
except IndexError:
71
71
title = url
72
72
return f"[{quote_title(title)}]({quote_url(url)})"