summaryrefslogtreecommitdiff
path: root/fig-web/src/Fig/Web/Module
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-11-14 20:56:47 -0500
committerLLLL Colonq <llll@colonq>2025-11-14 20:56:47 -0500
commita69da398584644daf975db58a3ff893d29d155eb (patch)
tree4bd475f3f7b58d284acc41ed99457efeea305afa /fig-web/src/Fig/Web/Module
parent48080c62a05dff885a10ac6b6d548a8ab3582a42 (diff)
Add TCG
Diffstat (limited to 'fig-web/src/Fig/Web/Module')
-rw-r--r--fig-web/src/Fig/Web/Module/TCG.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/fig-web/src/Fig/Web/Module/TCG.hs b/fig-web/src/Fig/Web/Module/TCG.hs
new file mode 100644
index 0000000..0636ad7
--- /dev/null
+++ b/fig-web/src/Fig/Web/Module/TCG.hs
@@ -0,0 +1,36 @@
+module Fig.Web.Module.TCG
+ ( public
+ ) where
+
+import Fig.Prelude
+
+import qualified Data.Text as Text
+
+import Fig.Web.Utils
+import Fig.Web.Types
+import qualified Fig.Web.DB as DB
+
+public :: PublicModule
+public a = do
+ onGet "/api/tcg/card/:uuid.png" do
+ uuidpng <- pathParam "uuid.png"
+ case Text.stripSuffix ".png" uuidpng of
+ Nothing -> do
+ status status400
+ respondText "malformed card path"
+ Just uuid -> DB.hget a.db "tcg:cards" (encodeUtf8 uuid) >>= \case
+ Nothing -> do
+ status status404
+ respondText "card does not exist"
+ Just image -> do
+ addHeader "Content-Type" "image/png"
+ respondBytes image
+ onGet "/api/tcg/binder/:userid" do
+ userid <- pathParam "userid"
+ cards <- DB.lrange a.db ("tcg-inventory:" <> userid) 0 (-1)
+ respondHTML do
+ head_ do
+ title_ "LCOLONQ: The Game"
+ body_ do
+ forM_ cards $ \c -> do
+ img_ [src_ $ mconcat ["/api/tcg/card/", decodeUtf8 c, ".png"]]