Besoin d'URL relatives pour les images téléchargées

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 « J'aime »

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 « J'aime »

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 « J'aime »

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.

J’aimerais apporter mon soutien en faveur des liens internes relatifs. Je utilise actuellement des URLs complètes pour faire référence, par exemple, à un autre sujet sur le même site.

En effet, notre site a récemment changé de domaine (en notant que la redirection est actuellement active) :

Et notre nouvel hébergeur, Communiteq (anciennement DiscourseHosting), a gentiment et somehow sédifié notre base de données pour refléter ce changement.

Y a-t-il peut-être des raisons techniques pour l’état actuel ? Pourrions-nous utiliser quelque chose comme %{THIS}/t/000 à l’avenir ? En tant que développeur, les chemins absolus me rendent généralement nerveux. Il y a aussi la question du passage de http: à https:, ce que nous avons également entrepris (ou du moins appliqué plus strictement) dans le cadre de la migration susmentionnée. Cela ressemble beaucoup au même cas d’usage que @mreach

Comme toujours, un grand merci à l’équipe Discourse pour ce merveilleux produit. R.

1 « J'aime »

Ce n’est généralement pas un gros problème d’exécuter une recherche et remplacement ciblé sur tous les messages concernés lors d’un changement de domaine.

1 « J'aime »