FIX: always store topic links using the upload url
This commit is contained in:
parent
47bed23a5f
commit
bf4d98e89d
|
@ -136,7 +136,8 @@ SQL
|
||||||
topic_id = nil
|
topic_id = nil
|
||||||
post_number = nil
|
post_number = nil
|
||||||
|
|
||||||
if Discourse.store.has_been_uploaded?(url)
|
if upload = Upload.get_from_url(url)
|
||||||
|
url = upload.url
|
||||||
internal = Discourse.store.internal?
|
internal = Discourse.store.internal?
|
||||||
elsif route = Discourse.route_for(parsed)
|
elsif route = Discourse.route_for(parsed)
|
||||||
internal = true
|
internal = true
|
||||||
|
|
|
@ -77,28 +77,17 @@ class Upload < ActiveRecord::Base
|
||||||
|
|
||||||
def self.get_from_url(url)
|
def self.get_from_url(url)
|
||||||
return if url.blank?
|
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 = begin
|
||||||
URI(URI.unescape(url))
|
URI(URI.unescape(url))
|
||||||
rescue URI::InvalidURIError, URI::InvalidComponentError
|
rescue URI::InvalidURIError, URI::InvalidComponentError
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def self.migrate_to_new_scheme(limit = nil)
|
def self.migrate_to_new_scheme(limit = nil)
|
||||||
|
|
|
@ -41,10 +41,10 @@ describe CookedPostProcessor do
|
||||||
end
|
end
|
||||||
|
|
||||||
context ".keep_reverse_index_up_to_date" do
|
context ".keep_reverse_index_up_to_date" do
|
||||||
let(:video_upload) { Fabricate(:upload, url: '/uploads/default/1/1234567890123456.mp4') }
|
let(:video_upload) { Fabricate(:upload, url: '/uploads/default/original/1X/1/1234567890123456.mp4') }
|
||||||
let(:image_upload) { Fabricate(:upload, url: '/uploads/default/1/1234567890123456.jpg') }
|
let(:image_upload) { Fabricate(:upload, url: '/uploads/default/original/1X/1/1234567890123456.jpg') }
|
||||||
let(:audio_upload) { Fabricate(:upload, url: '/uploads/default/1/1234567890123456.ogg') }
|
let(:audio_upload) { Fabricate(:upload, url: '/uploads/default/original/1X/1/1234567890123456.ogg') }
|
||||||
let(:attachment_upload) { Fabricate(:upload, url: '/uploads/default/1/1234567890123456.csv') }
|
let(:attachment_upload) { Fabricate(:upload, url: '/uploads/default/original/1X/1/1234567890123456.csv') }
|
||||||
|
|
||||||
let(:raw) do
|
let(:raw) do
|
||||||
<<~RAW
|
<<~RAW
|
||||||
|
|
Loading…
Reference in New Issue