mirror of
https://github.com/mastodon/mastodon.git
synced 2026-03-21 18:05:23 -05:00
Convert Oj.load -> JSON.parse in most places (#38236)
This commit is contained in:
parent
0e14224eaf
commit
3832030711
|
|
@ -35,7 +35,7 @@ class Api::V1::DonationCampaignsController < Api::BaseController
|
|||
return if key.blank?
|
||||
|
||||
campaign = Rails.cache.read("donation_campaign:#{key}", raw: true)
|
||||
Oj.load(campaign) if campaign.present?
|
||||
JSON.parse(campaign) if campaign.present?
|
||||
end
|
||||
|
||||
def save_to_cache!(campaign)
|
||||
|
|
@ -57,7 +57,7 @@ class Api::V1::DonationCampaignsController < Api::BaseController
|
|||
url.query_values = { platform: 'web', seed: seed, locale: locale, environment: Rails.configuration.x.donation_campaigns.environment }.compact
|
||||
|
||||
Request.new(:get, url.to_s).perform do |res|
|
||||
return Oj.load(res.body_with_limit, mode: :strict) if res.code == 200
|
||||
return JSON.parse(res.body_with_limit) if res.code == 200
|
||||
end
|
||||
end
|
||||
rescue *Mastodon::HTTP_CONNECTION_ERRORS, Oj::ParseError
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ module JsonLdHelper
|
|||
end
|
||||
|
||||
def body_to_json(body, compare_id: nil)
|
||||
json = body.is_a?(String) ? Oj.load(body, mode: :strict) : body
|
||||
json = body.is_a?(String) ? JSON.parse(body) : body
|
||||
|
||||
return if compare_id.present? && json['id'] != compare_id
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class Admin::Metrics::Dimension::SoftwareVersionsDimension < Admin::Metrics::Dim
|
|||
|
||||
def ffmpeg_version
|
||||
version_output = Terrapin::CommandLine.new(Rails.configuration.x.ffprobe_binary, '-show_program_version -v 0 -of json').run
|
||||
version = Oj.load(version_output, mode: :strict, symbol_keys: true).dig(:program_version, :version)
|
||||
version = JSON.parse(version_output, symbolize_names: true).dig(:program_version, :version)
|
||||
|
||||
{
|
||||
key: 'ffmpeg',
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ class LinkDetailsExtractor
|
|||
end
|
||||
|
||||
def json
|
||||
@json ||= root_array(Oj.load(@data)).compact.find { |obj| SUPPORTED_TYPES.include?(obj['@type']) } || {}
|
||||
@json ||= root_array(JSON.parse(@data)).compact.find { |obj| SUPPORTED_TYPES.include?(obj['@type']) } || {}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -265,7 +265,7 @@ class LinkDetailsExtractor
|
|||
next unless structured_data.valid?
|
||||
|
||||
structured_data
|
||||
rescue Oj::ParseError, EncodingError
|
||||
rescue JSON::ParserError, EncodingError
|
||||
Rails.logger.debug { "Invalid JSON-LD in #{@original_url}" }
|
||||
next
|
||||
end.first
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class TranslationService::DeepL < TranslationService
|
|||
|
||||
def fetch_languages(type)
|
||||
request(:get, "/v2/languages?type=#{type}") do |res|
|
||||
Oj.load(res.body_with_limit).map { |language| normalize_language(language['language']) }
|
||||
JSON.parse(res.body_with_limit).map { |language| normalize_language(language['language']) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ class TranslationService::DeepL < TranslationService
|
|||
end
|
||||
|
||||
def transform_response(json)
|
||||
data = Oj.load(json, mode: :strict)
|
||||
data = JSON.parse(json)
|
||||
raise UnexpectedResponseError unless data.is_a?(Hash)
|
||||
|
||||
data['translations'].map do |translation|
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class TranslationService::LibreTranslate < TranslationService
|
|||
|
||||
def languages
|
||||
request(:get, '/languages') do |res|
|
||||
languages = Oj.load(res.body_with_limit).to_h do |language|
|
||||
languages = JSON.parse(res.body_with_limit).to_h do |language|
|
||||
[language['code'], language['targets'].without(language['code'])]
|
||||
end
|
||||
languages[nil] = languages.values.flatten.uniq.sort
|
||||
|
|
@ -45,7 +45,7 @@ class TranslationService::LibreTranslate < TranslationService
|
|||
end
|
||||
|
||||
def transform_response(json, source_language)
|
||||
data = Oj.load(json, mode: :strict)
|
||||
data = JSON.parse(json)
|
||||
raise UnexpectedResponseError unless data.is_a?(Hash)
|
||||
|
||||
data['translatedText'].map.with_index do |text, index|
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class VideoMetadataExtractor
|
|||
|
||||
def initialize(path)
|
||||
@path = path
|
||||
@metadata = Oj.load(ffmpeg_command_output, mode: :strict, symbol_keys: true)
|
||||
@metadata = JSON.parse(ffmpeg_command_output, symbolize_names: true)
|
||||
|
||||
parse_metadata
|
||||
rescue Terrapin::ExitStatusError, Oj::ParseError
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class Webfinger
|
|||
|
||||
def initialize(uri, body)
|
||||
@uri = uri
|
||||
@json = Oj.load(body, mode: :strict)
|
||||
@json = JSON.parse(body)
|
||||
|
||||
validate_response!
|
||||
end
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class Webhooks::PayloadRenderer
|
|||
/iox
|
||||
|
||||
def initialize(json)
|
||||
@document = DocumentTraverser.new(Oj.load(json))
|
||||
@document = DocumentTraverser.new(JSON.parse(json))
|
||||
end
|
||||
|
||||
def render(template)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class ActivityPub::ProcessCollectionService < BaseService
|
|||
|
||||
def call(body, actor, **options)
|
||||
@account = actor
|
||||
@json = original_json = Oj.load(body, mode: :strict)
|
||||
@json = original_json = JSON.parse(body)
|
||||
@options = options
|
||||
|
||||
return unless @json.is_a?(Hash)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class SoftwareUpdateCheckService < BaseService
|
|||
|
||||
def fetch_update_notices
|
||||
Request.new(:get, "#{api_url}?version=#{version}").add_headers('Accept' => 'application/json', 'User-Agent' => 'Mastodon update checker').perform do |res|
|
||||
return Oj.load(res.body_with_limit, mode: :strict) if res.code == 200
|
||||
return JSON.parse(res.body_with_limit) if res.code == 200
|
||||
end
|
||||
rescue *Mastodon::HTTP_CONNECTION_ERRORS, Oj::ParseError
|
||||
nil
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ReactionValidator < ActiveModel::Validator
|
||||
SUPPORTED_EMOJIS = Oj.load_file(Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_map.json').to_s).keys.freeze
|
||||
SUPPORTED_EMOJIS = JSON.load_file(Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_map.json').to_s).keys.freeze
|
||||
|
||||
LIMIT = 8
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user