This commit is contained in:
Dmitry Zuikov 2024-04-17 14:40:24 +03:00
parent 56f0866685
commit ab6b7ac142
11 changed files with 62 additions and 10 deletions

View File

@ -0,0 +1,14 @@
{-# Language TemplateHaskell #-}
module HBS2.Git.Web.Assets where
import Data.FileEmbed
import Data.ByteString
version :: Int
version = 3
assetsDir :: [(FilePath, ByteString)]
assetsDir = $(embedDir "hbs2-git-dashboard-assets/assets")

View File

Before

Width:  |  Height:  |  Size: 468 B

After

Width:  |  Height:  |  Size: 468 B

View File

Before

Width:  |  Height:  |  Size: 384 B

After

Width:  |  Height:  |  Size: 384 B

View File

Before

Width:  |  Height:  |  Size: 564 B

After

Width:  |  Height:  |  Size: 564 B

View File

Before

Width:  |  Height:  |  Size: 600 B

After

Width:  |  Height:  |  Size: 600 B

View File

@ -6,11 +6,13 @@ import HBS2.Prelude.Plated
import HBS2.OrDie import HBS2.OrDie
import HBS2.System.Dir import HBS2.System.Dir
import HBS2.Git.Html.Root import HBS2.Git.Web.Assets
import HBS2.Git.Web.Html.Root
import HBS2.Peer.CLI.Detect import HBS2.Peer.CLI.Detect
import Data.Config.Suckless import Data.Config.Suckless
import Data.Config.Suckless.KeyValue
import Lucid import Lucid
import Options.Applicative as O import Options.Applicative as O
@ -21,6 +23,7 @@ import Control.Applicative
import Data.ByteString.Lazy qualified as LBS import Data.ByteString.Lazy qualified as LBS
import Network.HTTP.Types.Status import Network.HTTP.Types.Status
import Network.Wai.Middleware.Static hiding ((<|>)) import Network.Wai.Middleware.Static hiding ((<|>))
import Network.Wai.Middleware.StaticEmbedded as E
import Network.Wai.Middleware.RequestLogger import Network.Wai.Middleware.RequestLogger
import Text.InterpolatedString.Perl6 (qc) import Text.InterpolatedString.Perl6 (qc)
import Web.Scotty.Trans import Web.Scotty.Trans
@ -33,9 +36,15 @@ import UnliftIO
data HttpPortOpt data HttpPortOpt
data DevelopAssetsOpt
instance HasConf m => HasCfgKey HttpPortOpt a m where instance HasConf m => HasCfgKey HttpPortOpt a m where
key = "port" key = "port"
instance HasConf m => HasCfgKey DevelopAssetsOpt a m where
key = "develop-assets"
data RunDashBoardOpts = RunDashBoardOpts data RunDashBoardOpts = RunDashBoardOpts
{ configPath :: Maybe FilePath } { configPath :: Maybe FilePath }
@ -110,15 +119,26 @@ runDashBoardM cli m = do
withDashBoardEnv env m withDashBoardEnv env m
-- type App =
runDashboardWeb :: ScottyT (DashBoardM IO) () data WebOptions =
runDashboardWeb = do WebOptions
{ _assetsOverride :: Maybe FilePath
}
runDashboardWeb :: WebOptions -> ScottyT (DashBoardM IO) ()
runDashboardWeb wo = do
middleware logStdout middleware logStdout
middleware $ staticPolicy (noDots >-> addBase "hbs2-git/hbs2-git-dashboard/assets/") let assets = _assetsOverride wo
get "/" $ do case assets of
Nothing -> do
middleware (E.static assetsDir)
Just f -> do
middleware $ staticPolicy (noDots >-> addBase f)
get "/" do
html =<< renderTextT (dashboardRootPage mempty) html =<< renderTextT (dashboardRootPage mempty)
main :: IO () main :: IO ()
@ -130,13 +150,15 @@ main = do
-- FIXME: to-config -- FIXME: to-config
pno <- cfgValue @HttpPortOpt @(Maybe Int) <&> fromMaybe 8090 pno <- cfgValue @HttpPortOpt @(Maybe Int) <&> fromMaybe 8090
wo <- cfgValue @DevelopAssetsOpt @(Maybe FilePath) <&> WebOptions
soname <- runMaybeT (getRPC <|> detectRPC) soname <- runMaybeT (getRPC <|> detectRPC)
`orDie` "hbs2-peer RPC not detected" `orDie` "hbs2-peer RPC not detected"
env <- ask env <- ask
conf <- getConf
scottyT pno (withDashBoardEnv env) runDashboardWeb scottyT pno (withDashBoardEnv env) (runDashboardWeb wo)
where where
opts = info (configParser <**> helper) opts = info (configParser <**> helper)

View File

@ -1,4 +1,4 @@
module HBS2.Git.Html.Root where module HBS2.Git.Web.Html.Root where
import HBS2.Prelude import HBS2.Prelude
import HBS2.Base58 import HBS2.Base58

View File

@ -125,23 +125,39 @@ library
hs-source-dirs: hbs2-git-client-lib hs-source-dirs: hbs2-git-client-lib
library hbs2-git-dashboard-assets
import: shared-properties
build-depends:
base, file-embed
exposed-modules:
HBS2.Git.Web.Assets
hs-source-dirs: hbs2-git-dashboard-assets
default-language: GHC2021
executable hbs2-git-dashboard executable hbs2-git-dashboard
import: shared-properties import: shared-properties
main-is: GitDashBoard.hs main-is: GitDashBoard.hs
other-modules: other-modules:
HBS2.Git.Html.Root HBS2.Git.Web.Html.Root
-- other-extensions: -- other-extensions:
build-depends: build-depends:
base, hbs2-peer, hbs2-git, suckless-conf base, hbs2-git-dashboard-assets, hbs2-peer, hbs2-git, suckless-conf
, binary , binary
, vector , vector
, optparse-applicative , optparse-applicative
, http-types , http-types
, file-embed
, wai , wai
, wai-extra , wai-extra
, wai-middleware-static , wai-middleware-static
, wai-middleware-static-embedded
, lucid , lucid
, lucid-htmx , lucid-htmx
, scotty >= 0.22 , scotty >= 0.22