mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-04-27 02:05:14 +00:00
782cacfb3c
* 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>
38 lines
1.8 KiB
Haskell
38 lines
1.8 KiB
Haskell
{-# LANGUAGE NamedFieldPuns #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module XFTPWeb
|
|
( xftpGenerateSite,
|
|
xftpServerInformation,
|
|
) where
|
|
|
|
import Data.ByteString (ByteString)
|
|
import Data.Maybe (isJust)
|
|
import Data.String (fromString)
|
|
import Web.Embedded (embeddedContent)
|
|
import Simplex.FileTransfer.Server.Env (XFTPServerConfig (..))
|
|
import Simplex.Messaging.Encoding.String (strEncode)
|
|
import Simplex.Messaging.Server.Expiration (ExpirationConfig (..))
|
|
import Simplex.Messaging.Server.Information (ServerPublicInfo)
|
|
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 (..))
|
|
|
|
xftpGenerateSite :: XFTPServerConfig -> Maybe ServerPublicInfo -> Maybe TransportHost -> FilePath -> IO ()
|
|
xftpGenerateSite cfg info onionHost path =
|
|
Web.generateSite embeddedContent (xftpServerInformation cfg info onionHost) [] path
|
|
|
|
xftpServerInformation :: XFTPServerConfig -> Maybe ServerPublicInfo -> Maybe TransportHost -> ByteString
|
|
xftpServerInformation XFTPServerConfig {fileExpiration, logStatsInterval, allowNewFiles, newFileBasicAuth} information onionHost = render (Web.indexHtml embeddedContent) substs
|
|
where
|
|
substs = [("smpConfig", Nothing), ("xftpConfig", Just "y")] <> substConfig <> serverInfoSubsts simplexmqSource information <> [("onionHost", strEncode <$> onionHost), ("iniFileName", Just "file-server.ini")]
|
|
substConfig =
|
|
[ ("fileExpiration", Just $ maybe "Never" (fromString . timedTTLText . ttl) fileExpiration),
|
|
("statsEnabled", Just . yesNo $ isJust logStatsInterval),
|
|
("newUploadsAllowed", Just . yesNo $ allowNewFiles),
|
|
("basicAuthEnabled", Just . yesNo $ isJust newFileBasicAuth)
|
|
]
|
|
yesNo True = "Yes"
|
|
yesNo False = "No"
|