enforce constraints on the settings, store settings in the image

This commit is contained in:
Gavin McDonald
2025-05-05 17:22:08 -04:00
parent 438fa306ae
commit 1ee183557c
2 changed files with 23 additions and 4 deletions

View File

@@ -6,10 +6,23 @@ defmodule LabelmakerWeb.LabelController do
File.mkdir_p!(@label_dir)
def show(conn, params) do
params =
params
|> Map.take(Constants.permitted_keys())
|> Enum.filter(fn {k, v} ->
case k do
"color" -> v in Constants.colors()
"font" -> v in Constants.fonts()
"label" -> String.length(v) <= Constants.max_label_length()
"size" -> v in Constants.sizes()
_ -> true
end
end)
|> Map.new()
options =
Constants.defaults()
|> Map.merge(params)
|> Map.take(Constants.permitted_keys())
filename =
options
@@ -40,6 +53,9 @@ defmodule LabelmakerWeb.LabelController do
"-font",
options["font"],
"label:#{options["label"]}",
"-set",
"comment",
inspect(options),
filepath
]