aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-04-18 01:01:41 +0000
committerFuwn <[email protected]>2026-04-18 01:05:13 +0000
commit53fac17bbcaa2957235b54b6e24e835cabca2033 (patch)
treec15f761fb4faeb9cfad7716ec76eea6f7059f7ec
parentrefactor: Tighten dead branches and fail fast on missing index.html (diff)
downloadmayu-53fac17bbcaa2957235b54b6e24e835cabca2033.tar.xz
mayu-53fac17bbcaa2957235b54b6e24e835cabca2033.zip
fix: Harden startup + SVG input handling
-rw-r--r--src/database.gleam6
-rw-r--r--src/request.gleam2
-rw-r--r--src/svg.gleam2
3 files changed, 4 insertions, 6 deletions
diff --git a/src/database.gleam b/src/database.gleam
index 5c3d9b2..053bc28 100644
--- a/src/database.gleam
+++ b/src/database.gleam
@@ -8,11 +8,9 @@ pub type Counter {
}
pub fn setup(connection) {
- let _ =
+ let assert Ok(_) =
sqlight.exec(
- "pragma foreign_keys = off;
-
- create table if not exists tb_count (
+ "create table if not exists tb_count (
id integer primary key autoincrement not null unique,
name text not null unique,
num int not null default (0)
diff --git a/src/request.gleam b/src/request.gleam
index 82048af..a56780b 100644
--- a/src/request.gleam
+++ b/src/request.gleam
@@ -45,7 +45,7 @@ pub fn handle(request, connection, image_cache, index_html) {
case list.key_find(query, "padding") {
Ok(padding) ->
case int.parse(padding) {
- Ok(n) -> n
+ Ok(n) -> int.clamp(n, min: 0, max: 32)
Error(_) -> 6
}
_ -> 6
diff --git a/src/svg.gleam b/src/svg.gleam
index f6ab4a4..4014910 100644
--- a/src/svg.gleam
+++ b/src/svg.gleam
@@ -49,7 +49,7 @@ pub fn xml(image_cache, theme, number, padding) {
image_cache,
theme,
{
- let assert Ok(digits) = int.digits(number, 10)
+ let assert Ok(digits) = int.digits(int.absolute_value(number), 10)
let digits_padding = padding - list.length(digits)
case digits_padding {