You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# frozen_string_literal: trueclassUpdateStatusService < BaseServiceincludeRedisableincludeLanguagesHelper# @param [Status] status# @param [Integer] account_id# @param [Hash] options# @option options [Array<Integer>] :media_ids# @option options [Hash] :poll# @option options [String] :text# @option options [String] :spoiler_text# @option options [Boolean] :sensitive# @option options [String] :languagedefcall(status,account_id,options={})@status=status@options=options@account_id=account_idStatus.transactiondocreate_previous_edit!update_media_attachments!if@options.key?(:media_ids)update_poll!if@options.key?(:poll)update_immediate_attributes!create_edit!endqueue_poll_notifications!reset_preview_card!update_metadata!broadcast_updates!@statusendprivatedefprepair_remote_attachments!@text=@options[:text]#@status.text@account=Account.find(@account_id)# Rails.logger.info("[debug] update @text #{JSON.generate([@text])}")# Rails.logger.info("[debug] update media_attachments #{JSON.generate([@status.media_attachments.to_a])}")remote_media_attachments=process_remote_attachments# Rails.logger.info("[debug] update @text after #{JSON.generate([@text])}")# Rails.logger.info("[debug] update media_attachments after #{JSON.generate([@status.media_attachments.to_a])}")return@status.media_attachments.to_a.concat(remote_media_attachments)enddefupdate_media_attachments!previous_media_attachments=@status.media_attachments.to_anext_media_attachments=validate_media!# Rails.logger.info("[debug] next_media_attachments #{JSON.generate([next_media_attachments])}")added_media_attachments=next_media_attachments - previous_media_attachmentsMediaAttachment.where(id: added_media_attachments.map(&:id)).update_all(status_id: @status.id)@status.ordered_media_attachment_ids=(@options[:media_ids] || []).map(&:to_i) & next_media_attachments.map(&:id)@status.media_attachments.reloadenddefvalidate_media!media_ids=@options[:media_ids]new_remote_media_attachments=prepair_remote_attachments!media_ids=media_ids.concat(new_remote_media_attachments.map(&:id))Rails.logger.info("[debugtoomany] media_ids #{JSON.generate([media_ids])}")# return [] if @options[:media_ids].blank? || !@options[:media_ids].is_a?(Enumerable)return[]ifmedia_ids.blank? || !media_ids.is_a?(Enumerable)# raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > 9 || @options[:poll].present?raiseMastodon::ValidationError,I18n.t('media_attachments.validations.too_many_nine')ifmedia_ids.size > 9 || @options[:poll].present?media_attachments=@status.account.media_attachments.where(status_id: [nil,@status.id]).where(scheduled_status_id: nil).where(id: @options[:media_ids].take(9).map(&:to_i)).to_amedia_attachments=media_attachments.to_a.concat(new_remote_media_attachments)media_attachments=media_attachments.take(9)raiseMastodon::ValidationError,I18n.t('media_attachments.validations.images_and_video')ifmedia_attachments.size > 1 && media_attachments.find(&:audio_or_video?)raiseMastodon::ValidationError,I18n.t('media_attachments.validations.not_ready')ifmedia_attachments.any?(&:not_processed?)media_attachmentsenddefupdate_poll!previous_poll=@status.preloadable_poll@previous_expires_at=previous_poll&.expires_atif@options[:poll].present?poll=previous_poll || @status.account.polls.new(status: @status,votes_count: 0)# If for some reasons the options were changed, it invalidates all previous# votes, so we need to remove thempoll_changed=trueif@options[:poll][:options] != poll.options || ActiveModel::Type::Boolean.new.cast(@options[:poll][:multiple]) != poll.multiplepoll.options=@options[:poll][:options]poll.hide_totals=@options[:poll][:hide_totals] || falsepoll.multiple=@options[:poll][:multiple] || falsepoll.expires_in=@options[:poll][:expires_in]poll.reset_votes!ifpoll_changedpoll.save!@status.poll_id=poll.idelsifprevious_poll.present?previous_poll.destroy@status.poll_id=nilendenddefupdate_immediate_attributes!@status.text=@options[:text].presence || @options.delete(:spoiler_text) || ''if@options.key?(:text)@status.text=@text.presence || @options.delete(:spoiler_text) || ''if@options.key?(:text)@status.spoiler_text=@options[:spoiler_text] || ''if@options.key?(:spoiler_text)@status.sensitive=@options[:sensitive] || @options[:spoiler_text].present?if@options.key?(:sensitive) || @options.key?(:spoiler_text)@status.language=valid_locale_cascade(@options[:language],@status.language,@status.account.user&.preferred_posting_language,I18n.default_locale)@status.edited_at=Time.now.utc@status.content_type=@options[:content_type] || 'text/plain'@status.local_only= !!@options[:local_only]@status.save!enddefreset_preview_card!returnunless@status.text_previously_changed?@status.preview_cards.clearLinkCrawlWorker.perform_async(@status.id)enddefupdate_metadata!ProcessHashtagsService.new.call(@status)ProcessMentionsService.new.call(@status)enddefbroadcast_updates!DistributionWorker.perform_async(@status.id,{'update'=>true})ActivityPub::StatusUpdateDistributionWorker.perform_async(@status.id)enddefqueue_poll_notifications!poll=@status.preloadable_poll# If the poll had no expiration date set but now has, or now has a sooner# expiration date, and people have voted, schedule a notificationreturnunlesspoll.present? && poll.expires_at.present? && poll.votes.exists?PollExpirationNotifyWorker.remove_from_scheduled(poll.id)if@previous_expires_at.present? && @previous_expires_at > poll.expires_atPollExpirationNotifyWorker.perform_at(poll.expires_at + 5.minutes,poll.id)enddefcreate_previous_edit!# We only need to create a previous edit when no previous edits exist, e.g.# when the status has never been edited. For other cases, we always create# an edit, so the step can be skippedreturnif@status.edits.any?@status.snapshot!(at_time: @status.created_at,rate_limit: false)enddefcreate_edit!@status.snapshot!(account_id: @account_id)enddefprocess_remote_attachments# IMAGE: [https://s3.mashiro.top/view/2022/02/24/6f3f209aa55e3083f0659ecb62448fc0.jpg]image_array=@text.scan(/IMAGE:\s*\[\s*((?:https|http):\/\/.+?)\s*\](?:\s*\{\s*((?:https|http):\/\/.+?)\s*\})*/)video_array=@text.scan(/VIDEO:\s*\[\s*((?:https|http):\/\/.+?)\s*\](?:\s*\{\s*((?:https|http):\/\/.+?)\s*\})*/)@text=@text.gsub(/(?:IMAGE|VIDEO):\s*\[\s*((?:https|http):\/\/.+?)\s*\](?:\s*\{\s*((?:https|http):\/\/.+?)\s*\})*/,'')return[]ifimage_array.blank? && video_array.blank?if !ENV['SKIP_REMOTE_MEDIA_AMOUNT_CHECK']Rails.logger.info("[debugtoomany] limit #{JSON.generate([@options[:media_ids].size + image_array.size])}")raiseMastodon::ValidationError,I18n.t('media_attachments.validations.too_many_nine')if@options[:media_ids].size + image_array.size > 9 || @options[:poll].present?endmedia_attachments=[]media_array=if !video_array.empty?[video_array.first]elseimage_arrayendmedia_array.eachdo |media|
nextifmedia_attachments.size >= 9original=Addressable::URI.parse(media[0]).normalize.to_sthumbnail=thumbnail_remote_url(media[1])media_attachment=MediaAttachment.create(account: @account,remote_url: original,thumbnail_remote_url: thumbnail,description: "Media source: #{original}",focus: nil,blurhash: nil)media_attachments << media_attachmentmedia_attachment.download_file!media_attachment.download_thumbnail!media_attachment.save!rescueMastodon::UnexpectedResponseError,HTTP::TimeoutError,HTTP::ConnectionError,OpenSSL::SSL::SSLErrorRedownloadMediaWorker.perform_in(rand(30..600).seconds,media_attachment.id)rescueSeahorse::Client::NetworkingErrornilendmedia_attachmentsrescueAddressable::URI::InvalidURIError=>eRails.logger.debug"Invalid URL in attachment: #{e}"media_attachmentsenddefthumbnail_remote_url(url)returnnilifurl == nilAddressable::URI.parse(url).normalize.to_srescueAddressable::URI::InvalidURIErrornilendend
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
本来尝试改了一下,但是发现有bug,,想来其实是基本用不到的功能,就不折腾了
Beta Was this translation helpful? Give feedback.
All reactions