Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable media preview #3983

Merged
merged 1 commit into from
Jul 27, 2020
Merged

Add option to disable media preview #3983

merged 1 commit into from
Jul 27, 2020

Conversation

dalcde
Copy link
Contributor

@dalcde dalcde commented Jul 12, 2020

This disables image previews iff prefetchStorage is disabled. This
stops the client from making any requests to third-party sites.

The change is backwards comaptible. Existing config files will have
disableMediaPreview set to undefined, which is functionally equivalent
to false.

Help wih setting up tests would be appreciated. I couldn't figure out how to
test that a preview is not displayed.

@xPaw
Copy link
Member

xPaw commented Jul 12, 2020

I think parseHtmlMedia should always resolve to false with this option so that HTML pages will still show a description, instead of no preview at all.

And for direct media, not sure why do the http request too, if it won't be displayed, the request could be avoided in the first place. Same for thumbnails from html.
EDIT: Although we would still want to display link size?

Existing config files will have
disableMediaPreview set to undefined, which is functionally equivalent
to false.

TL falls back to default config for missing keys, FYI.

@dalcde
Copy link
Contributor Author

dalcde commented Jul 12, 2020 via email

@xPaw xPaw requested a review from a team July 12, 2020 08:43
@xPaw xPaw added the Type: Feature Tickets that describe a desired feature or PRs that add them to the project. label Jul 12, 2020
@xPaw
Copy link
Member

xPaw commented Jul 12, 2020

Can you add tests for this?

@dalcde
Copy link
Contributor Author

dalcde commented Jul 12, 2020 via email

@xPaw
Copy link
Member

xPaw commented Jul 12, 2020

You can still test things like not picking videos from html.

@dalcde
Copy link
Contributor Author

dalcde commented Jul 18, 2020 via email

@xPaw
Copy link
Member

xPaw commented Jul 18, 2020

You can group that test with describe and then use before and after to correctly reset it: https://stackoverflow.com/a/37897703

I also would like to see more tests like a direct link to image where it should not produce an image thumbnail, but still return the image size.

@dalcde
Copy link
Contributor Author

dalcde commented Jul 18, 2020 via email

@xPaw
Copy link
Member

xPaw commented Jul 19, 2020

I don't see anything changed.

@dalcde
Copy link
Contributor Author

dalcde commented Jul 19, 2020 via email

@@ -222,6 +222,40 @@ Vivamus bibendum vulputate tincidunt. Sed vitae ligula felis.`;
});
});

describe("test disableMediaPreview", function () {
beforeEach(function (done) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need done as there is nothing async. Same in afterEach.

@xPaw
Copy link
Member

xPaw commented Jul 19, 2020

"I also would like to see more tests like a direct link to image where it should not produce an image thumbnail, but still return the image size."

Can you add more tests please?

@dalcde
Copy link
Contributor Author

dalcde commented Jul 20, 2020 via email

@xPaw
Copy link
Member

xPaw commented Jul 20, 2020

Ah yeah you're right that we can't do that. In that case we can avoid the image thumbnail request here:

// Verify that thumbnail pic exists and is under allowed size
if (thumb.length) {

As it will be dropped later on anyway. Again, I would like to see tests for it (e.g. to see that msg:preview triggered, but thumbnail url was NOT visited).

@dalcde
Copy link
Contributor Author

dalcde commented Jul 20, 2020 via email

@xPaw
Copy link
Member

xPaw commented Jul 20, 2020

Thanks, that looks better now. Did you test that throw actually works there? I was thinking of tracking a bool there instead. But if throw works, that's fine too.

I would like to see tests for direct image/video links too (without html), for that you would need get routes that return correct content-type though.

That way we can also verify that direct links do not generate previews. Not sure how we would track removePreview calls though, since it won't emit a preview event.

Sorry if I'm being catious/annoying, I just want the link prefetch code to be test covered to avoid any problems in the future.

@dalcde
Copy link
Contributor Author

dalcde commented Jul 21, 2020 via email

This disables image previews iff prefetchStorage is disabled. This
stops the client from making any requests to third-party sites.
@xPaw
Copy link
Member

xPaw commented Jul 21, 2020

There's a /real-test-image.png route available for all tests that you can use.

For videos and images, you can set the type in express route, something like this: https://stackoverflow.com/questions/51661744/how-to-set-content-type-when-doing-res-send/51661772

@dalcde
Copy link
Contributor Author

dalcde commented Jul 21, 2020 via email

@xPaw
Copy link
Member

xPaw commented Jul 21, 2020

Yeah that is a bit tricky. One solution I can imagine working is creating a Proxy on message.previews and the first change to the array would be type loading as link prefetcher discovers the link, and the second one would be the array emptying as it get removed.

@xPaw xPaw added this to the 4.2.0 milestone Jul 27, 2020
@xPaw xPaw merged commit ec65fd1 into thelounge:master Jul 27, 2020
@xPaw xPaw changed the title Add option to disable media preview. Add option to disable media preview Jul 27, 2020
@dalcde dalcde deleted the audio branch July 27, 2020 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Tickets that describe a desired feature or PRs that add them to the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants