Update upload URL for importers

Uploads now generate Markdown like:

![square-abc-640|500x500](upload://md1vKocQHFmG9K4vpC57cKCTQv9.png)

script/import_scripts/base/uploader.rb does this:

    def embedded_image_html(upload)
      image_width = [upload.width, SiteSetting.max_image_width].compact.min
      image_height = [upload.height, SiteSetting.max_image_height].compact.min
      %Q[<img src="#{upload.url}" width="#{image_width}" height="#{image_height}"><br/>]
    end

Should this be updated to use the new format? If so, should it call whatever it is that generates the new format (and if so, where do I find that?) or just do it like

    def embedded_image_html(upload)
      image_width = [upload.width, SiteSetting.max_image_width].compact.min
      image_height = [upload.height, SiteSetting.max_image_height].compact.min
      upload_name = upload.url.split('/').last
      %Q~![#{upload.original_filename}|#{image_width}x#{image_height}](#{upload_name})~
    end

Edit: well, that doesn’t quite work…

Yes, I think it would be a good idea to have that available in Ruby as well. Currently it’s only available in JS.

https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/utilities.js.es6#L363-L364

upload.short_url || upload.url should work :wink:

3 Likes

https://github.com/discourse/discourse/commit/3f167ae5ce71be706c72935e5c76718c14bc020d

4 Likes