Fix #3715: Provide any/none modifiers for pixiv: metatag

This commit is contained in:
evazion
2018-08-22 00:25:38 -05:00
parent 8cc393183e
commit 9a0f37e359
3 changed files with 29 additions and 5 deletions

View File

@@ -122,7 +122,6 @@ class PostQueryBuilder
relation = add_range_relation(q["#{category}_tag_count".to_sym], "posts.tag_count_#{category}", relation) relation = add_range_relation(q["#{category}_tag_count".to_sym], "posts.tag_count_#{category}", relation)
end end
relation = add_range_relation(q[:post_tag_count], "posts.tag_count", relation) relation = add_range_relation(q[:post_tag_count], "posts.tag_count", relation)
relation = add_range_relation(q[:pixiv_id], "posts.pixiv_id", relation)
if q[:md5] if q[:md5]
relation = relation.where(["posts.md5 IN (?)", q[:md5]]) relation = relation.where(["posts.md5 IN (?)", q[:md5]])
@@ -327,6 +326,16 @@ class PostQueryBuilder
relation = relation.where("posts.has_children = TRUE") relation = relation.where("posts.has_children = TRUE")
end end
if q[:pixiv_id]
if q[:pixiv_id] == "any"
relation = relation.where("posts.pixiv_id IS NOT NULL")
elsif q[:pixiv_id] == "none"
relation = relation.where("posts.pixiv_id IS NULL")
else
relation = add_range_relation(q[:pixiv_id], "posts.pixiv_id", relation)
end
end
if q[:rating] =~ /^q/ if q[:rating] =~ /^q/
relation = relation.where("posts.rating = 'q'") relation = relation.where("posts.rating = 'q'")
elsif q[:rating] =~ /^s/ elsif q[:rating] =~ /^s/

View File

@@ -763,7 +763,11 @@ class Tag < ApplicationRecord
q[:filetype_neg] = g2.downcase q[:filetype_neg] = g2.downcase
when "pixiv_id", "pixiv" when "pixiv_id", "pixiv"
q[:pixiv_id] = parse_helper(g2) if g2.downcase == "any" || g2.downcase == "none"
q[:pixiv_id] = g2.downcase
else
q[:pixiv_id] = parse_helper(g2)
end
when "upvote" when "upvote"
if CurrentUser.user.is_moderator? if CurrentUser.user.is_moderator?

View File

@@ -2223,19 +2223,30 @@ class PostTest < ActiveSupport::TestCase
post = FactoryBot.create(:post, :source => url) post = FactoryBot.create(:post, :source => url)
assert_tag_match([post], "pixiv_id:789") assert_tag_match([post], "pixiv_id:789")
end end
should "return posts for a pixiv id search (type 3)" do should "return posts for a pixiv id search (type 3)" do
url = "http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=19113635&page=0" url = "http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=19113635&page=0"
post = FactoryBot.create(:post, :source => url) post = FactoryBot.create(:post, :source => url)
assert_tag_match([post], "pixiv_id:19113635") assert_tag_match([post], "pixiv_id:19113635")
end end
should "return posts for a pixiv id search (type 4)" do should "return posts for a pixiv id search (type 4)" do
url = "http://i2.pixiv.net/img70/img/disappearedstump/34551381_p3.jpg?1364424318" url = "http://i2.pixiv.net/img70/img/disappearedstump/34551381_p3.jpg?1364424318"
post = FactoryBot.create(:post, :source => url) post = FactoryBot.create(:post, :source => url)
assert_tag_match([post], "pixiv_id:34551381") assert_tag_match([post], "pixiv_id:34551381")
end end
should "return posts for a pixiv_id:any search" do
url = "http://i1.pixiv.net/img-original/img/2014/10/02/13/51/23/46304396_p0.png"
post = FactoryBot.create(:post, source: url)
assert_tag_match([post], "pixiv_id:any")
end
should "return posts for a pixiv_id:none search" do
post = FactoryBot.create(:post)
assert_tag_match([post], "pixiv_id:none")
end
# should "return posts for a pixiv novel id search" do # should "return posts for a pixiv novel id search" do
# url = "http://www.pixiv.net/novel/show.php?id=2156088" # url = "http://www.pixiv.net/novel/show.php?id=2156088"
# post = FactoryBot.create(:post, :source => url) # post = FactoryBot.create(:post, :source => url)