From b1e189eed23e85c089de0e8507fc3ea81cc79324 Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 5 May 2023 23:10:57 +0200 Subject: protoserve: Add some input validation --- gerbonara/cad/protoserve.py | 7 +- gerbonara/cad/protoserve_data/protoserve.html | 259 +++++++++++++++----------- 2 files changed, 157 insertions(+), 109 deletions(-) diff --git a/gerbonara/cad/protoserve.py b/gerbonara/cad/protoserve.py index bcd48ce..25ef8c6 100644 --- a/gerbonara/cad/protoserve.py +++ b/gerbonara/cad/protoserve.py @@ -4,7 +4,7 @@ import importlib.resources from tempfile import NamedTemporaryFile, TemporaryDirectory from pathlib import Path -from quart import Quart, request, Response, send_file +from quart import Quart, request, Response, send_file, abort from . import protoboard as pb from . import protoserve_data @@ -144,7 +144,10 @@ def to_board(obj): mounting_hole_offset = float(holes.get('offset', unit(5, MM))) if obj.get('children'): - content = deserialize(obj['children'][0], unit) + try: + content = deserialize(obj['children'][0], unit) + except ValueError: + return abort(400) else: content = [pb.EmptyProtoArea()] diff --git a/gerbonara/cad/protoserve_data/protoserve.html b/gerbonara/cad/protoserve_data/protoserve.html index 00b038e..c42ce6c 100644 --- a/gerbonara/cad/protoserve_data/protoserve.html +++ b/gerbonara/cad/protoserve_data/protoserve.html @@ -97,6 +97,11 @@ input { text-align: center; } +.group > .attribution, .group > .usage { + grid-column-start: 1; + grid-column-end: span 3; +} + .group > div > .proportion { display: none; } @@ -140,6 +145,14 @@ input { margin: 0 5px 0 5px; } +input[type="text"]:invalid { + background: rgba(255 0 0 / 30%); +} + +input[type="text"]:focus:valid { + background: rgba(0 192 64 / 30%); +} + .group.expand { border-radius: 0; } @@ -161,6 +174,7 @@ input { } #preview { + position: relative; grid-area: main; padding: 20px; } @@ -171,6 +185,25 @@ input { object-fit: contain; } +#preview-message { + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: hsla(0 0% 50% / 30%); + display: none; + justify-content: center; + align-items: center; + font-size: 18pt; + font-weight: bold; + color: white; +} + +#preview-message.loading { + display: flex; +} + #links { grid-area: links; display: flex; @@ -225,63 +258,66 @@ input {
-
-

Board settings

- - - - - - -
-
+
Automatically generated preview image +