pixiv: fix failbooru when uploading bad pixiv id posts.
Fixes an "incompatible character encodings: UTF-8 and ASCII-8BIT" exception when uploading a deleted Pixiv post. Caused by the Pixiv API error message not having the encoding set to UTF-8.
This commit is contained in:
@@ -141,12 +141,13 @@ class PixivApiClient
|
||||
|
||||
url = "https://public-api.secure.pixiv.net/v#{API_VERSION}/works/#{illust_id.to_i}.json"
|
||||
resp = HTTParty.get(url, Danbooru.config.httparty_options.deep_merge(query: params, headers: headers))
|
||||
body = resp.body.force_encoding("utf-8")
|
||||
|
||||
if resp.success?
|
||||
json = parse_api_json(resp.body)
|
||||
json = parse_api_json(body)
|
||||
WorksResponse.new(json["response"][0])
|
||||
else
|
||||
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{resp.body})")
|
||||
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -177,11 +178,13 @@ private
|
||||
url = "https://oauth.secure.pixiv.net/auth/token"
|
||||
|
||||
resp = HTTParty.post(url, Danbooru.config.httparty_options.deep_merge(body: params, headers: headers))
|
||||
body = resp.body.force_encoding("utf-8")
|
||||
|
||||
if resp.success?
|
||||
json = JSON.parse(resp.body)
|
||||
json = JSON.parse(body)
|
||||
access_token = json["response"]["access_token"]
|
||||
else
|
||||
raise Error.new("Pixiv API access token call failed (status=#{resp.code} body=#{resp.body})")
|
||||
raise Error.new("Pixiv API access token call failed (status=#{resp.code} body=#{body})")
|
||||
end
|
||||
|
||||
access_token
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<% if CurrentUser.user.is_builder? && @exception.present? %>
|
||||
<h1><%= @exception.class.to_s %> exception raised</h1>
|
||||
<ul style="font-family: monospace; font-size: 1.2em; list-style-type: none;">
|
||||
<li><%= @exception.message %></li>
|
||||
<li><%= @exception.message.force_encoding("utf-8") %></li>
|
||||
<%- Rails.backtrace_cleaner.clean(@exception.backtrace).each do |b| -%>
|
||||
<li style="list-style-type: none;"><%= b %></li>
|
||||
<%- end -%>
|
||||
@@ -9,5 +9,5 @@
|
||||
<% elsif @error_message %>
|
||||
<p><%= @error_message %></p>
|
||||
<% else %>
|
||||
<p><%= @exception.message %></p>
|
||||
<p><%= @exception.message.force_encoding("utf-8") %></p>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user