fix(proxy): correct URL composition for CDNJS

Updated the URL construction within the proxy function to correctly reference CDNJS URLs. Previously the variable name mistakenly suggested an old CDN (jsdelivr), potentially leading to confusion and incorrect URL referencing. This change ensures accuracy and consistency when fetching and streaming resources.
This commit is contained in:
Kumi 2024-08-03 16:39:46 +02:00
parent c519a056c2
commit ce9e34f55e
Signed by: kumi
GPG key ID: ECBCC9082395383F

6
app.py
View file

@ -16,13 +16,13 @@ def home():
@app.route("/<path:url>") @app.route("/<path:url>")
def proxy(url): def proxy(url):
jsdelivr_url = f"https://cdnjs.cloudflare.com/{url}" cdnjs_url = f"https://cdnjs.cloudflare.com/{url}"
def generate(): def generate():
# Subfunction to allow streaming the data instead of # Subfunction to allow streaming the data instead of
# downloading all of it at once # downloading all of it at once
try: try:
with urlopen(unquote(url)) as data: with urlopen(unquote(cdnjs_url)) as data:
while True: while True:
chunk = data.read(1024 * 1024) chunk = data.read(1024 * 1024)
if not chunk: if not chunk:
@ -32,7 +32,7 @@ def proxy(url):
abort(e.code) abort(e.code)
try: try:
with urlopen(unquote(jsdelivr_url)) as data: with urlopen(unquote(cdnjs_url)) as data:
content_type = data.headers["content-type"] content_type = data.headers["content-type"]
except HTTPError as e: except HTTPError as e:
abort(e.code) abort(e.code)