summaryrefslogtreecommitdiff
path: root/fig-web/src/Fig/Web/Module
diff options
context:
space:
mode:
Diffstat (limited to 'fig-web/src/Fig/Web/Module')
-rw-r--r--fig-web/src/Fig/Web/Module/User.hs33
1 files changed, 33 insertions, 0 deletions
diff --git a/fig-web/src/Fig/Web/Module/User.hs b/fig-web/src/Fig/Web/Module/User.hs
index 7f9ac40..90daa6f 100644
--- a/fig-web/src/Fig/Web/Module/User.hs
+++ b/fig-web/src/Fig/Web/Module/User.hs
@@ -8,6 +8,7 @@ import Data.Maybe (mapMaybe)
import qualified Data.Text as Text
import qualified Data.ByteString.Char8 as BS.C8
import qualified Data.Map.Strict as Map
+import qualified Data.Aeson as Aeson
import Fig.Web.Utils
import Fig.Web.Types
@@ -40,6 +41,22 @@ getIntegerValuedMap db key = do
(iv, _) <- BS.C8.readInteger v
Just (tk, iv)
+data UserInfo = UserInfo
+ { stats :: Map.Map Text Integer
+ , talents :: Map.Map Text Integer
+ , properties :: Map.Map Text Text
+ , badges :: [Text]
+ } deriving Generic
+instance Aeson.ToJSON UserInfo
+
+getUserInfo :: MonadIO m => DB -> ByteString -> m UserInfo
+getUserInfo db uid = do
+ stats <- getIntegerValuedMap db $ "user:stats:" <> uid
+ talents <- getIntegerValuedMap db $ "user:talents:" <> uid
+ properties <- getTextValuedMap db $ "user:properties:" <> uid
+ badges <- getTextList db $ "user:badges:" <> uid
+ pure UserInfo{..}
+
public :: PublicModule
public a = do
-- users
@@ -50,6 +67,9 @@ public a = do
status status404
respondText "user not found"
Just val -> respondText $ decodeUtf8 val
+ onGet "/api/user/info/:uid" do -- get everything bundled together
+ uid <- pathParam "uid"
+ respondJSON =<< getUserInfo a.db uid
onGet "/api/user/stats/:uid" do
uid <- pathParam "uid"
respondJSON =<< getIntegerValuedMap a.db ("user:stats:" <> uid)
@@ -62,6 +82,19 @@ public a = do
onGet "/api/user/badges/:uid" do
uid <- pathParam "uid"
respondJSON =<< getTextList a.db ("user:badges:" <> uid)
+ onGet "/api/user/avatar/:uid.png" do
+ uuidpng <- pathParam "uid.png"
+ case Text.stripSuffix ".png" uuidpng of
+ Nothing -> do
+ status status400
+ respondText "malformed user avatar path"
+ Just uid -> DB.get a.db ("user:avatar:" <> encodeUtf8 uid) >>= \case
+ Nothing -> do
+ addHeader "Content-Type" "image/png"
+ respondBytes "\137PNG\r\n\SUB\n\NUL\NUL\NUL\rIHDR\NUL\NUL\NUL\STX\NUL\NUL\NUL\STX\b\ACK\NUL\NUL\NULr\182\r$\NUL\NUL\NUL\SOHsRGB\NUL\174\206\FS\233\NUL\NUL\NUL\SUBIDAT\b\153cd``\248\207T)\206\192\192T)\254\159\129\129\225?\NUL\RS\188\EOT#\137b%\ACK\NUL\NUL\NUL\NULIEND\174B`\130"
+ Just img -> do
+ addHeader "Content-Type" "image/png"
+ respondBytes img
-- badges
onGet "/api/badge/:uuid" do
uuid <- pathParam "uuid"