summaryrefslogtreecommitdiff
path: root/fig-web/src/Fig/Web/Module
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-12-17 05:01:05 -0500
committerLLLL Colonq <llll@colonq>2025-12-17 05:01:05 -0500
commitefdc8dc21571c3737662a9f49761961fe1068ead (patch)
tree8427505d85eeae4dd0e5090ad1c1705c40e79a7e /fig-web/src/Fig/Web/Module
parentfe4d5cfedaaa0aebde3d3ab3f1fbfff7e40d66de (diff)
Delete cards from Redis
Diffstat (limited to 'fig-web/src/Fig/Web/Module')
-rw-r--r--fig-web/src/Fig/Web/Module/TCG.hs29
1 files changed, 22 insertions, 7 deletions
diff --git a/fig-web/src/Fig/Web/Module/TCG.hs b/fig-web/src/Fig/Web/Module/TCG.hs
index d1bc4fb..c322df5 100644
--- a/fig-web/src/Fig/Web/Module/TCG.hs
+++ b/fig-web/src/Fig/Web/Module/TCG.hs
@@ -6,6 +6,9 @@ import Fig.Prelude
import qualified Data.Text as Text
+import qualified System.Directory as Dir
+import qualified Data.ByteString as BS
+
import Fig.Web.Utils
import Fig.Web.Types
import qualified Fig.Web.DB as DB
@@ -18,13 +21,25 @@ public a = do
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
+ Just uuid -> do
+ let cardDir = a.cfg.dataPath <> "/cards"
+ -- liftIO $ Dir.createDirectoryIfMissing True cardDir
+ let cardPath = cardDir <> unpack uuid <> ".png"
+ liftIO (Dir.doesFileExist cardPath) >>= \case
+ False -> DB.hget a.db "tcg:cards" (encodeUtf8 uuid) >>= \case
+ Nothing -> do
+ status status404
+ respondText "card does not exist"
+ Just image -> do
+ log $ "Deleting card from Redis: " <> uuid
+ liftIO $ BS.writeFile cardPath image
+ DB.hdel a.db "tcg:cards" $ encodeUtf8 uuid
+ addHeader "Content-Type" "image/png"
+ respondBytes image
+ True -> do
+ image <- liftIO $ BS.readFile cardPath
+ addHeader "Content-Type" "image/png"
+ respondBytes image
onGet "/api/tcg/binder/:userid" do
userid <- pathParam "userid"
cards <- take 20 <$> DB.lrange a.db ("tcg-inventory:" <> userid) 0 (-1)