需要上传图像的相对URL

How can I get Discourse to generate relative URLs for uploaded images?

I have a site that is available over HTTPS and a TOR .onion and I need a way to get images working for both.

How can I configure Discourse so that upload:// URLs are converted to relative URLs in the <img> tag? Where (which source file) does this URL generation take place?

I don’t think relative image URLs is a supported configuration, and that might be a very difficult change cc @sam

1 个赞

Just to clarify:

Uploading works correctly both from the HTTPS domain and the TOR hidden service .onion but the actual HTML generated for a post uses a full URL which is a problem.

I’m assuming somewhere there is some code that does something like

 '<img src="' + Discourse.base_url_no_prefix + '/uploads/....jpg' + '">'

and I need it to generate

 '<img src="' + '/uploads/....jpg' + '">'

Would playing with absolute_without_cdn be too low-level and affect too many things?

The URL needs to be relative because:

  • A normal browser cannot access the .onion URL.
  • Cannot access the normal site over TOR because it is behind DDoS protection. And even if it worked, I don’t want to leak details to TOR exit nodes.
1 个赞

This would require some internal changes, I am somewhat sympathetic cause it makes life a bit easier when changing domain names for sites that do not use A CDN.

Would have to be something like, IF no CDN configured then cook a relative url.

3 个赞

I assume you only need to set this up when the configuration is changed?

Imagine having

'<img src="' + Discourse.cdn_url_no_prefix + '/uploads/....jpg' + '">'

When there is no CDN configured then Discourse.cdn_url_no_prefix can simply be a empty string.

Does that mean that there is a chance you can implement this in the (near) future?

Just to add a voice and to agree with @sam, we’ve already had some switcheroos with our domains and relative URLs is most certainly needed.

我支持使用相对内部链接。目前,我使用完整 URL 来引用同一站点上的其他主题。

事实上,我们的网站最近更换了域名(请注意,当前重定向已生效):

我们的新主机 Communiteq(原 DiscourseHosting)以某种方式 sed 了我们的数据库,以反映这一变更。

当前状态是否有技术原因?未来我们是否可以使用类似 %{THIS}/t/000 的方式?作为一名开发者,绝对路径通常让我感到不安。此外,我们在此次迁移过程中(或至少更严格地执行了)从 http: 切换到 https: 的问题也与此相关。这看起来与 @mreach 提到的用例非常相似。

一如既往,非常感谢 Discourse 团队提供如此出色的产品。R.

1 个赞

当域名变更时,对所有受影响的帖子执行一次针对性的搜索和替换通常不是什么大问题。

1 个赞