diff options
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/fan_out_on_write_service.rb | 2 | ||||
-rw-r--r-- | app/services/fetch_atom_service.rb | 4 | ||||
-rw-r--r-- | app/services/fetch_link_card_service.rb | 10 | ||||
-rw-r--r-- | app/services/fetch_remote_account_service.rb | 3 | ||||
-rw-r--r-- | app/services/fetch_remote_resource_service.rb | 28 | ||||
-rw-r--r-- | app/services/fetch_remote_status_service.rb | 3 | ||||
-rw-r--r-- | app/services/notify_service.rb | 2 | ||||
-rw-r--r-- | app/services/precompute_feed_service.rb | 13 | ||||
-rw-r--r-- | app/services/process_feed_service.rb | 23 |
9 files changed, 57 insertions, 31 deletions
diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index 3b74696d5..47a47a735 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -54,7 +54,7 @@ class FanOutOnWriteService < BaseService end def render_anonymous_payload(status) - @payload = InlineRenderer.render(status, nil, 'api/v1/statuses/show') + @payload = InlineRenderer.render(status, nil, :status) @payload = Oj.dump(event: :update, payload: @payload) end diff --git a/app/services/fetch_atom_service.rb b/app/services/fetch_atom_service.rb index 8f42db0aa..d430b22e9 100644 --- a/app/services/fetch_atom_service.rb +++ b/app/services/fetch_atom_service.rb @@ -20,6 +20,10 @@ class FetchAtomService < BaseService process_html(fetch(url)) rescue OpenSSL::SSL::SSLError => e Rails.logger.debug "SSL error: #{e}" + nil + rescue HTTP::ConnectionError => e + Rails.logger.debug "HTTP ConnectionError: #{e}" + nil end private diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb index c2df7b2f0..6ef3abb66 100644 --- a/app/services/fetch_link_card_service.rb +++ b/app/services/fetch_link_card_service.rb @@ -18,6 +18,8 @@ class FetchLinkCardService < BaseService return if res.code != 200 || res.mime_type != 'text/html' attempt_opengraph(card, url) unless attempt_oembed(card, url) + rescue HTTP::ConnectionError, OpenSSL::SSL::SSLError + nil end private @@ -82,7 +84,13 @@ class FetchLinkCardService < BaseService return if response.code != 200 || response.mime_type != 'text/html' - page = Nokogiri::HTML(response.to_s) + html = response.to_s + + detector = CharlockHolmes::EncodingDetector.new + detector.strip_tags = true + + guess = detector.detect(html, response.charset) + page = Nokogiri::HTML(html, nil, guess&.fetch(:encoding)) card.type = :link card.title = meta_property(page, 'og:title') || page.at_xpath('//title')&.content diff --git a/app/services/fetch_remote_account_service.rb b/app/services/fetch_remote_account_service.rb index 8eed0d454..1efac365b 100644 --- a/app/services/fetch_remote_account_service.rb +++ b/app/services/fetch_remote_account_service.rb @@ -32,5 +32,8 @@ class FetchRemoteAccountService < BaseService rescue Nokogiri::XML::XPath::SyntaxError Rails.logger.debug 'Invalid XML or missing namespace' nil + rescue Goldfinger::NotFoundError, Goldfinger::Error + Rails.logger.debug 'Exceptions related to Goldfinger occurs' + nil end end diff --git a/app/services/fetch_remote_resource_service.rb b/app/services/fetch_remote_resource_service.rb index 5dfa3a0ff..2c1c1f05f 100644 --- a/app/services/fetch_remote_resource_service.rb +++ b/app/services/fetch_remote_resource_service.rb @@ -5,6 +5,9 @@ class FetchRemoteResourceService < BaseService def call(url) @url = url + + return process_local_url if local_url? + process_url unless fetched_atom_feed.nil? end @@ -38,4 +41,29 @@ class FetchRemoteResourceService < BaseService def xml_data @_xml_data ||= Nokogiri::XML(body, nil, 'utf-8') end + + def local_url? + TagManager.instance.local_url?(@url) + end + + def process_local_url + recognized_params = Rails.application.routes.recognize_path(@url) + + return unless recognized_params[:action] == 'show' + + if recognized_params[:controller] == 'stream_entries' + status = StreamEntry.find_by(id: recognized_params[:id])&.status + check_local_status(status) + elsif recognized_params[:controller] == 'statuses' + status = Status.find_by(id: recognized_params[:id]) + check_local_status(status) + elsif recognized_params[:controller] == 'accounts' + Account.find_local(recognized_params[:username]) + end + end + + def check_local_status(status) + return if status.nil? + status if status.public_visibility? || status.unlisted_visibility? + end end diff --git a/app/services/fetch_remote_status_service.rb b/app/services/fetch_remote_status_service.rb index f414813ad..4cfd33d90 100644 --- a/app/services/fetch_remote_status_service.rb +++ b/app/services/fetch_remote_status_service.rb @@ -33,6 +33,9 @@ class FetchRemoteStatusService < BaseService rescue Nokogiri::XML::XPath::SyntaxError Rails.logger.debug 'Invalid XML or missing namespace' nil + rescue Goldfinger::NotFoundError, Goldfinger::Error + Rails.logger.debug 'Exceptions related to Goldfinger occurs' + nil end def confirmed_domain?(domain, account) diff --git a/app/services/notify_service.rb b/app/services/notify_service.rb index 422d5f97e..407d385ea 100644 --- a/app/services/notify_service.rb +++ b/app/services/notify_service.rb @@ -60,7 +60,7 @@ class NotifyService < BaseService def create_notification @notification.save! return unless @notification.browserable? - Redis.current.publish("timeline:#{@recipient.id}", Oj.dump(event: :notification, payload: InlineRenderer.render(@notification, @recipient, 'api/v1/notifications/show'))) + Redis.current.publish("timeline:#{@recipient.id}", Oj.dump(event: :notification, payload: InlineRenderer.render(@notification, @recipient, :notification))) end def send_email diff --git a/app/services/precompute_feed_service.rb b/app/services/precompute_feed_service.rb index 83765bb05..85635a008 100644 --- a/app/services/precompute_feed_service.rb +++ b/app/services/precompute_feed_service.rb @@ -13,21 +13,16 @@ class PrecomputeFeedService < BaseService attr_reader :account def populate_feed - redis.pipelined do - statuses.each do |status| - process_status(status) - end + pairs = statuses.reverse_each.lazy.reject(&method(:status_filtered?)).map(&method(:process_status)).to_a + redis.pipelined do + redis.zadd(account_home_key, pairs) if pairs.any? redis.del("account:#{@account.id}:regeneration") end end def process_status(status) - add_status_to_feed(status) unless status_filtered?(status) - end - - def add_status_to_feed(status) - redis.zadd(account_home_key, status.id, status.reblog? ? status.reblog_of_id : status.id) + [status.id, status.reblog? ? status.reblog_of_id : status.id] end def status_filtered?(status) diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb index fbdf92caa..c335d2159 100644 --- a/app/services/process_feed_service.rb +++ b/app/services/process_feed_service.rb @@ -20,8 +20,6 @@ class ProcessFeedService < BaseService end class ProcessEntry - include AuthorExtractor - def call(xml, account) @account = account @xml = xml @@ -42,7 +40,7 @@ class ProcessFeedService < BaseService private def create_status - if redis.exists("delete_upon_arrival:#{id}") + if redis.exists("delete_upon_arrival:#{@account.id}:#{id}") Rails.logger.debug "Delete for status #{id} was queued, ignoring" return end @@ -99,15 +97,13 @@ class ProcessFeedService < BaseService def delete_status Rails.logger.debug "Deleting remote status #{id}" - status = Status.find_by(uri: id) + status = Status.find_by(uri: id, account: @account) if status.nil? - redis.setex("delete_upon_arrival:#{id}", 6 * 3_600, id) + redis.setex("delete_upon_arrival:#{@account.id}:#{id}", 6 * 3_600, id) else RemoveStatusService.new.call(status) end - - nil end def skip_unsupported_type? @@ -128,18 +124,7 @@ class ProcessFeedService < BaseService return [status, false] unless status.nil? - # If status embeds an author, find that author - # If that author cannot be found, don't record the status (do not misattribute) - if account?(entry) - begin - account = author_from_xml(entry) - return [nil, false] if account.nil? - rescue Goldfinger::Error - return [nil, false] - end - else - account = @account - end + account = @account return [nil, false] if account.suspended? |