Merge commit 'a02ff33f0e' into kb-draft-5.22-lts

This commit is contained in:
KMY 2024-08-16 22:15:12 +09:00
commit 3ab66262de
43 changed files with 212 additions and 68 deletions

View file

@ -365,13 +365,15 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
def fetch_replies(status)
collection = @object['replies']
return if collection.nil?
return if collection.blank?
replies = ActivityPub::FetchRepliesService.new.call(status, collection, allow_synchronous_requests: false, request_id: @options[:request_id])
return unless replies.nil?
uri = value_or_id(collection)
ActivityPub::FetchRepliesWorker.perform_async(status.id, uri, { 'request_id' => @options[:request_id] }) unless uri.nil?
rescue => e
Rails.logger.warn "Error fetching replies: #{e}"
end
def conversation_from_uri(uri)

View file

@ -20,6 +20,6 @@ class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base
serialized_hash = serialized_hash.select { |k, _| options[:fields].include?(k) } if options[:fields]
serialized_hash = self.class.transform_key_casing!(serialized_hash, instance_options)
{ '@context' => serialized_context(named_contexts, context_extensions) }.merge(serialized_hash)
{ '@context': serialized_context(named_contexts, context_extensions) }.merge(serialized_hash)
end
end

View file

@ -41,8 +41,8 @@ class VideoMetadataExtractor
@colorspace = video_stream[:pix_fmt]
@width = video_stream[:width]
@height = video_stream[:height]
@frame_rate = video_stream[:avg_frame_rate] == '0/0' ? nil : Rational(video_stream[:avg_frame_rate])
@r_frame_rate = video_stream[:r_frame_rate] == '0/0' ? nil : Rational(video_stream[:r_frame_rate])
@frame_rate = parse_framerate(video_stream[:avg_frame_rate])
@r_frame_rate = parse_framerate(video_stream[:r_frame_rate])
# For some video streams the frame_rate reported by `ffprobe` will be 0/0, but for these streams we
# should use `r_frame_rate` instead. Video screencast generated by Gnome Screencast have this issue.
@frame_rate ||= @r_frame_rate
@ -55,4 +55,10 @@ class VideoMetadataExtractor
@invalid = true if @metadata.key?(:error)
end
def parse_framerate(raw)
Rational(raw)
rescue ZeroDivisionError
nil
end
end

View file

@ -6,6 +6,8 @@ class Webfinger
class RedirectError < Error; end
class Response
ACTIVITYPUB_READY_TYPE = ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].freeze
attr_reader :uri
def initialize(uri, body)
@ -20,17 +22,28 @@ class Webfinger
end
def link(rel, attribute)
links.dig(rel, attribute)
links.dig(rel, 0, attribute)
end
def self_link_href
self_link.fetch('href')
end
private
def links
@links ||= @json['links'].index_by { |link| link['rel'] }
@links ||= @json.fetch('links', []).group_by { |link| link['rel'] }
end
def self_link
links.fetch('self', []).find do |link|
ACTIVITYPUB_READY_TYPE.include?(link['type'])
end
end
def validate_response!
raise Webfinger::Error, "Missing subject in response for #{@uri}" if subject.blank?
raise Webfinger::Error, "Missing self link in response for #{@uri}" if self_link.blank?
end
end