Use query param for /status and unquote URL for vercel support
Change the /status endpoint to accept the target URL via a query parameter instead of a path component. Update client-side EventSource to call /status?url=... and import urllib.parse.unquote to decode the incoming URL. Return a 400 error when the url param is missing. This avoids routing/encoding issues with encoded URLs.
This commit is contained in:
+10
-4
@@ -7,7 +7,7 @@ import uuid
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from urllib.parse import urljoin, urlparse, quote
|
from urllib.parse import urljoin, urlparse, quote, unquote
|
||||||
from flask import request, Response
|
from flask import request, Response
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
@@ -435,7 +435,7 @@ html = """
|
|||||||
elapsedEl.textContent = UI_STRINGS.elapsed_template.replace('{seconds}', sec);
|
elapsedEl.textContent = UI_STRINGS.elapsed_template.replace('{seconds}', sec);
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
const evtSource = new EventSource('/status/' + encodeURIComponent(link));
|
const evtSource = new EventSource('/status?url=' + encodeURIComponent(link));
|
||||||
|
|
||||||
evtSource.addEventListener('step', function(e) {
|
evtSource.addEventListener('step', function(e) {
|
||||||
const data = JSON.parse(e.data);
|
const data = JSON.parse(e.data);
|
||||||
@@ -752,8 +752,14 @@ def main_page():
|
|||||||
return render_main_page()
|
return render_main_page()
|
||||||
|
|
||||||
|
|
||||||
@app.route("/status/<path:url>")
|
@app.route("/status")
|
||||||
def status_stream(url):
|
def status_stream():
|
||||||
|
raw_url = request.args.get("url", "")
|
||||||
|
url = unquote(raw_url)
|
||||||
|
|
||||||
|
if not url:
|
||||||
|
return "Missing URL", 400
|
||||||
|
|
||||||
strings = load_strings()
|
strings = load_strings()
|
||||||
job_id = str(uuid.uuid4())
|
job_id = str(uuid.uuid4())
|
||||||
with jobs_lock:
|
with jobs_lock:
|
||||||
|
|||||||
Reference in New Issue
Block a user