diff --git a/app/logical/pixiv_api_client.rb b/app/logical/pixiv_api_client.rb index 905b638f7..a4f0fcabe 100644 --- a/app/logical/pixiv_api_client.rb +++ b/app/logical/pixiv_api_client.rb @@ -154,6 +154,9 @@ class PixivApiClient else raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})") end + rescue Net::OpenTimeout + sleep(5) + retry rescue JSON::ParserError raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})") end @@ -173,7 +176,7 @@ class PixivApiClient } url = "https://oauth.secure.pixiv.net/auth/token" - resp = HTTParty.post(url, Danbooru.config.httparty_options.deep_merge(timeout: 20, body: params, headers: headers)) + resp = HTTParty.post(url, Danbooru.config.httparty_options.deep_merge(body: params, headers: headers)) body = resp.body.force_encoding("utf-8") if resp.success? diff --git a/config/docker/compose.yml b/config/docker/compose.yml index 3a50c601d..1d8e70b10 100644 --- a/config/docker/compose.yml +++ b/config/docker/compose.yml @@ -48,6 +48,7 @@ services: - DANBOORU_NIJIE_PASSWORD - DANBOORU_NICO_SEIGA_LOGIN - DANBOORU_NICO_SEIGA_PASSWORD + - DANBOORU_PERSIST_PIXIV_SESSION build: context: ../.. dockerfile: config/docker/danbooru-ci diff --git a/test/test_helper.rb b/test/test_helper.rb index 192c92a22..dbb02c4ff 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -44,6 +44,22 @@ module TestHelpers def as_admin(&block) CurrentUser.as_admin(&block) end + + def load_pixiv_tokens! + if ENV["DANBOORU_PERSIST_PIXIV_SESSION"] && Cache.get("pixiv-papi-access-token") + Cache.put("pixiv-papi-access-token", Thread.current[:pixiv_papi_access_token]) + Cache.put(PixivWebAgent::SESSION_CACHE_KEY, Thread.current[:pixiv_session_cache_key]) + Cache.put(PixivWebAgent::COMIC_SESSION_CACHE_KEY, Thread.current[:pixiv_comic_session_cache_key]) + end + end + + def save_pixiv_tokens! + if ENV["DANBOORU_PERSIST_PIXIV_SESSION"] + Thread.current[:pixiv_papi_access_token] = Cache.get("pixiv-papi-access-token") + Thread.current[:pixiv_session_cache_key] = Cache.get(PixivWebAgent::SESSION_CACHE_KEY) + Thread.current[:pixiv_comic_session_cache_key] = Cache.get(PixivWebAgent::COMIC_SESSION_CACHE_KEY) + end + end end diff --git a/test/unit/downloads/pixiv_test.rb b/test/unit/downloads/pixiv_test.rb index 54f4161ff..5c2f211b6 100644 --- a/test/unit/downloads/pixiv_test.rb +++ b/test/unit/downloads/pixiv_test.rb @@ -2,6 +2,16 @@ require 'test_helper' module Downloads class PixivTest < ActiveSupport::TestCase + def setup + super + load_pixiv_tokens! + end + + def teardown + save_pixiv_tokens! + super + end + context "An ugoira site for pixiv" do setup do @download = Downloads::File.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364") diff --git a/test/unit/sources/pixiv_test.rb b/test/unit/sources/pixiv_test.rb index a2ba1a350..e9e61ee3a 100644 --- a/test/unit/sources/pixiv_test.rb +++ b/test/unit/sources/pixiv_test.rb @@ -8,6 +8,16 @@ module Sources @site end + def setup + super + load_pixiv_tokens! + end + + def teardown + save_pixiv_tokens! + super + end + context "in all cases" do context "A touch page" do setup do