-- | CDN url stuff
module Calamity.Utils.CDNUrl (
  cdnURL,
  assetHashFile,
  isGIFAsset,
) where

import Data.Text qualified as T
import Network.HTTP.Req qualified as Req

-- | The CDN URL
cdnURL :: Req.Url 'Req.Https
cdnURL :: Url 'Https
cdnURL = Text -> Url 'Https
Req.https Text
"cdn.discordapp.com"

-- | Test if an asset hash is animated
isGIFAsset :: T.Text -> Bool
isGIFAsset :: Text -> Bool
isGIFAsset = Text -> Text -> Bool
T.isPrefixOf Text
"a_"

{- | Generate \'hash.ext\' for an asset hash. @ext@ will be \'gif\' for animated
 assets, \'png\' otherwise.
-}
assetHashFile :: T.Text -> T.Text
assetHashFile :: Text -> Text
assetHashFile Text
h = if Text -> Bool
isGIFAsset Text
h then Text
h Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
".gif" else Text
h Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
".png"