<commit_before>module Avatar where

import qualified Data.Text as T
import Network.Libravatar

import Import.NoFoundation

getUserAvatar :: MonadHandler m => Route (HandlerSite m) -> Maybe User -> m Text
getUserAvatar defaultRoute muser = do
    defaultUrl <- getUrlRender <*> pure defaultRoute

    maybe (return defaultUrl)
          (\user -> do
              let email = fromMaybe T.empty (userEmail user)
              if userEmail_verified user
                  then liftIO (libravatar email defaultUrl)
                  else return defaultUrl)
          muser

  where
    libravatar :: Text -> Text -> IO Text
    libravatar e defUrl = do
        mavatar <-
            avatarUrl (Email $ T.unpack e)
                      defOpts
                          { optSecure = False
                          , optDefault = ImgCustom (T.unpack defUrl)
                          , optSize = DefaultSize
                          , optTryGravatar = False
                          }
        return $ maybe defUrl T.pack mavatar<commit_msg>Keep secure libravatar uri<commit_after>module Avatar where

import qualified Data.Text as T
import Network.Libravatar

import Import.NoFoundation

getUserAvatar :: MonadHandler m => Route (HandlerSite m) -> Maybe User -> m Text
getUserAvatar defaultRoute muser = do
    defaultUrl <- getUrlRender <*> pure defaultRoute

    maybe (return defaultUrl)
          (\user -> do
              let email = fromMaybe T.empty (userEmail user)
              if userEmail_verified user
                  then liftIO (libravatar email defaultUrl)
                  else return defaultUrl)
          muser

  where
    libravatar :: Text -> Text -> IO Text
    libravatar e defUrl = do
        mavatar <-
            avatarUrl (Email $ T.unpack e)
                      defOpts
                          { optSecure = True
                          , optDefault = ImgCustom (T.unpack defUrl)
                          , optSize = DefaultSize
                          , optTryGravatar = False
                          }
        return $ maybe defUrl T.pack mavatar
{'fraction_non_alphanumeric': 0.05921680993314231, 'fraction_numerical': 0.0, 'mean_word_length': 1.5424757281553398, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2522238', 'n_tokens_mistral': 545, 'n_tokens_neox': 521, 'n_words': 170}