sources: remove canonical_url method.

Refactor source strategies to remove the `canonical_url` method.

`canonical_url` returned the URL that should be used as the source of
the post after upload. Now we simply use `Source::URL#page_url` to
determine the source after upload. If the source is an image URL that is
convertible to a page URL, then the image URL is used as the source. If
the source is an image URL that is not convertible to a page URL, then
the page URL is used as the source.

This simplifies source strategies so that all they have to care about is
implementing the `Source::URL#page_url` and `Sources::Strategies#page_url`
methods, and the preferred source will be chosen for posts automatically.
This commit is contained in:
evazion
2022-03-23 20:47:17 -05:00
parent eef6e8f55f
commit 4ef8178bd1
29 changed files with 88 additions and 130 deletions

View File

@@ -88,6 +88,9 @@ module Source
# When viewing a post, the source will be shown as the page URL if it's
# possible to convert the source from an image URL to a page URL.
#
# When uploading a post, the source will be set to the image URL if the
# image URL is convertible to a page URL. Otherwise, it's set to the page URL.
#
# Examples:
#
# * https://i.pximg.net/img-original/img/2014/10/03/18/10/20/46324488_p0.png

View File

@@ -103,7 +103,6 @@ class Source::URL::Moebooru < Source::URL
filename_prefix = "Konachan.com%20-%20"
end
# try to include the post_id so that it's saved for posterity in the canonical_url.
if post_id.present?
"https://#{file_host}/image/#{md5}/#{filename_prefix}#{post_id}.#{file_ext}"
else