This commit is contained in:
Dmitry Zuikov 2024-03-29 10:57:57 +03:00
parent d0de8b9bd2
commit e05f7a7d5f
3 changed files with 28 additions and 9 deletions

View File

@ -8,16 +8,21 @@ import HBS2.Prelude.Plated
import HBS2.Base58
import HBS2.Net.Proto.Types
import HBS2.Peer.Proto.RefChan
import HBS2.Peer.Proto.BrowserPlugin
import HBS2.Net.Messaging.Pipe
import Data.Config.Suckless.Syntax
import Data.HashMap.Strict qualified as HM
import Data.Maybe
import Lucid (Html,HtmlT,toHtml)
import Lucid (Html,HtmlT,toHtml,toHtmlRaw)
import Lucid.Html5 hiding (for_)
import Data.Text qualified as Text
import Text.InterpolatedString.Perl6 (q)
import System.FilePath
import Control.Monad
import UnliftIO
rootPath :: [String] -> [String]
rootPath = ("/browser":)
@ -117,8 +122,17 @@ browserRootPage syn = rootPage do
p_ (toHtml s)
channelPage :: Monad m => RefChanId L4Proto -> HtmlT m ()
channelPage chan = rootPage $ pure ()
channelPage :: MonadIO m
=> ServiceCaller BrowserPluginAPI PIPE
-> [(Text,Text)]
-> HtmlT m ()
channelPage api env' = do
let env = HM.toList $ HM.fromList env' <> HM.fromList [("METHOD","list-entries"),("OUTPUT","html")]
r <- liftIO (callRpcWaitMay @RpcChannelQuery (TimeoutSec 1) api env)
<&> join
<&> fromMaybe mempty
rootPage $ toHtmlRaw r

View File

@ -314,13 +314,17 @@ httpWorker (PeerConfig syn) pmeta e = do
get "/browser" do
renderTextT (browserRootPage syn) >>= html
get "/browser/channel/:refchan" $ void $ flip runContT pure do
-- get "/browser/channel/:refchan" $ void $ flip runContT pure do
chan <- lift (param @String "refchan")
<&> fromStringMay
>>= orElse (status status404)
-- chan <- lift (param @String "refchan")
-- <&> fromStringMay
-- >>= orElse (status status404)
lift $ renderTextT (channelPage chan) >>= html
-- plugin <- readTVarIO handles <&> HM.lookup chan
-- >>= orElse (status status404)
-- let env = mempty
-- lift $ renderTextT (channelPage plugin env) >>= html
put "/" do

View File

@ -1,5 +1,6 @@
module HBS2.Peer.Proto.BrowserPlugin
( module HBS2.Peer.Proto.BrowserPlugin
, module HBS2.Net.Proto.Service
, PIPE
) where