posts: automatically add the bad_link and bad_source tags.
Automatically add the bad_link tag when the source is an image url from a known site, but it can't be converted to a page url (for example, a Twitter or Tumblr direct image link). Automatically add the bad_source tag when the source is from a known site, but it's not an image or page url (for example, a Twitter or Pixiv profile url)
This commit is contained in:
@@ -9,6 +9,14 @@
|
||||
# To add a new site, create a subclass of Source::URL and implement `#match?` to define
|
||||
# which URLs belong to the site, and `#parse` to parse and extract information from the URL.
|
||||
#
|
||||
# The following methods should be implemented by subclasses:
|
||||
#
|
||||
# * match?
|
||||
# * parse
|
||||
# * image_url?
|
||||
# * page_url
|
||||
# * profile_url
|
||||
#
|
||||
# Source::URL is a subclass of Danbooru::URL, so it inherits some common utility methods
|
||||
# from there.
|
||||
#
|
||||
@@ -87,6 +95,13 @@ module Source
|
||||
self.class.name.demodulize.titleize
|
||||
end
|
||||
|
||||
# True if the URL is from a recognized site. False if the URL is from an unrecognized site.
|
||||
#
|
||||
# @return [Boolean]
|
||||
def recognized?
|
||||
true # overridden in Source::URL::Null to return false for unknown sites
|
||||
end
|
||||
|
||||
# True if the URL is a direct image URL.
|
||||
#
|
||||
# Examples:
|
||||
|
||||
@@ -38,6 +38,8 @@ class Source::URL::Null < Source::URL
|
||||
end
|
||||
|
||||
def parse
|
||||
@recognized = true
|
||||
|
||||
case [subdomain, domain, *path_segments]
|
||||
|
||||
# http://about.me/rig22
|
||||
@@ -240,7 +242,12 @@ class Source::URL::Null < Source::URL
|
||||
@page_url = "https://www.zerochan.net/#{@work_id}#full"
|
||||
|
||||
else
|
||||
nil
|
||||
@recognized = false
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def recognized?
|
||||
@recognized
|
||||
end
|
||||
end
|
||||
|
||||
@@ -430,6 +430,23 @@ class Post < ApplicationRecord
|
||||
tags << "non-web_source"
|
||||
end
|
||||
|
||||
source_url = parsed_source
|
||||
if source_url.present? && source_url.recognized?
|
||||
# A bad_link is an image URL from a recognized site that can't be converted to a page URL.
|
||||
if source_url.image_url? && source_url.page_url.nil?
|
||||
tags << "bad_link"
|
||||
else
|
||||
tags -= ["bad_link"]
|
||||
end
|
||||
|
||||
# A bad_source is a source from a recognized site that isn't an image url or a page url.
|
||||
if !source_url.image_url? && !source_url.page_url?
|
||||
tags << "bad_source"
|
||||
else
|
||||
tags -= ["bad_source"]
|
||||
end
|
||||
end
|
||||
|
||||
# Allow only Flash files to be manually tagged as `animated`; GIFs, PNGs, videos, and ugoiras are automatically tagged.
|
||||
tags -= ["animated"] unless is_flash?
|
||||
tags << "animated" if media_asset.is_animated?
|
||||
|
||||
Reference in New Issue
Block a user