mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-03-30 20:45:52 +00:00
* web: extract shared web module from smp-server
Move web serving infrastructure (warp, static files, HTML templating)
from apps/smp-server/web/Static.hs into library modules:
- Simplex.Messaging.Server.Web (generic web infra + templating)
- Simplex.Messaging.Server.Web.Embedded (TH-embedded assets)
Move static assets from apps/smp-server/static/ to
src/Simplex/Messaging/Server/Web/.
Move EmbeddedWebParams/WebHttpsParams from Server.Main to Server.Web.
Keep SMP-specific rendering (serverInformation) in apps/smp-server/SMP/Web.hs.
generateSite is now generic: takes pre-rendered HTML + link page paths,
enabling reuse by XFTP and NTF servers.
* web: add tests for templating engine
Tests for render, section_, item_, and timedTTLText functions
in Simplex.Messaging.Server.Web module.
* web: add serverInfoSubsts, serveStaticPageH2, safe port parsing
* web: rename SMP.Web to SMPWeb, remove SMP subdirectory
* fix(web): section_ collapsing sections with Just "" content
Commit e48bedea ("servers: fix server pages when source code is not
specified") changed section_ to treat Just "" the same as Nothing -
collapsing the section. The intent was to handle the sourceCode case
(empty string when not specified), but the guard
`not (B.null content)` also broke operator, admin, complaints, and
hosting - all of which legitimately use Just "" as a
section-present marker.
Before (correct):
Nothing -> before <> next
Just content -> before <> item_ label content inside <> ...
After (broken):
Just content | not (B.null content) -> ...
_ -> before <> next
Restore the original behavior: only Nothing collapses a section.
* refactor
---------
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 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.Server.Web.Embedded as E
|
|
import Simplex.Messaging.Transport.Client (TransportHost (..))
|
|
|
|
smpGenerateSite :: ServerInformation -> Maybe TransportHost -> FilePath -> IO ()
|
|
smpGenerateSite si onionHost path =
|
|
Web.generateSite (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 E.indexHtml 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"
|