New module Yesod.FedURI: Render routes into FedURI and LocalURI

This commit is contained in:
fr33domlover 2019-03-20 10:08:36 +00:00
parent 6f3df6d569
commit 3f2a178830
3 changed files with 43 additions and 7 deletions

View file

@ -39,6 +39,7 @@ import Text.Email.Local
import Network.FedURI import Network.FedURI
import Web.ActivityPub import Web.ActivityPub
import Yesod.FedURI
--import Vervis.ActivityStreams --import Vervis.ActivityStreams
import Vervis.ActorKey import Vervis.ActorKey
@ -128,13 +129,9 @@ getPersonNewR = redirect $ AuthR newAccountR
getPerson :: ShrIdent -> Person -> Handler TypedContent getPerson :: ShrIdent -> Person -> Handler TypedContent
getPerson shr person = do getPerson shr person = do
renderUrl <- getUrlRender route2fed <- getEncodeRouteFed
let route2uri route = route2local <- getEncodeRouteLocal
case parseFedURI $ renderUrl route of let (host, me) = f2l $ route2fed $ SharerR shr
Left e -> error $ "getRenderUrl produced invalid FedURI!!! " ++ e
Right u -> u
route2local = snd . f2l . route2uri
(host, me) = f2l $ route2uri $ SharerR shr
selectRep $ do selectRep $ do
provideRep $ do provideRep $ do
secure <- getSecure secure <- getSecure

38
src/Yesod/FedURI.hs Normal file
View file

@ -0,0 +1,38 @@
{- This file is part of Vervis.
-
- Written 2019 by fr33domlover <fr33domlover@riseup.net>.
-
- Copying is an act of love. Please copy, reuse and share.
-
- The author(s) have dedicated all copyright and related and neighboring
- rights to this software to the public domain worldwide. This software is
- distributed without any warranty.
-
- You should have received a copy of the CC0 Public Domain Dedication along
- with this software. If not, see
- <http://creativecommons.org/publicdomain/zero/1.0/>.
-}
module Yesod.FedURI
( getEncodeRouteFed
, getEncodeRouteLocal
)
where
import Prelude
import Yesod.Core
import Yesod.Core.Handler
import Network.FedURI
getEncodeRouteFed :: MonadHandler m => m (Route (HandlerSite m) -> FedURI)
getEncodeRouteFed = toFed <$> getUrlRender
where
toFed renderUrl route =
case parseFedURI $ renderUrl route of
Left e -> error $ "getUrlRender produced invalid FedURI: " ++ e
Right u -> u
getEncodeRouteLocal :: MonadHandler m => m (Route (HandlerSite m) -> LocalURI)
getEncodeRouteLocal = (\ f -> snd . f2l . f) <$> getEncodeRouteFed

View file

@ -95,6 +95,7 @@ library
Yesod.Auth.Unverified Yesod.Auth.Unverified
Yesod.Auth.Unverified.Creds Yesod.Auth.Unverified.Creds
Yesod.Auth.Unverified.Internal Yesod.Auth.Unverified.Internal
Yesod.FedURI
Yesod.Paginate.Local Yesod.Paginate.Local
Yesod.SessionEntity Yesod.SessionEntity