Skip to content

Commit

Permalink
fix #1541
Browse files Browse the repository at this point in the history
  • Loading branch information
DoroWolf committed Jan 13, 2025
1 parent 06c2115 commit a1a4745
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
7 changes: 5 additions & 2 deletions core/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,11 @@ def Config(q: str,
'''
if get_url:
v = CFGManager.get(q, default, str, secret, table_name, _global, _generate)
if v and v[-1] != '/':
v += '/'
if v:
if not re.match(r'^[a-zA-Z][a-zA-Z\d+\-.]*://', v):
v = "http://" + v
if v[-1] != '/':
v += '/'
else:
v = CFGManager.get(q, default, cfg_type, secret, table_name, _global, _generate)
return v
Expand Down
2 changes: 2 additions & 0 deletions core/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ async def get_():
timeout=timeout,
headers=headers,
params=params,
follow_redirects=True,
)
Logger.debug(f"[{resp.status_code}] {url}")
if logging_resp:
Expand Down Expand Up @@ -173,6 +174,7 @@ async def _post():
data=data,
headers=headers,
timeout=timeout,
follow_redirects=True,
)
Logger.debug(f"[{resp.status_code}] {url}")
if logging_resp:
Expand Down
9 changes: 5 additions & 4 deletions core/utils/web_render.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import traceback
from typing import Tuple, Optional, Union
from typing import Tuple, Optional
from urllib.parse import quote

from core.config import Config
from core.constants.info import Info
from core.logger import Logger
from core.utils.http import get_url

web_render = Config("web_render", secret=True, get_url=True)
web_render_local = Config("web_render_local", get_url=True)
web_render = Config("web_render", cfg_type=str, secret=True, get_url=True)
web_render_local = Config("web_render_local", cfg_type=str, get_url=True)


def webrender(
Expand All @@ -28,7 +29,7 @@ def webrender(
if method == "source":
url = "" if not url else url
if Info.web_render_status or _ignore_status:
return f"{(web_render_local if use_local else web_render)}source?url={url}"
return f"{(web_render_local if use_local else web_render)}source?url={quote(url)}"
else:
url = ""
if Info.web_render_status or _ignore_status:
Expand Down
2 changes: 1 addition & 1 deletion modules/mcmod/mcmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async def mcmod(msg, keyword: str, detail: bool = False):
endpoint = api_details if detail else api
search_url = endpoint + quote(keyword)
html = await get_url(
webrender("source", quote(search_url)), 200, request_private_ip=True
webrender("source", search_url), 200, request_private_ip=True
)
Logger.debug(html)
bs = BeautifulSoup(html, "html.parser")
Expand Down
9 changes: 3 additions & 6 deletions modules/wiki/utils/wikilib.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ async def get_json_from_api(self, api, _no_login=False, **kwargs) -> dict:
if api in redirect_list:
api = redirect_list[api]
if kwargs:
api = api + "?" + urllib.parse.urlencode(kwargs) + "&format=json"
api = f"{api}?{urllib.parse.urlencode(kwargs)}&format=json"
Logger.debug(api)
else:
raise ValueError("kwargs is None")
request_local = False
for x in request_by_web_render_list:
if x.match(api):
api = webrender("source", urllib.parse.quote(api))
api = webrender("source", api)
request_local = True
break

Expand Down Expand Up @@ -215,10 +215,7 @@ async def check_wiki_available(self):
except Exception:
try:
get_page = await get_url(self.url, status_code=None, fmt="text", headers=self.headers)
if (
get_page.find("<title>Attention Required! | Cloudflare</title>")
!= -1
):
if get_page.find("<title>Attention Required! | Cloudflare</title>") != -1:
return WikiStatus(
available=False,
value=False,
Expand Down
2 changes: 1 addition & 1 deletion schedulers/mcv_rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def get_article(version):

try:
html = await get_url(
webrender("source", quote(link)),
webrender("source", link),
attempt=1,
request_private_ip=True,
logging_err_resp=False,
Expand Down
2 changes: 1 addition & 1 deletion schedulers/minecraft_news.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def start_check_news():
baseurl = "https://www.minecraft.net"
url = "https://www.minecraft.net/content/minecraftnet/language-masters/en-us/articles/jcr:content/root/container/image_grid_a.articles.json"
try:
get_webrender = webrender("source", quote(url))
get_webrender = webrender("source", url)
if get_webrender == url:
Logger.debug("WebRender is not working, skip check minecraft news.")
return
Expand Down

0 comments on commit a1a4745

Please sign in to comment.