about summary refs log tree commit diff stats
path: root/app/controllers/webmentions_controller.rb
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-12-07 18:58:50 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2024-12-07 18:58:50 -0500
commit9d8deddb0a9df7d4d7d4b649ddf01b15570719e0 (patch)
tree3e98477e2bf2e38a6c0bd372a417ac507950d194 /app/controllers/webmentions_controller.rb
parenta30b6daedb8b71606abe0e83f82e1f7c356cab6b (diff)
downloadthoughts-9d8deddb0a9df7d4d7d4b649ddf01b15570719e0.tar.gz
thoughts-9d8deddb0a9df7d4d7d4b649ddf01b15570719e0.tar.bz2
thoughts-9d8deddb0a9df7d4d7d4b649ddf01b15570719e0.zip
Moved webmentions to a single endpoint
Diffstat (limited to 'app/controllers/webmentions_controller.rb')
-rw-r--r--app/controllers/webmentions_controller.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/app/controllers/webmentions_controller.rb b/app/controllers/webmentions_controller.rb new file mode 100644 index 0000000..d8aefc7 --- /dev/null +++ b/app/controllers/webmentions_controller.rb
@@ -0,0 +1,36 @@
1require 'microformats'
2require 'webmention'
3
4class WebmentionsController < ApplicationController
5 skip_before_action :verify_authenticity_token
6
7 def create
8 source = params[:source]
9 target = params[:target]
10
11 verification = Webmention.verify_webmention(source, target)
12 unless verification.verified?
13 render json: { error: "Webmention could not be verified." }
14 return
15 end
16
17 target_parts = URI.parse(target).path.split("/").drop(1)
18
19 if target_parts[0] == "blog"
20 blog = Blog.find_by_slug(target_parts[1])
21
22 raise ActiveRecord::RecordNotFound unless blog
23 raise ActiveRecord::RecordNotFound unless blog.published
24
25 response = Webmention::Request.get(source)
26 parsed = Microformats.parse(response.body.to_s)
27
28 if parsed.entry.properties.to_hash.include?("like-of") and parsed.entry.like_of(:all).map(&:to_s).include? target
29 blog.like!(parsed.entry.author.url, parsed.entry.author.name)
30 end
31 end
32
33 head :ok
34 end
35
36end