Jelajahi Sumber

web: remove viewlog route, use root with build_id param instead

There is no advantage of an extra route to open the same page. The query parameter on main route should do.
Shiv Tyagi 2 bulan lalu
induk
melakukan
9a5b701bc1
3 mengubah file dengan 8 tambahan dan 25 penghapusan
  1. 1 1
      web/static/js/add_build.js
  2. 3 3
      web/templates/index.html
  3. 4 21
      web/ui/router.py

+ 1 - 1
web/static/js/add_build.js

@@ -719,7 +719,7 @@ async function handleFormSubmit(event) {
         const result = await response.json();
         
         // Redirect to viewlog page
-        window.location.href = `/viewlog/${result.build_id}`;
+        window.location.href = `/?build_id=${result.build_id}`;
         
     } catch (error) {
         console.error('Error submitting build:', error);

+ 3 - 3
web/templates/index.html

@@ -127,12 +127,12 @@
     <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.min.js" integrity="sha384-mQ93GR66B00ZXjt0YO5KlohRA5SY2XofN4zfuZxLkoj1gXtW8ANNCe9d5Y3eG5eD" crossorigin="anonymous"></script>
     <script type="text/javascript" src="/static/js/index.js"></script>
 
-    {% if token != None %}
+    {% if build_id != None %}
     <script>
-        document.addEventListener("load", launchLogModal('{{token}}'));
+        document.addEventListener("load", launchLogModal('{{build_id}}'));
 
         // Poll every 5 seconds for auto-download
-        autoDownloadIntervalId = setInterval(tryAutoDownload, 5000, '{{token}}');
+        autoDownloadIntervalId = setInterval(tryAutoDownload, 5000, '{{build_id}}');
     </script>
     {% endif %}
 

+ 4 - 21
web/ui/router.py

@@ -14,38 +14,21 @@ templates = Jinja2Templates(directory=str(WEB_ROOT / "templates"))
 
 
 @router.get("/", response_class=HTMLResponse)
-async def index(request: Request, token: str = None):
+async def index(request: Request, build_id: str = None):
     """
     Render the main index page showing all builds.
 
     Args:
         request: FastAPI Request object
-        token: Optional build token to automatically show log modal
+        build_id: Optional build ID to automatically show log modal and
+            trigger artifact download on build completion
 
     Returns:
         Rendered HTML template
     """
     return templates.TemplateResponse(
         "index.html",
-        {"request": request, "token": token}
-    )
-
-
-@router.get("/viewlog/{token}", response_class=HTMLResponse)
-async def viewlog(request: Request, token: str):
-    """
-    Render the index page with a specific build log open.
-
-    Args:
-        request: FastAPI Request object
-        token: Build ID to show log for
-
-    Returns:
-        Rendered HTML template with token
-    """
-    return templates.TemplateResponse(
-        "index.html",
-        {"request": request, "token": token}
+        {"request": request, "build_id": build_id}
     )