nijie: fix failure to fetch source data due to change in login system.
Nijie changed their login system so that now there are two cookies that need to be remembered: NIJIEIJIEID, and nijie_tok.
This commit is contained in:
@@ -226,13 +226,14 @@ module Sources
|
|||||||
|
|
||||||
def client
|
def client
|
||||||
return nil if cached_session_cookie.nil?
|
return nil if cached_session_cookie.nil?
|
||||||
http.cookies(NIJIEIJIEID: cached_session_cookie, R18: 1)
|
http.cookies(R18: 1, **cached_session_cookie)
|
||||||
end
|
end
|
||||||
|
|
||||||
def http
|
def http
|
||||||
super.timeout(60).use(retriable: { max_retries: 20 })
|
super.timeout(60).use(retriable: { max_retries: 20 })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# { "NIJIEIJIEID" => "5ca3f816c0c1f3e647940b08b8ab7a45", "nijie_tok" => <long-base64-string> }
|
||||||
def cached_session_cookie
|
def cached_session_cookie
|
||||||
Cache.get("nijie-session-cookie", 60.minutes, skip_nil: true) do
|
Cache.get("nijie-session-cookie", 60.minutes, skip_nil: true) do
|
||||||
session_cookie
|
session_cookie
|
||||||
@@ -258,7 +259,7 @@ module Sources
|
|||||||
response = http.post("https://nijie.info/login_int.php", form: form)
|
response = http.post("https://nijie.info/login_int.php", form: form)
|
||||||
|
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
response.cookies.select { |c| c.name == "NIJIEIJIEID" }.compact.first
|
response.cookies.cookies.map { |cookie| [cookie.name, cookie.value] }.to_h
|
||||||
else
|
else
|
||||||
DanbooruLogger.info "Nijie login failed (#{url}, #{response.status})"
|
DanbooruLogger.info "Nijie login failed (#{url}, #{response.status})"
|
||||||
nil
|
nil
|
||||||
|
|||||||
@@ -314,8 +314,8 @@ module Sources
|
|||||||
should "clear the cached cookie after failing to fetch the data" do
|
should "clear the cached cookie after failing to fetch the data" do
|
||||||
site = Sources::Strategies.find("https://nijie.info/view.php?id=203688")
|
site = Sources::Strategies.find("https://nijie.info/view.php?id=203688")
|
||||||
|
|
||||||
Cache.put("nijie-session-cookie", HTTP::Cookie.new(name: "NIJIEIJIEID", value: "fake", domain: "nijie.info", path: "/"))
|
Cache.put("nijie-session-cookie", { "NIJIEIJIEID" => "fake", "nijie_tok" => "fake" })
|
||||||
assert_equal("fake", site.cached_session_cookie.value)
|
assert_equal({ "NIJIEIJIEID" => "fake", "nijie_tok" => "fake" }, site.cached_session_cookie)
|
||||||
|
|
||||||
assert_equal([], site.image_urls)
|
assert_equal([], site.image_urls)
|
||||||
assert_nil(Cache.get("nijie-session-cookie"))
|
assert_nil(Cache.get("nijie-session-cookie"))
|
||||||
|
|||||||
Reference in New Issue
Block a user