Clean up webmentions

This commit is contained in:
2023-07-06 21:08:42 +10:00
parent d0d1b43f6e
commit bee8adc407
6 changed files with 123 additions and 18 deletions

View File

@@ -4,29 +4,24 @@ module Adamantium
module Actions
module Webmentions
class Create < Adamantium::Action
include Deps["repos.webmentions_repo", "repos.post_repo"]
include Deps["repos.webmentions_repo",
"repos.post_repo",
webmention_parser: "param_parser.webmention"
]
def handle(req, res)
if req.params[:"wm-property"] == "in-reply-to"
webmention = webmention_parser.call(params: req.params)
case webmention
in Success[:reply, reply]
slug = req.params[:"in-reply-to"].split("/").last
post = post_repo.fetch!(slug)
attrs = {
type: "reply",
author_name: req.params[:author][:name],
author_photo: req.params[:author][:photo],
author_url: req.params[:author][:url],
published_at: req.params[:published],
content_html: req.params[:content][:html],
content_text: req.params[:content][:text],
source_url: req.params[:url],
target_url: req.params[:"in-reply-to"],
post_id: post.id
}
reply[:post_id] = post.id
webmentions_repo.create(attrs)
webmentions_repo.create(reply)
res.status = 201
in Failure(:invalid_request)
res.status = 429
end
end
end