mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: always store topic links using the upload url
This commit is contained in:
@@ -77,28 +77,17 @@ class Upload < ActiveRecord::Base
|
||||
|
||||
def self.get_from_url(url)
|
||||
return if url.blank?
|
||||
# we store relative urls, so we need to remove any host/cdn
|
||||
url = url.sub(Discourse.asset_host, "") if Discourse.asset_host.present? && Discourse.asset_host != SiteSetting.Upload.s3_cdn_url
|
||||
# when using s3 without CDN
|
||||
url = url.sub(/^https?\:/, "") if url.include?(Discourse.store.absolute_base_url) && Discourse.store.external?
|
||||
|
||||
# when using s3, we need to replace with the absolute base url
|
||||
if SiteSetting.Upload.s3_cdn_url.present?
|
||||
url = url.sub(
|
||||
SiteSetting.Upload.s3_cdn_url,
|
||||
SiteSetting.Upload.s3_base_url
|
||||
)
|
||||
end
|
||||
|
||||
# always try to get the path
|
||||
uri = begin
|
||||
URI(URI.unescape(url))
|
||||
rescue URI::InvalidURIError, URI::InvalidComponentError
|
||||
end
|
||||
|
||||
url = uri.path if uri.try(:scheme)
|
||||
return if uri&.path.blank?
|
||||
|
||||
Upload.find_by(url: url)
|
||||
path = uri.path[/(\/original\/\dX\/[\/\.\w]+)/, 1]
|
||||
|
||||
Upload.find_by("url LIKE ?", "%#{path}")
|
||||
end
|
||||
|
||||
def self.migrate_to_new_scheme(limit = nil)
|
||||
|
||||
Reference in New Issue
Block a user