Refactor Post#parse_pixiv_id to use illust_id_from_url (fix #2695).

* Make illust_id_from_url a public class method instead of a protected
  instance method so that Post#parse_pixiv_id can use it.
* Also make illust_id_from_url swallow the exception that
  illust_id_from_url! throws so that parse_pixiv_id can use it.
This commit is contained in:
evazion
2016-10-03 01:29:19 +00:00
parent f4f85bd0d8
commit d38e83cd00
2 changed files with 48 additions and 54 deletions

View File

@@ -1644,23 +1644,7 @@ class Post < ActiveRecord::Base
module PixivMethods
def parse_pixiv_id
if source =~ %r!http://i\d\.pixiv\.net/img-inf/img/\d+/\d+/\d+/\d+/\d+/\d+/(\d+)_s.jpg!
self.pixiv_id = $1
elsif source =~ %r!http://img\d+\.pixiv\.net/img/[^\/]+/(\d+)!
self.pixiv_id = $1
elsif source =~ %r!http://i\d\.pixiv\.net/img\d+/img/[^\/]+/(\d+)!
self.pixiv_id = $1
elsif source =~ %r!http://i\d\.pixiv\.net/img-original/img/(?:\d+\/)+(\d+)_p!
self.pixiv_id = $1
elsif source =~ %r!http://i\d\.pixiv\.net/c/\d+x\d+/img-master/img/(?:\d+\/)+(\d+)_p!
self.pixiv_id = $1
elsif source =~ /pixiv\.net/ && source =~ /illust_id=(\d+)/
self.pixiv_id = $1
elsif source =~ %r!http://i\d\.pixiv\.net/img-zip-ugoira/img/(?:\d+\/)+(\d+)_ugoira!
self.pixiv_id = $1
else
self.pixiv_id = nil
end
self.pixiv_id = Sources::Strategies::Pixiv.illust_id_from_url(source)
end
end