diff options
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/activitypub/fetch_featured_collection_service.rb | 2 | ||||
-rw-r--r-- | app/services/activitypub/fetch_remote_account_service.rb | 2 | ||||
-rw-r--r-- | app/services/activitypub/fetch_remote_actor_service.rb | 2 | ||||
-rw-r--r-- | app/services/activitypub/fetch_remote_key_service.rb | 2 | ||||
-rw-r--r-- | app/services/activitypub/fetch_remote_status_service.rb | 13 | ||||
-rw-r--r-- | app/services/activitypub/fetch_replies_service.rb | 4 | ||||
-rw-r--r-- | app/services/activitypub/process_collection_service.rb | 6 | ||||
-rw-r--r-- | app/services/activitypub/process_status_update_service.rb | 2 | ||||
-rw-r--r-- | app/services/fetch_link_card_service.rb | 2 | ||||
-rw-r--r-- | app/services/fetch_oembed_service.rb | 2 | ||||
-rw-r--r-- | app/services/fetch_remote_status_service.rb | 4 | ||||
-rw-r--r-- | app/services/fetch_resource_service.rb | 2 | ||||
-rw-r--r-- | app/services/keys/claim_service.rb | 2 | ||||
-rw-r--r-- | app/services/keys/query_service.rb | 2 | ||||
-rw-r--r-- | app/services/resolve_account_service.rb | 2 | ||||
-rw-r--r-- | app/services/resolve_url_service.rb | 2 | ||||
-rw-r--r-- | app/services/verify_link_service.rb | 4 |
17 files changed, 32 insertions, 23 deletions
diff --git a/app/services/activitypub/fetch_featured_collection_service.rb b/app/services/activitypub/fetch_featured_collection_service.rb index a746ef4d6..1208820df 100644 --- a/app/services/activitypub/fetch_featured_collection_service.rb +++ b/app/services/activitypub/fetch_featured_collection_service.rb @@ -53,7 +53,7 @@ class ActivityPub::FetchFeaturedCollectionService < BaseService status.id rescue ActiveRecord::RecordInvalid => e - Rails.logger.debug "Invalid pinned status #{uri}: #{e.message}" + Rails.logger.debug { "Invalid pinned status #{uri}: #{e.message}" } nil end diff --git a/app/services/activitypub/fetch_remote_account_service.rb b/app/services/activitypub/fetch_remote_account_service.rb index 7aba8269e..567dd8a14 100644 --- a/app/services/activitypub/fetch_remote_account_service.rb +++ b/app/services/activitypub/fetch_remote_account_service.rb @@ -6,7 +6,7 @@ class ActivityPub::FetchRemoteAccountService < ActivityPub::FetchRemoteActorServ actor = super return actor if actor.nil? || actor.is_a?(Account) - Rails.logger.debug "Fetching account #{uri} failed: Expected Account, got #{actor.class.name}" + Rails.logger.debug { "Fetching account #{uri} failed: Expected Account, got #{actor.class.name}" } raise Error, "Expected Account, got #{actor.class.name}" unless suppress_errors end end diff --git a/app/services/activitypub/fetch_remote_actor_service.rb b/app/services/activitypub/fetch_remote_actor_service.rb index 4f60ea5e8..8908d21e2 100644 --- a/app/services/activitypub/fetch_remote_actor_service.rb +++ b/app/services/activitypub/fetch_remote_actor_service.rb @@ -38,7 +38,7 @@ class ActivityPub::FetchRemoteActorService < BaseService ActivityPub::ProcessAccountService.new.call(@username, @domain, @json, only_key: only_key, verified_webfinger: !only_key, request_id: request_id) rescue Error => e - Rails.logger.debug "Fetching actor #{uri} failed: #{e.message}" + Rails.logger.debug { "Fetching actor #{uri} failed: #{e.message}" } raise unless suppress_errors end diff --git a/app/services/activitypub/fetch_remote_key_service.rb b/app/services/activitypub/fetch_remote_key_service.rb index 32e82b47a..8eb97c1e6 100644 --- a/app/services/activitypub/fetch_remote_key_service.rb +++ b/app/services/activitypub/fetch_remote_key_service.rb @@ -38,7 +38,7 @@ class ActivityPub::FetchRemoteKeyService < BaseService find_actor(owner_uri, @owner, suppress_errors) rescue Error => e - Rails.logger.debug "Fetching key #{uri} failed: #{e.message}" + Rails.logger.debug { "Fetching key #{uri} failed: #{e.message}" } raise unless suppress_errors end diff --git a/app/services/activitypub/fetch_remote_status_service.rb b/app/services/activitypub/fetch_remote_status_service.rb index 21b9242f8..936737bf6 100644 --- a/app/services/activitypub/fetch_remote_status_service.rb +++ b/app/services/activitypub/fetch_remote_status_service.rb @@ -2,10 +2,13 @@ class ActivityPub::FetchRemoteStatusService < BaseService include JsonLdHelper + include Redisable + + DISCOVERIES_PER_REQUEST = 1000 # Should be called when uri has already been checked for locality def call(uri, id: true, prefetched_body: nil, on_behalf_of: nil, expected_actor_uri: nil, request_id: nil) - @request_id = request_id + @request_id = request_id || "#{Time.now.utc.to_i}-status-#{uri}" @json = begin if prefetched_body.nil? fetch_resource(uri, id, on_behalf_of) @@ -42,7 +45,13 @@ class ActivityPub::FetchRemoteStatusService < BaseService # activity as an update rather than create activity_json['type'] = 'Update' if equals_or_includes_any?(activity_json['type'], %w(Create)) && Status.where(uri: object_uri, account_id: actor.id).exists? - ActivityPub::Activity.factory(activity_json, actor, request_id: request_id).perform + with_redis do |redis| + discoveries = redis.incr("status_discovery_per_request:#{@request_id}") + redis.expire("status_discovery_per_request:#{@request_id}", 5.minutes.seconds) + return nil if discoveries > DISCOVERIES_PER_REQUEST + end + + ActivityPub::Activity.factory(activity_json, actor, request_id: @request_id).perform end private diff --git a/app/services/activitypub/fetch_replies_service.rb b/app/services/activitypub/fetch_replies_service.rb index 8cb309e52..18a27e851 100644 --- a/app/services/activitypub/fetch_replies_service.rb +++ b/app/services/activitypub/fetch_replies_service.rb @@ -3,14 +3,14 @@ class ActivityPub::FetchRepliesService < BaseService include JsonLdHelper - def call(parent_status, collection_or_uri, allow_synchronous_requests = true) + def call(parent_status, collection_or_uri, allow_synchronous_requests: true, request_id: nil) @account = parent_status.account @allow_synchronous_requests = allow_synchronous_requests @items = collection_items(collection_or_uri) return if @items.nil? - FetchReplyWorker.push_bulk(filtered_replies) + FetchReplyWorker.push_bulk(filtered_replies) { |reply_uri| [reply_uri, { 'request_id' => request_id}] } @items end diff --git a/app/services/activitypub/process_collection_service.rb b/app/services/activitypub/process_collection_service.rb index fffe30195..52f48bd49 100644 --- a/app/services/activitypub/process_collection_service.rb +++ b/app/services/activitypub/process_collection_service.rb @@ -11,7 +11,7 @@ class ActivityPub::ProcessCollectionService < BaseService begin @json = compact(@json) if @json['signature'].is_a?(Hash) rescue JSON::LD::JsonLdError => e - Rails.logger.debug "Error when compacting JSON-LD document for #{value_or_id(@json['actor'])}: #{e.message}" + Rails.logger.debug { "Error when compacting JSON-LD document for #{value_or_id(@json['actor'])}: #{e.message}" } @json = original_json.without('signature') end @@ -71,8 +71,8 @@ class ActivityPub::ProcessCollectionService < BaseService @account = ActivityPub::LinkedDataSignature.new(@json).verify_actor! @account = nil unless @account.is_a?(Account) @account - rescue JSON::LD::JsonLdError => e - Rails.logger.debug "Could not verify LD-Signature for #{value_or_id(@json['actor'])}: #{e.message}" + rescue JSON::LD::JsonLdError, RDF::WriterError => e + Rails.logger.debug { "Could not verify LD-Signature for #{value_or_id(@json['actor'])}: #{e.message}" } nil end end diff --git a/app/services/activitypub/process_status_update_service.rb b/app/services/activitypub/process_status_update_service.rb index 11b38ab92..1dc393e28 100644 --- a/app/services/activitypub/process_status_update_service.rb +++ b/app/services/activitypub/process_status_update_service.rb @@ -94,7 +94,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService @next_media_attachments << media_attachment rescue Addressable::URI::InvalidURIError => e - Rails.logger.debug "Invalid URL in attachment: #{e}" + Rails.logger.debug { "Invalid URL in attachment: #{e}" } end end diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb index e5b5b730e..4d55aa5e2 100644 --- a/app/services/fetch_link_card_service.rb +++ b/app/services/fetch_link_card_service.rb @@ -30,7 +30,7 @@ class FetchLinkCardService < BaseService attach_card if @card&.persisted? rescue HTTP::Error, OpenSSL::SSL::SSLError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError => e - Rails.logger.debug "Error fetching link #{@original_url}: #{e}" + Rails.logger.debug { "Error fetching link #{@original_url}: #{e}" } nil end diff --git a/app/services/fetch_oembed_service.rb b/app/services/fetch_oembed_service.rb index 7d0879c79..9851ac098 100644 --- a/app/services/fetch_oembed_service.rb +++ b/app/services/fetch_oembed_service.rb @@ -82,7 +82,7 @@ class FetchOEmbedService return if @endpoint_url.blank? body = Request.new(:get, @endpoint_url).perform do |res| - res.code != 200 ? nil : res.body_with_limit + res.code == 200 ? res.body_with_limit : nil end validate(parse_for_format(body)) if body.present? diff --git a/app/services/fetch_remote_status_service.rb b/app/services/fetch_remote_status_service.rb index eafde4d4a..08c2d24ba 100644 --- a/app/services/fetch_remote_status_service.rb +++ b/app/services/fetch_remote_status_service.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class FetchRemoteStatusService < BaseService - def call(url, prefetched_body = nil) + def call(url, prefetched_body: nil, request_id: nil) if prefetched_body.nil? resource_url, resource_options = FetchResourceService.new.call(url) else @@ -9,6 +9,6 @@ class FetchRemoteStatusService < BaseService resource_options = { prefetched_body: prefetched_body } end - ActivityPub::FetchRemoteStatusService.new.call(resource_url, **resource_options) unless resource_url.nil? + ActivityPub::FetchRemoteStatusService.new.call(resource_url, **resource_options.merge(request_id: request_id)) unless resource_url.nil? end end diff --git a/app/services/fetch_resource_service.rb b/app/services/fetch_resource_service.rb index 73204e55d..4470fca01 100644 --- a/app/services/fetch_resource_service.rb +++ b/app/services/fetch_resource_service.rb @@ -12,7 +12,7 @@ class FetchResourceService < BaseService process(url) rescue HTTP::Error, OpenSSL::SSL::SSLError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError => e - Rails.logger.debug "Error fetching resource #{@url}: #{e}" + Rails.logger.debug { "Error fetching resource #{@url}: #{e}" } nil end diff --git a/app/services/keys/claim_service.rb b/app/services/keys/claim_service.rb index ae9e24a24..0451c3cb1 100644 --- a/app/services/keys/claim_service.rb +++ b/app/services/keys/claim_service.rb @@ -58,7 +58,7 @@ class Keys::ClaimService < BaseService @result = Result.new(@target_account, @device_id, key_id: json['id'], key: json['publicKeyBase64'], signature: json.dig('signature', 'signatureValue')) rescue HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::Error => e - Rails.logger.debug "Claiming one-time key for #{@target_account.acct}:#{@device_id} failed: #{e}" + Rails.logger.debug { "Claiming one-time key for #{@target_account.acct}:#{@device_id} failed: #{e}" } nil end diff --git a/app/services/keys/query_service.rb b/app/services/keys/query_service.rb index ac3388bdc..404854c9f 100644 --- a/app/services/keys/query_service.rb +++ b/app/services/keys/query_service.rb @@ -73,7 +73,7 @@ class Keys::QueryService < BaseService Device.new(device_id: device['id'], name: device['name'], identity_key: device.dig('identityKey', 'publicKeyBase64'), fingerprint_key: device.dig('fingerprintKey', 'publicKeyBase64'), claim_url: device['claim']) end rescue HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::Error => e - Rails.logger.debug "Querying devices for #{@account.acct} failed: #{e}" + Rails.logger.debug { "Querying devices for #{@account.acct} failed: #{e}" } nil end end diff --git a/app/services/resolve_account_service.rb b/app/services/resolve_account_service.rb index d8b81a7b9..1ba372cd6 100644 --- a/app/services/resolve_account_service.rb +++ b/app/services/resolve_account_service.rb @@ -54,7 +54,7 @@ class ResolveAccountService < BaseService fetch_account! rescue Webfinger::Error => e - Rails.logger.debug "Webfinger query for #{@uri} failed: #{e}" + Rails.logger.debug { "Webfinger query for #{@uri} failed: #{e}" } raise unless @options[:suppress_errors] end diff --git a/app/services/resolve_url_service.rb b/app/services/resolve_url_service.rb index 52f35daf3..d8e795f3b 100644 --- a/app/services/resolve_url_service.rb +++ b/app/services/resolve_url_service.rb @@ -25,7 +25,7 @@ class ResolveURLService < BaseService if equals_or_includes_any?(type, ActivityPub::FetchRemoteActorService::SUPPORTED_TYPES) ActivityPub::FetchRemoteActorService.new.call(resource_url, prefetched_body: body) elsif equals_or_includes_any?(type, ActivityPub::Activity::Create::SUPPORTED_TYPES + ActivityPub::Activity::Create::CONVERTED_TYPES) - status = FetchRemoteStatusService.new.call(resource_url, body) + status = FetchRemoteStatusService.new.call(resource_url, prefetched_body: body) authorize_with @on_behalf_of, status, :show? unless status.nil? status end diff --git a/app/services/verify_link_service.rb b/app/services/verify_link_service.rb index 9708cdd73..707aeb4e0 100644 --- a/app/services/verify_link_service.rb +++ b/app/services/verify_link_service.rb @@ -11,7 +11,7 @@ class VerifyLinkService < BaseService field.mark_verified! rescue OpenSSL::SSL::SSLError, HTTP::Error, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, IPAddr::AddressFamilyError => e - Rails.logger.debug "Error fetching link #{@url}: #{e}" + Rails.logger.debug { "Error fetching link #{@url}: #{e}" } nil end @@ -19,7 +19,7 @@ class VerifyLinkService < BaseService def perform_request! @body = Request.new(:get, @url).add_headers('Accept' => 'text/html').perform do |res| - res.code != 200 ? nil : res.body_with_limit + res.code == 200 ? res.body_with_limit : nil end end |