返回提交历史
Modified
g4f/config.py
+1
-1
Modified
g4f/gui/server/website.py
+20
-14
XFEstudio/gpt4free
Update download URL in website.py to use GITHUB_URL for improved version handling
130a4295
代码差异
2 个文件
+21
-15
@@ -27,4 +27,4 @@ DIST_DIR = f"./{STATIC_DOMAIN}/dist"
27
27
DEFAULT_MODEL = "openai/gpt-oss-120b"
28
28
JSDELIVR_URL = "https://cdn.jsdelivr.net/"
29
29
DOWNLOAD_URL = f"{JSDELIVR_URL}gh/{ORGANIZATION}/{STATIC_DOMAIN}/"
30
# DOWNLOAD_URL = f"https://raw.githubusercontent.com/{ORGANIZATION}/{STATIC_DOMAIN}/refs/heads/main/"
30
GITHUB_URL = f"https://raw.githubusercontent.com/{ORGANIZATION}/{STATIC_DOMAIN}/refs/heads/main/"
@@ -9,20 +9,20 @@ from flask import send_from_directory, redirect, request
9
9
from ...image.copy_images import secure_filename
10
10
from ...cookies import get_cookies_dir
11
11
from ...errors import VersionNotFoundError
12
from ...config import STATIC_URL, DOWNLOAD_URL, DIST_DIR, JSDELIVR_URL
12
from ...config import STATIC_URL, DOWNLOAD_URL, DIST_DIR, JSDELIVR_URL, GITHUB_URL
13
13
from ... import version
14
14
15
15
def redirect_home():
16
16
return redirect('/chat/')
17
17
18
def render(filename = "home", download_url: str = DOWNLOAD_URL):
18
def render(filename = "home", download_url: str = GITHUB_URL):
19
19
if download_url == DOWNLOAD_URL:
20
20
filename += ("" if "." in filename else ".html")
21
21
html = None
22
22
if os.path.exists(DIST_DIR) and not request.args.get("debug"):
23
23
path = os.path.abspath(os.path.join(os.path.dirname(DIST_DIR), filename))
24
24
if os.path.exists(path):
25
if download_url == DOWNLOAD_URL:
25
if download_url == GITHUB_URL:
26
26
html = open(path, 'r', encoding='utf-8').read()
27
27
else:
28
28
return send_from_directory(os.path.dirname(path), os.path.basename(path))
@@ -41,18 +41,24 @@ def render(filename = "home", download_url: str = DOWNLOAD_URL):
41
41
os.makedirs(cache_dir, exist_ok=True)
42
42
latest_version = quote(unquote(request.query_string.decode())) or str(latest_version)
43
43
if html is None:
44
response = requests.get(f"{download_url}{filename}{'?' + latest_version if latest_version and download_url == DOWNLOAD_URL else ''}")
45
if not response.ok:
46
found = None
47
for root, _, files in os.walk(cache_dir):
48
for file in files:
49
if file.startswith(secure_filename(filename)):
50
found = os.path.abspath(root), file
51
break
52
if found:
53
return send_from_directory(found[0], found[1])
54
else:
44
try:
45
response = requests.get(f"{download_url}{filename}{'?' + latest_version if latest_version and download_url == GITHUB_URL else ''}")
46
response.raise_for_status()
47
except requests.RequestException:
48
try:
49
response = requests.get(f"{DOWNLOAD_URL}{filename}{'?' + latest_version if latest_version and download_url == GITHUB_URL else ''}")
55
50
response.raise_for_status()
51
except requests.RequestException:
52
found = None
53
for root, _, files in os.walk(cache_dir):
54
for file in files:
55
if file.startswith(secure_filename(filename)):
56
found = os.path.abspath(root), file
57
break
58
if found:
59
return send_from_directory(found[0], found[1])
60
else:
61
raise
56
62
html = response.text
57
63
html = html.replace("../dist/", f"dist/")
58
64
html = html.replace("\"dist/", f"\"{STATIC_URL}dist/")