moebooru: rewrite konachan urls for Post#normalized_source (#3911).

This commit is contained in:
evazion
2018-10-06 00:58:22 -05:00
parent 864349dc7b
commit fdb6e4ecee
2 changed files with 20 additions and 1 deletions

View File

@@ -507,6 +507,12 @@ class Post < ApplicationRecord
when %r{\Ahttps?://(?:[^.]+\.)?yande\.re/(?:image|jpeg|sample)/(?<md5>\h{32})(?:/yande\.re.*|/?\.(?:jpg|png))\z}i
"https://yande.re/post?tags=md5:#{$~[:md5]}"
when %r{\Ahttps?://(?:[^.]+\.)?konachan\.com/(?:image|jpeg|sample)/\h{32}/Konachan\.com%20-%20(?<post_id>\d+)}i
"https://konachan.com/post/show/#{$~[:post_id]}"
when %r{\Ahttps?://(?:[^.]+\.)?konachan\.com/(?:image|jpeg|sample)/(?<md5>\h{32})(?:/Konachan\.com%20-%20.*|/?\.(?:jpg|png))\z}i
"https://konachan.com/post?tags=md5:#{$~[:md5]}"
# https://gfee_li.artstation.com/projects/XPGOD
# https://gfee_li.artstation.com/projects/asuka-7
when %r{\Ahttps?://\w+\.artstation.com/(?:artwork|projects)/(?<project_id>[a-z0-9-]+)\z/}i

View File

@@ -97,7 +97,7 @@ module Sources
end
context "Post#normalized_source" do
should "convert image urls to post urls" do
should "convert yande.re image urls to post urls" do
@post = FactoryBot.build(:post)
@post.source = "https://files.yande.re/image/b66909b940e8d77accab7c9b25aa4dc3/yande.re%20377828.png"
@@ -112,6 +112,19 @@ module Sources
@post.source = "https://yande.re/jpeg/22577d2344fe694cf47f80563031b3cd.jpg"
assert_equal("https://yande.re/post?tags=md5:22577d2344fe694cf47f80563031b3cd", @post.normalized_source)
end
should "convert konachan.com image urls to post urls" do
@post = FactoryBot.build(:post)
@post.source = "https://konachan.com/image/5d633771614e4bf5c17df19a0f0f333f/Konachan.com%20-%20270807%20black_hair%20bokuden%20clouds%20grass%20landscape%20long_hair%20original%20phone%20rope%20scenic%20seifuku%20skirt%20sky%20summer%20torii%20tree.jpg"
assert_equal("https://konachan.com/post/show/270807", @post.normalized_source)
@post.source = "https://konachan.com/sample/e2e2994bae738ff52fff7f4f50b069d5/Konachan.com%20-%20270803%20sample.jpg"
assert_equal("https://konachan.com/post/show/270803", @post.normalized_source)
@post.source = "https://konachan.com/image/99a3c4f10c327d54486259a74173fc0b.jpg"
assert_equal("https://konachan.com/post?tags=md5:99a3c4f10c327d54486259a74173fc0b", @post.normalized_source)
end
end
end
end