WIP: saving attachments - parse api into list of Attachments

This commit is contained in:
towards-a-new-leftypol 2024-01-17 16:53:55 -05:00
parent f07907df1b
commit b2d03b59c7
2 changed files with 12 additions and 10 deletions

View File

@ -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 ]

@ -1 +1 @@
Subproject commit 0026e48cea06e2768f7a22f4a25bf115debcea35
Subproject commit 7a1ee2819b34a10566d96faee2e33f8161546399