diff --git a/app/logical/sources/strategies/deviant_art.rb b/app/logical/sources/strategies/deviant_art.rb index bec7e3556..6bf4b7767 100644 --- a/app/logical/sources/strategies/deviant_art.rb +++ b/app/logical/sources/strategies/deviant_art.rb @@ -120,21 +120,23 @@ module Sources mech = Mechanize.new auth, userinfo = session_cookies(mech) - # This cookie needs to be set to allow viewing of mature works - cookie = Mechanize::Cookie.new("agegate_state", "1") - cookie.domain = ".deviantart.com" - cookie.path = "/" - mech.cookie_jar.add(cookie) + if auth + # This cookie needs to be set to allow viewing of mature works + cookie = Mechanize::Cookie.new("agegate_state", "1") + cookie.domain = ".deviantart.com" + cookie.path = "/" + mech.cookie_jar.add(cookie) - cookie = Mechanize::Cookie.new("auth", auth) - cookie.domain = ".deviantart.com" - cookie.path = "/" - mech.cookie_jar.add(cookie) + cookie = Mechanize::Cookie.new("auth", auth) + cookie.domain = ".deviantart.com" + cookie.path = "/" + mech.cookie_jar.add(cookie) - cookie = Mechanize::Cookie.new("userinfo", userinfo) - cookie.domain = ".deviantart.com" - cookie.path = "/" - mech.cookie_jar.add(cookie) + cookie = Mechanize::Cookie.new("userinfo", userinfo) + cookie.domain = ".deviantart.com" + cookie.path = "/" + mech.cookie_jar.add(cookie) + end mech end @@ -145,6 +147,12 @@ module Sources mech.request_headers = Danbooru.config.http_headers page = mech.get("https://www.deviantart.com/users/login") + + if page.search('div[class="g-recaptcha"]').any? + # we got captcha'd, have to abort + return nil + end + validate_key = page.search('input[name="validate_key"]').attribute("value").value validate_token = page.search('input[name="validate_token"]').attribute("value").value @@ -156,8 +164,8 @@ module Sources remember_me: 1, }) - auth = mech.cookies.find { |cookie| cookie.name == "auth" }.value - userinfo = mech.cookies.find { |cookie| cookie.name == "userinfo" }.value + auth = mech.cookies.find { |cookie| cookie.name == "auth" }.try(:value) + userinfo = mech.cookies.find { |cookie| cookie.name == "userinfo" }.try(:value) mech.cookie_jar.clear [auth, userinfo] diff --git a/app/models/post.rb b/app/models/post.rb index e269e48ba..f9e1258f4 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1367,7 +1367,7 @@ class Post < ApplicationRecord transaction do Post.without_timeout do ModAction.log("permanently deleted post ##{id}") - delete!("Permanently deleted post ##{id}", :without_mod_action => true) + #delete!("Permanently deleted post ##{id}", :without_mod_action => true) give_favorites_to_parent update_children_on_destroy diff --git a/test/unit/sources/deviantart_test.rb b/test/unit/sources/deviantart_test.rb index a28305057..95b7640c3 100644 --- a/test/unit/sources/deviantart_test.rb +++ b/test/unit/sources/deviantart_test.rb @@ -9,11 +9,11 @@ module Sources end should "get the image url" do - assert_equal("http://orig02.deviantart.net/7b5b/f/2017/160/c/5/test_post_please_ignore_by_noizave-dbc3a48.png", @site.image_url) + assert_equal("https://orig02.deviantart.net/7b5b/f/2017/160/c/5/test_post_please_ignore_by_noizave-dbc3a48.png", @site.image_url) end should "get the profile" do - assert_equal("http://noizave.deviantart.com/", @site.profile_url) + assert_equal("https://noizave.deviantart.com/", @site.profile_url) end should "get the artist name" do @@ -26,7 +26,7 @@ module Sources should "get the artist commentary" do title = "test post please ignore" - desc = "
this is a quote\n
this is a quote\n