From b2d03b59c7ec702070f21ccbf4a6ca1b4c2c2320 Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Wed, 17 Jan 2024 16:53:55 -0500 Subject: [PATCH] WIP: saving attachments - parse api into list of Attachments --- src/Backfill.hs | 20 +++++++++++--------- src/Common | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Backfill.hs b/src/Backfill.hs index f166bf6..a7697c2 100644 --- a/src/Backfill.hs +++ b/src/Backfill.hs @@ -228,18 +228,14 @@ setPostIdInPosts post_pairs ids = map f ids (\(i, j) -> (i, j { Posts.post_id = Just asdf1 })) (post_map Map.! (asdf2, asdf3)) -fileToAttachment :: Posts.Post -> JS.File -> IO Attachments.Attachment -fileToAttachment post file = do - -- sha :: Text <- undefined - - return Attachments.Attachment +fileToAttachment :: Posts.Post -> JS.File -> Attachments.Attachment +fileToAttachment post file = + Attachments.Attachment { Attachments.attachment_id = Nothing - , Attachments.mimetype = "undefined/undefined" + , Attachments.mimetype = maybe "undefined/undefined" id (JS.mime file) , Attachments.creation_time = Posts.creation_time post , Attachments.sha256_hash = undefined - , Attachments.phash = undefined -- oh shit? we need a network request for this - -- but here we don't want to make a network request for every file we get for every post. - -- - probably most of them will already be in the database! + , Attachments.phash = undefined , Attachments.illegal = False , Attachments.post_id = fromJust $ Posts.post_id post } @@ -273,6 +269,12 @@ processBoard settings board = do Right (new_ids :: [ Client.PostId ]) -> do let perfectPostPairs = setPostIdInPosts postPairs new_ids + existingAttachments <- Client.getAttachments settings (map (fromJust . Posts.post_id . snd) perfectPostPairs) + + let attachments_on_board = concatMap + (\(p, q) -> map (fileToAttachment q) (maybe [] id $ JSONPosts.files p)) + perfectPostPairs + -- must call -- Client.postAttachments settings (all_attachments_on_board :: [ Attachments.Attachment ]) -- so we need [ Attachments.Attachment ] diff --git a/src/Common b/src/Common index 0026e48..7a1ee28 160000 --- a/src/Common +++ b/src/Common @@ -1 +1 @@ -Subproject commit 0026e48cea06e2768f7a22f4a25bf115debcea35 +Subproject commit 7a1ee2819b34a10566d96faee2e33f8161546399