Compare commits

...

2 commits

Author SHA1 Message Date
me
452477fc11 a few more fixes 2024-11-07 18:28:42 +02:00
me
c5465b93f1 format time as rfc 2616 2024-11-07 17:18:01 +02:00
4 changed files with 13 additions and 13 deletions

View file

@ -29,7 +29,7 @@ data DB
, insertNote :: NoteEntry -> IO (DB.Int64, Note)
, insertFollower ::
forall a. Typeable a => FollowerEntry -> (DB.Int64 -> IO a) -> IO a
, deleteFollower :: FollowerEntry -> IO DB.Int64
, deleteFollower :: FollowerEntry -> IO (Maybe DB.Int64)
, getFollowers :: IO [Follower]
}
@ -156,10 +156,10 @@ insertFollowerToDb follower = do
[n] <- map decodeIntRow <$> uncurry DB.runWith (insertFollowerSQL follower)
pure n
deleteFollowerFromDb :: FollowerEntry -> DB.SQLite DB.Int64
deleteFollowerFromDb :: FollowerEntry -> DB.SQLite (Maybe DB.Int64)
deleteFollowerFromDb follower = do
[n] <- map decodeIntRow <$> uncurry DB.runWith (deleteFollowerSQL follower)
pure n
ns <- map decodeIntRow <$> uncurry DB.runWith (deleteFollowerSQL follower)
pure $ listToMaybe ns
getFollowersFromDb :: Url -> DB.SQLite [Follower]
getFollowersFromDb url =
@ -248,7 +248,7 @@ deleteFollowerSQL follower =
( [r|
DELETE FROM follower
WHERE follow_id = ? AND actor = ?
RETURNING follow_id
RETURNING id
|]
,
[ DB.SQLText follower.followId
@ -310,7 +310,7 @@ decodeNoteRow = \case
decodeIntRow :: [DB.SQLData] -> DB.Int64
decodeIntRow = \case
[DB.SQLInteger fid] -> fid
row -> error $ "Couldn't decode row as NoteId: " <> show row
row -> error $ "Couldn't decode row as id: " <> show row
decodeFollowerRow :: [DB.SQLData] -> Follower
decodeFollowerRow = \case

View file

@ -146,7 +146,7 @@ handleInbox db detailsFile activity = do
)
callback =
( \(insertId :: DB.Int64) -> do
(result :: A.Value) <- Fedi.sendPost
result <- Fedi.sendPost
details
(actor.unwrap <> "/inbox")
( Fedi.makeAccept
@ -196,5 +196,5 @@ sendFollowers details db message = do
followers <- db.getFollowers
Fedi.for_ followers \follower -> do
Async.async $ do
result <- Fedi.sendPost @A.Value details (T.unpack follower.actorId <> "/inbox") message
print (follower.actorId, A.encode result)
bs <- Fedi.sendPost details (T.unpack follower.actorId <> "/inbox") message
print (follower.actorId, bs)

View file

@ -13,11 +13,11 @@ import Text.URI qualified as URI
import Data.Text qualified as T
sendPost
:: (A.FromJSON output, A.ToJSON input)
:: A.ToJSON input
=> UserDetails
-> String
-> input
-> IO output
-> IO ByteString
sendPost details url payload = do
uri <- URI.mkURI $ fromString url
let encoded = BSL.toStrict $ A.encode payload
@ -29,7 +29,7 @@ sendPost details url payload = do
Req.POST
url'
(Req.ReqBodyBs encoded)
Req.jsonResponse
Req.bsResponse
( scheme
<> sigHeaders httpSignature
)

View file

@ -20,7 +20,7 @@ signSignature
:: UserDetails -> String -> String -> ByteString -> IO HttpSignature
signSignature details host requestTarget body = do
date <- Time.getCurrentTime
<&> Time.formatTime Time.defaultTimeLocale Time.rfc822DateFormat
<&> Time.formatTime Time.defaultTimeLocale "%a, %d %b %Y %H:%M:%S GMT"
let
digest = "SHA-256=" <> encodeBase64 (makeDigest body)