Navigate before initializing page state
This commit is contained in:
+18
-1
@@ -6,12 +6,13 @@ import secrets
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from typing import Annotated, Any
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
import speedtest # type: ignore[import-untyped]
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, field_validator
|
||||
|
||||
from admin.models import (
|
||||
delete_flow_config,
|
||||
@@ -91,6 +92,17 @@ class FlowConfigIn(BaseModel):
|
||||
scenario: str = "dynamic"
|
||||
stop_on_first_click: bool = False
|
||||
|
||||
@field_validator("target_url")
|
||||
@classmethod
|
||||
def validate_target_url(cls, value: str) -> str:
|
||||
value = value.strip()
|
||||
if value and "://" not in value:
|
||||
value = f"https://{value}"
|
||||
parsed = urlsplit(value)
|
||||
if parsed.scheme not in {"http", "https"} or not parsed.netloc:
|
||||
raise ValueError("Target URL must be a complete HTTP(S) URL")
|
||||
return value
|
||||
|
||||
|
||||
def _to_db_dict(body: FlowConfigIn) -> dict[str, Any]:
|
||||
return {
|
||||
@@ -181,6 +193,11 @@ async def add_to_batch_queue(body: BatchTaskIn, _: Auth) -> dict[str, object]:
|
||||
raise HTTPException(
|
||||
status_code=404, detail=f"Flow config {body.config_id} not found"
|
||||
)
|
||||
if not str(cfg.get("target_url") or "").strip():
|
||||
raise HTTPException(
|
||||
status_code=422,
|
||||
detail="The selected flow config has no Target URL. Edit and save it first.",
|
||||
)
|
||||
|
||||
result = enqueue(cfg, body.workers, body.total_runs, body.stagger_ms, body.headless)
|
||||
log.info(
|
||||
|
||||
Reference in New Issue
Block a user