mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Convert mix of JSON.parse and JSON.load_file (#38242)
This commit is contained in:
@@ -86,14 +86,14 @@ class FetchOEmbedService
|
|||||||
end
|
end
|
||||||
|
|
||||||
validate(parse_for_format(body)) if body.present?
|
validate(parse_for_format(body)) if body.present?
|
||||||
rescue Oj::ParseError, Ox::ParseError
|
rescue JSON::ParserError, Ox::ParseError
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_for_format(body)
|
def parse_for_format(body)
|
||||||
case @format
|
case @format
|
||||||
when :json
|
when :json
|
||||||
Oj.load(body, mode: :strict)&.with_indifferent_access
|
JSON.parse(body)&.with_indifferent_access
|
||||||
when :xml
|
when :xml
|
||||||
Ox.load(body, mode: :hash_no_attrs)&.with_indifferent_access&.dig(:oembed)
|
Ox.load(body, mode: :hash_no_attrs)&.with_indifferent_access&.dig(:oembed)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -140,13 +140,13 @@ module Mastodon::CLI
|
|||||||
Request.new(:get, "https://#{domain}/api/v1/instance").perform do |res|
|
Request.new(:get, "https://#{domain}/api/v1/instance").perform do |res|
|
||||||
next unless res.code == 200
|
next unless res.code == 200
|
||||||
|
|
||||||
stats[domain] = Oj.load(res.to_s)
|
stats[domain] = JSON.parse(res.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
Request.new(:get, "https://#{domain}/api/v1/instance/peers").perform do |res|
|
Request.new(:get, "https://#{domain}/api/v1/instance/peers").perform do |res|
|
||||||
next unless res.code == 200
|
next unless res.code == 200
|
||||||
|
|
||||||
Oj.load(res.to_s).reject { |peer| stats.key?(peer) }.each do |peer|
|
JSON.parse(res.to_s).reject { |peer| stats.key?(peer) }.each do |peer|
|
||||||
pool.post(peer, &work_unit)
|
pool.post(peer, &work_unit)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -154,7 +154,7 @@ module Mastodon::CLI
|
|||||||
Request.new(:get, "https://#{domain}/api/v1/instance/activity").perform do |res|
|
Request.new(:get, "https://#{domain}/api/v1/instance/activity").perform do |res|
|
||||||
next unless res.code == 200
|
next unless res.code == 200
|
||||||
|
|
||||||
stats[domain]['activity'] = Oj.load(res.to_s)
|
stats[domain]['activity'] = JSON.parse(res.to_s)
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
failed.increment
|
failed.increment
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ namespace :emojis do
|
|||||||
emojis_light = '👽⚾🐔☁️💨🕊️👀🍥👻🐐❕❔⛸️🌩️🔊🔇📃🌧️🐏🍚🍙🐓🐑💀☠️🌨️🔉🔈💬💭🏐🏳️⚪⬜◽◻️▫️🪽🪿'
|
emojis_light = '👽⚾🐔☁️💨🕊️👀🍥👻🐐❕❔⛸️🌩️🔊🔇📃🌧️🐏🍚🍙🐓🐑💀☠️🌨️🔉🔈💬💭🏐🏳️⚪⬜◽◻️▫️🪽🪿'
|
||||||
emojis_dark = '🎱🐜⚫🖤⬛◼️◾◼️✒️▪️💣🎳📷📸♣️🕶️✴️🔌💂♀️📽️🍳🦍💂🔪🕳️🕹️🕋🖊️🖋️💂♂️🎤🎓🎥🎼♠️🎩🦃📼📹🎮🐃🏴🐞🕺📱📲🚲🪮🐦⬛'
|
emojis_dark = '🎱🐜⚫🖤⬛◼️◾◼️✒️▪️💣🎳📷📸♣️🕶️✴️🔌💂♀️📽️🍳🦍💂🔪🕳️🕹️🕋🖊️🖋️💂♂️🎤🎓🎥🎼♠️🎩🦃📼📹🎮🐃🏴🐞🕺📱📲🚲🪮🐦⬛'
|
||||||
|
|
||||||
map = Oj.load(File.read(src))
|
map = JSON.parse(File.read(src))
|
||||||
|
|
||||||
emojis_light.each_grapheme_cluster do |emoji|
|
emojis_light.each_grapheme_cluster do |emoji|
|
||||||
gen_border map[emoji], 'black'
|
gen_border map[emoji], 'black'
|
||||||
@@ -193,7 +193,7 @@ namespace :emojis do
|
|||||||
require 'vips'
|
require 'vips'
|
||||||
|
|
||||||
src = Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_data.json')
|
src = Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_data.json')
|
||||||
sheet = Oj.load(File.read(src))
|
sheet = JSON.load_file(src)
|
||||||
|
|
||||||
max = 0
|
max = 0
|
||||||
sheet['emojis'].each_value do |row|
|
sheet['emojis'].each_value do |row|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace :repo do
|
|||||||
|
|
||||||
while url.present?
|
while url.present?
|
||||||
response = HTTP.get(url)
|
response = HTTP.get(url)
|
||||||
contributors = Oj.load(response.body)
|
contributors = JSON.parse(response.body)
|
||||||
|
|
||||||
contributors.each do |c|
|
contributors.each do |c|
|
||||||
file << "* [#{c['login']}](#{c['html_url']})\n" if c['login']
|
file << "* [#{c['login']}](#{c['html_url']})\n" if c['login']
|
||||||
@@ -68,7 +68,7 @@ namespace :repo do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
pull_request = Oj.load(response.to_s)
|
pull_request = JSON.parse(response.to_s)
|
||||||
pull_request['user']['login']
|
pull_request['user']['login']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ module ViteRuby::ManifestIntegrityExtension
|
|||||||
end
|
end
|
||||||
|
|
||||||
def load_name_lookup_cache
|
def load_name_lookup_cache
|
||||||
Oj.load(config.build_output_dir.join('.vite/manifest-lookup.json').read)
|
JSON.load_file(config.build_output_dir.join('.vite/manifest-lookup.json'))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Upstream's `virtual` type is a hack, re-implement it with efficient exact name lookup
|
# Upstream's `virtual` type is a hack, re-implement it with efficient exact name lookup
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ RSpec.describe ActivityPub::Activity::QuoteRequest do
|
|||||||
expect { subject.perform }
|
expect { subject.perform }
|
||||||
.to enqueue_sidekiq_job(ActivityPub::DeliveryWorker)
|
.to enqueue_sidekiq_job(ActivityPub::DeliveryWorker)
|
||||||
.with(satisfying do |body|
|
.with(satisfying do |body|
|
||||||
outgoing_json = Oj.load(body)
|
outgoing_json = JSON.parse(body)
|
||||||
outgoing_json['type'] == 'Reject' && %w(type id actor object instrument).all? { |key| json[key] == outgoing_json['object'][key] }
|
outgoing_json['type'] == 'Reject' && %w(type id actor object instrument).all? { |key| json[key] == outgoing_json['object'][key] }
|
||||||
end, recipient.id, sender.inbox_url)
|
end, recipient.id, sender.inbox_url)
|
||||||
end
|
end
|
||||||
@@ -78,7 +78,7 @@ RSpec.describe ActivityPub::Activity::QuoteRequest do
|
|||||||
expect { subject.perform }
|
expect { subject.perform }
|
||||||
.to enqueue_sidekiq_job(ActivityPub::DeliveryWorker)
|
.to enqueue_sidekiq_job(ActivityPub::DeliveryWorker)
|
||||||
.with(satisfying do |body|
|
.with(satisfying do |body|
|
||||||
outgoing_json = Oj.load(body)
|
outgoing_json = JSON.parse(body)
|
||||||
outgoing_json['type'] == 'Reject' && json['instrument']['id'] == outgoing_json['object']['instrument'] && %w(type id actor object).all? { |key| json[key] == outgoing_json['object'][key] }
|
outgoing_json['type'] == 'Reject' && json['instrument']['id'] == outgoing_json['object']['instrument'] && %w(type id actor object).all? { |key| json[key] == outgoing_json['object'][key] }
|
||||||
end, recipient.id, sender.inbox_url)
|
end, recipient.id, sender.inbox_url)
|
||||||
end
|
end
|
||||||
@@ -95,7 +95,7 @@ RSpec.describe ActivityPub::Activity::QuoteRequest do
|
|||||||
.to change { quoted_post.reload.quotes.accepted.count }.by(1)
|
.to change { quoted_post.reload.quotes.accepted.count }.by(1)
|
||||||
.and enqueue_sidekiq_job(ActivityPub::DeliveryWorker)
|
.and enqueue_sidekiq_job(ActivityPub::DeliveryWorker)
|
||||||
.with(satisfying do |body|
|
.with(satisfying do |body|
|
||||||
outgoing_json = Oj.load(body)
|
outgoing_json = JSON.parse(body)
|
||||||
outgoing_json['type'] == 'Accept' && %w(type id actor object instrument).all? { |key| json[key] == outgoing_json['object'][key] }
|
outgoing_json['type'] == 'Accept' && %w(type id actor object instrument).all? { |key| json[key] == outgoing_json['object'][key] }
|
||||||
end, recipient.id, sender.inbox_url)
|
end, recipient.id, sender.inbox_url)
|
||||||
end
|
end
|
||||||
@@ -113,7 +113,7 @@ RSpec.describe ActivityPub::Activity::QuoteRequest do
|
|||||||
.to change { quoted_post.reload.quotes.accepted.count }.by(1)
|
.to change { quoted_post.reload.quotes.accepted.count }.by(1)
|
||||||
.and enqueue_sidekiq_job(ActivityPub::DeliveryWorker)
|
.and enqueue_sidekiq_job(ActivityPub::DeliveryWorker)
|
||||||
.with(satisfying do |body|
|
.with(satisfying do |body|
|
||||||
outgoing_json = Oj.load(body)
|
outgoing_json = JSON.parse(body)
|
||||||
outgoing_json['type'] == 'Accept' && json['instrument']['id'] == outgoing_json['object']['instrument'] && %w(type id actor object).all? { |key| json[key] == outgoing_json['object'][key] }
|
outgoing_json['type'] == 'Accept' && json['instrument']['id'] == outgoing_json['object']['instrument'] && %w(type id actor object).all? { |key| json[key] == outgoing_json['object'][key] }
|
||||||
end, recipient.id, sender.inbox_url)
|
end, recipient.id, sender.inbox_url)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ RSpec.describe 'Donation campaigns' do
|
|||||||
expect(Rails.cache.read("donation_campaign_request:#{seed}:en", raw: true))
|
expect(Rails.cache.read("donation_campaign_request:#{seed}:en", raw: true))
|
||||||
.to eq 'campaign-1:en'
|
.to eq 'campaign-1:en'
|
||||||
|
|
||||||
expect(Oj.load(Rails.cache.read('donation_campaign:campaign-1:en', raw: true)))
|
expect(JSON.parse(Rails.cache.read('donation_campaign:campaign-1:en', raw: true)))
|
||||||
.to match(campaign_json)
|
.to match(campaign_json)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
let(:json) { Oj.load(JSON.generate(payload)) }
|
let(:json) { JSON.parse(JSON.generate(payload)) }
|
||||||
|
|
||||||
let(:alice) { Fabricate(:account) }
|
let(:alice) { Fabricate(:account) }
|
||||||
let(:bob) { Fabricate(:account) }
|
let(:bob) { Fabricate(:account) }
|
||||||
|
|||||||
@@ -161,8 +161,8 @@ class StreamingClient
|
|||||||
|
|
||||||
def wait_for_message
|
def wait_for_message
|
||||||
message = @connection.wait_for_event(:message)
|
message = @connection.wait_for_event(:message)
|
||||||
event = Oj.load(message)
|
event = JSON.parse(message)
|
||||||
event['payload'] = Oj.load(event['payload']) if event['payload']
|
event['payload'] = JSON.parse(event['payload']) if event['payload']
|
||||||
|
|
||||||
event.deep_symbolize_keys
|
event.deep_symbolize_keys
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user