Add setting to disable hotlinking of large image files

Hi @vinothkannans hoping its all going well, let us know if you are stuck on anything.

I tried to overlay broken chain icon on broken pictures. Now browser still returns mixed content warnings. We have to replace original image url with our broken chain image in post raw. So I have idea like below

Lorem Ipsum is simply dummy text of the printing and typesetting industry.
![](http://external-site1.com/some-broken-url.jpg)
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
<img src="http://external-site2.com/very-large-image-url.jpg">
When an unknown printer took a galley of type and scrambled it to make a type specimen book.

Let assume above is original post raw. Then I think we can replace it like below

Lorem Ipsum is simply dummy text of the printing and typesetting industry.
![](https://meta.discourse.org/broken-image-placeholder.jpg)
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
<img src="http://meta.discourse.org/general-placeholder.jpg">
When an unknown printer took a galley of type and scrambled it to make a type specimen book.

<!---
Broken images:
 http://external-site1.com/some-broken-url.jpg

Large images:
 http://external-site2.com/very-large-image-url.jpg
-->

Is it ok to add comments like this in post raw?

bump. just reminding @sam.

Yeah I had it bookmarked was about to reply :slight_smile:

Let’s go through the workflow:

Someone adds an image, which somehow renders an image tag into the post, like this:

<img src='//assets-meta-cdck-prod-meta.s3.dualstack.us-west-1.amazonaws.com/original/3X/b/5/b52b10868d97bc52fa87e954705d2ff61acbb2d8.jpg' width="695" height="590" title="Gilded Flicker (Colaptes chrysoides)">

Our cooked post processor then download the image locally per earlier code.

If there are “problems” it replaces the image with a magic “span” that we can style.

<span class='broken-image'></span>

or if image is too big

<a href='original image' class='large-image'><span></span><a>

Not following why you need any magic comments here. It can be broken in the post temporarily till the post processor runs.

5 Likes

Good idea.

Yes it will be broken until post processor. After post process broken image url will removed fully. So the user can’t see it again to correct it. In that point of view I added comments. If it is not necessary we can skip it.

I don’t see why end users need to know the url of the broken image, the author can always get to it by looking in the markdown. If we must get all fancy you could make a tooltip or something.

1 Like

2 Beiträge wurden in ein neues Thema verschoben: System user replaces wrong URL when it downloads local copy of image

Why? From where is it removed fully?
It’s still in raw, isn’t it? I guess what @sam is saying is that the span for “too large” or “broken image” should only be in cooked. At least that’s how I’m reading it.

1 Like

No. It is markdown comment only. It won’t visible to end users. I thought broken urls going to be replaced in markdown itself (since we are doing like that for other urls). Now no problem since we are going to replace it only on cooked html :+1:

1 Like

Yes this is only the case for cooked html and is only applied via post processor. No mucking with raw please.

2 Likes

Yes it going to be replaced only in cookied html. I was wrongly understood. Please bear with my understanding level in english :slight_smile:

1 Like

I think there is a use case for keeping an anchor tag of the broken image in the page. Say there is an image that can only be viewed by users who are authenticated on a certain website. When they post it on Discourse, it may throw an error and not display, but we still want to have <a href that links to the image, even if we don’t embed it in the page.

2 Likes

May be in that case it is better if you link it instead of embedding the image directly.

2 Likes

Aren’t images automatically embedded if you post the URL?

I pasted an image URL into this post without any other actions.


And it appears embedded. Now I post an invalid image URL

Imgur

It appears as a link.

This is literally covered in the topic of the title, if the image is very large (imagine a 1 gigabyte image) it won’t be downloaded to your local instance.

Since we not changing the raw post I am unable to store which are the images broken or bigger size.

We are detecting broken & bigger images in pull_hotlinked_images job. There we only editing raw post and triggering the cooked post_processor job. Currently no way to send list of images should replace with placeholder to cooking process. Even if I try to cook in pull_hotlinked_images job itself or try to send list of images to post_processor job then again it will become problem when the post is recooked in future.

Can you please guide me to fix this problem?

I can live with a 5 minute delay here.

PullHotlinkedImages is guaranteed to run every time after cooked post processor. It queues it.

So just have PullHotlinkedImages edit the “cooked” value direct on the post.

4 Likes

Great idea. Thank you :+1:

https://github.com/discourse/discourse/pull/5113

Travis failed for some other reason.

4 Likes

Now it is merged. Broken and large images will be replaced with placeholders.

2 Likes