@@ -420,7 +420,6 @@ async def scan_status_get() -> AsyncIterator[str] | WerkzeugResponse:
420
420
421
421
if status == ScanStatus .DONE :
422
422
filename = data [0 ]
423
- APP_STORAGE ["scan_status" ] = None
424
423
return app .redirect (f"/{ filename } " )
425
424
426
425
progress : ScanProgress | None = None
@@ -472,9 +471,9 @@ async def root_get() -> AsyncIterator[str]:
472
471
)
473
472
474
473
475
- @app .post ("/" )
474
+ @app .post ("/" ) # type: ignore[type-var]
476
475
@pretty_exception
477
- async def root_post () -> WerkzeugResponse :
476
+ async def root_post () -> WerkzeugResponse | AsyncIterator [ str ] :
478
477
"""Handle page POST."""
479
478
multi_dict = await request .form
480
479
data = multi_dict .to_dict ()
@@ -488,6 +487,18 @@ async def root_post() -> WerkzeugResponse:
488
487
if device == "none" :
489
488
return app .redirect ("/scanners" )
490
489
490
+ raw_status = APP_STORAGE .get ("scan_status" )
491
+
492
+ if raw_status is not None :
493
+ status , * _data = raw_status
494
+ if status != ScanStatus .DONE :
495
+ return await send_error (
496
+ "Scan Already Currently Running" ,
497
+ "There is a scan request already running. Please wait for the previous scan to complete." ,
498
+ return_link = "/scan-status" ,
499
+ )
500
+ APP_STORAGE ["scan_status" ] = None
501
+
491
502
nursery : trio .Nursery | None = APP_STORAGE .get ("nursery" )
492
503
assert isinstance (nursery , trio .Nursery ), "Must be nursery"
493
504
@@ -497,6 +508,7 @@ async def root_post() -> WerkzeugResponse:
497
508
498
509
499
510
@app .get ("/update_scanners" )
511
+ @pretty_exception
500
512
async def update_scanners_get () -> WerkzeugResponse :
501
513
"""Update scanners get handling."""
502
514
APP_STORAGE ["scanners" ] = get_devices ()
0 commit comments