about summary refs log tree commit diff stats
path: root/app/controllers/blogs_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/blogs_controller.rb')
-rw-r--r--app/controllers/blogs_controller.rb34
1 files changed, 0 insertions, 34 deletions
diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 4bbbc28..033d6bb 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb
@@ -1,9 +1,6 @@
1require 'microformats'
2require 'redcarpet/render_strip' 1require 'redcarpet/render_strip'
3require 'webmention'
4 2
5class BlogsController < ApplicationController 3class BlogsController < ApplicationController
6 skip_before_action :verify_authenticity_token, only: [:webmention]
7 4
8 def summary 5 def summary
9 @blogs = Blog.where(published: true).order(published_at: :desc).paginate(page: params[:page], per_page: 10) 6 @blogs = Blog.where(published: true).order(published_at: :desc).paginate(page: params[:page], per_page: 10)
@@ -92,35 +89,4 @@ class BlogsController < ApplicationController
92 end 89 end
93 end 90 end
94 91
95 def webmention
96 @blog = Blog.find_by_slug(params[:slug])
97
98 raise ActiveRecord::RecordNotFound unless @blog
99 raise ActiveRecord::RecordNotFound unless @blog.published
100
101 permalink = url_for(@blog)
102
103 target = params[:target]
104 unless target == permalink
105 render json: { error: "Incorrect target for webmention endpoint (#{target} != #{permalink})." }
106 return
107 end
108
109 source = params[:source]
110 verification = Webmention.verify_webmention(source, target)
111 unless verification.verified?
112 render json: { error: "Webmention could not be verified." }
113 return
114 end
115
116 response = Webmention::Request.get(source)
117 parsed = Microformats.parse(response.body.to_s)
118
119 if parsed.entry.properties.to_hash.include?("like-of") and parsed.entry.like_of(:all).map(&:to_s).include? permalink
120 @blog.like!(parsed.entry.author.url, parsed.entry.author.name)
121 end
122
123 head :ok
124 end
125
126end 92end