Clean up webmentions
This commit is contained in:
@@ -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
|
||||
|
@@ -4,4 +4,4 @@ module Adamantium
|
||||
commands :create
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user