mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-03-29 20:59:59 +00:00
* web: parameterize generateSite, remove Embedded from library Move embedFile/embedDir out of the library so it works when simplexmq is consumed as a dependency. generateSite now accepts mediaContent, wellKnown, and linkHtml as parameters. * smp-server, xftp-server: embed static files in executables Add shared apps/common/Embedded.hs with TH splices, update SMPWeb and XFTPWeb to pass embedded content to generateSite, move file-embed dependency from library to executables and test suite. * refactor * add export, move common files to Web subfolder * fix .cabal --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
44 lines
1.8 KiB
Haskell
44 lines
1.8 KiB
Haskell
{-# LANGUAGE NamedFieldPuns #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module SMPWeb
|
|
( smpGenerateSite,
|
|
serverInformation,
|
|
) where
|
|
|
|
import Data.ByteString (ByteString)
|
|
import Data.String (fromString)
|
|
import Web.Embedded (embeddedContent)
|
|
import Simplex.Messaging.Encoding.String (strEncode)
|
|
import Simplex.Messaging.Server.Information
|
|
import Simplex.Messaging.Server.Main (simplexmqSource)
|
|
import qualified Simplex.Messaging.Server.Web as Web
|
|
import Simplex.Messaging.Server.Web (render, serverInfoSubsts, timedTTLText)
|
|
import Simplex.Messaging.Transport.Client (TransportHost (..))
|
|
|
|
smpGenerateSite :: ServerInformation -> Maybe TransportHost -> FilePath -> IO ()
|
|
smpGenerateSite si onionHost path =
|
|
Web.generateSite embeddedContent (serverInformation si onionHost) smpLinkPages path
|
|
|
|
smpLinkPages :: [String]
|
|
smpLinkPages = ["contact", "invitation", "a", "c", "g", "r", "i"]
|
|
|
|
serverInformation :: ServerInformation -> Maybe TransportHost -> ByteString
|
|
serverInformation ServerInformation {config, information} onionHost = render (Web.indexHtml embeddedContent) substs
|
|
where
|
|
substs = [("smpConfig", Just "y"), ("xftpConfig", Nothing)] <> substConfig <> serverInfoSubsts simplexmqSource information <> [("onionHost", strEncode <$> onionHost), ("iniFileName", Just "smp-server.ini")]
|
|
substConfig =
|
|
[ ( "persistence",
|
|
Just $ case persistence config of
|
|
SPMMemoryOnly -> "In-memory only"
|
|
SPMQueues -> "Queues"
|
|
SPMMessages -> "Queues and messages"
|
|
),
|
|
("messageExpiration", Just $ maybe "Never" (fromString . timedTTLText) $ messageExpiration config),
|
|
("statsEnabled", Just . yesNo $ statsEnabled config),
|
|
("newQueuesAllowed", Just . yesNo $ newQueuesAllowed config),
|
|
("basicAuthEnabled", Just . yesNo $ basicAuthEnabled config)
|
|
]
|
|
yesNo True = "Yes"
|
|
yesNo False = "No"
|