Skip to content

Commit

Permalink
delete webmentions when a 410 is received
Browse files Browse the repository at this point in the history
closes #127
  • Loading branch information
aaronpk committed Jun 15, 2019
1 parent 26a6001 commit eaa3990
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions helpers/webmention_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ def process_mention(username, source, target, protocol, token, code=nil)
source_data = XRay.parse source, target
end


if source_data.nil?
error = 'invalid_source'
error_status token, source, target, protocol, error, 'Error retrieving source. No result returned from XRay.'
return nil, error
end



debug = Debug.all(:page_url => target, :enabled => true) | Debug.all(:domain => target_domain, :enabled => true)
if debug.count > 0
puts "Debug enabled for #{target}"
Expand All @@ -143,21 +143,42 @@ def process_mention(username, source, target, protocol, token, code=nil)
end



if source_data.class == XRayError
if source_data.error != "no_link_found"
# Don't log these errors
puts "\tError retrieving source: #{source_data.error} : #{source_data.error_description}"
end

# Check for an existing post that has been deleted
site = Site.first :account => target_account, :domain => target_domain
if site
page = Page.first :site => site, :href => target
if page
link = Link.first_or_create({:page => page, :href => source}, {:site => site, :account => site.account, :domain => source_uri.host})
if link
# This webmention was previously received, but now was deleted, so delete from the DB
link.destroy

# And respond with a success
WebmentionProcessor.update_status @redis, token, {
:status => 'deleted',
:source => source,
:target => target,
:private => link.is_private,
}

return nil, 'deleted'
end
end
end

error_status token, source, target, protocol, source_data.error, source_data.error_description
return nil, source_data.error
end






site = Site.first_or_create :account => target_account, :domain => target_domain

puts "Processing... s=#{source} t=#{target}"
Expand Down

0 comments on commit eaa3990

Please sign in to comment.