DEV: Support both `http` and `https` for `InlineUploads`.

approved
#1

DEV: Support both http and https for InlineUploads.

diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb
index 7d80fb8..772fe9c 100644
--- a/app/services/inline_uploads.rb
+++ b/app/services/inline_uploads.rb
@@ -241,10 +241,12 @@ class InlineUploads
   def self.matched_uploads(node)
     matches = []
 
+    base_url = Discourse.base_url.sub(/https?:\/\//, "(https?://)")
+
     regexps = [
       /(upload:\/\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
       /(\/uploads\/short-url\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
-      /(#{Discourse.base_url}\/uploads\/short-url\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
+      /(#{base_url}\/uploads\/short-url\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
     ]
 
     db = RailsMultisite::ConnectionManagement.current_db
@@ -257,11 +259,11 @@ class InlineUploads
         regexps << /((https?:)?#{SiteSetting.Upload.s3_base_url}#{UPLOAD_REGEXP_PATTERN})/
         regexps << /(#{SiteSetting.Upload.s3_cdn_url}#{UPLOAD_REGEXP_PATTERN})/
         regexps << /(\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
-        regexps << /(#{Discourse.base_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
+        regexps << /(#{base_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
       end
     else
       regexps << /(\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
-      regexps << /(#{Discourse.base_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
+      regexps << /(#{base_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
     end
 
     node = node.to_s
diff --git a/spec/services/inline_uploads_spec.rb b/spec/services/inline_uploads_spec.rb
index 13e8c53..a89d8a2 100644
--- a/spec/services/inline_uploads_spec.rb
+++ b/spec/services/inline_uploads_spec.rb
@@ -190,7 +190,7 @@ RSpec.describe InlineUploads do
         <img src="#{upload.url}">
 
         [1]: #{Discourse.base_url}#{upload.url}
-        [2]: #{Discourse.base_url}#{upload2.url}
+        [2]: #{Discourse.base_url.sub("http://", "https://")}#{upload2.url}
         MD
 
         expect(InlineUploads.process(md)).to eq(<<~MD)

GitHub sha: 41abebcb

1 Like
Approved #2