diff options
| author | Fuwn <[email protected]> | 2024-07-01 11:42:58 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-07-01 11:42:58 +0000 |
| commit | 4c3f0bc80e65d64e631ee8257b24b34db3d954d3 (patch) | |
| tree | 5761460f39645d5d4916f0d6cdc103daa6d8603b /src/request.gleam | |
| parent | feat(svg): pad to 5 by default (diff) | |
| download | mayu-0.1.12.tar.xz mayu-0.1.12.zip | |
feat(request): padding query parameterv0.1.12
Diffstat (limited to 'src/request.gleam')
| -rw-r--r-- | src/request.gleam | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/request.gleam b/src/request.gleam index 6e23caf..62abf1f 100644 --- a/src/request.gleam +++ b/src/request.gleam @@ -1,6 +1,8 @@ import database import envoy +import gleam/int import gleam/json +import gleam/list import gleam/string import gleam/string_builder import simplifile @@ -44,13 +46,23 @@ pub fn handle(request, connection) { Ok(counter) -> { wisp.ok() |> wisp.set_header("Content-Type", "image/svg+xml") - |> wisp.string_body(svg.xml( - case wisp.get_query(request) { - [#("theme", theme)] -> theme - _ -> "asoul" - }, - counter.num, - )) + |> wisp.string_body( + svg.xml( + case list.key_find(wisp.get_query(request), "theme") { + Ok(theme) -> theme + _ -> "asoul" + }, + counter.num, + case list.key_find(wisp.get_query(request), "padding") { + Ok(padding) -> + case int.parse(padding) { + Ok(n) -> n + Error(_) -> 6 + } + _ -> 6 + }, + ), + ) } Error(_) -> wisp.unprocessable_entity() } |