-
Notifications
You must be signed in to change notification settings - Fork 680
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
Conversation
I think 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.
TL falls back to default config for missing keys, FYI. |
Updated. Thanks!
|
Can you add tests for this? |
I'm not sure how to do this. A "loading" preview exists by default and then is removed asynchronously. Checking if the preview still exists after a timeout seems prone to errors.
|
You can still test things like not picking videos from html. |
I've added a test, but I'm not a huge fan of this. It modifies the
global config object, which has to be restored at the end of the test.
This seems pretty prone to errors in the future.
|
You can group that test with 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. |
Done!
|
I don't see anything changed. |
Sorry forgot to push!
|
@@ -222,6 +222,40 @@ Vivamus bibendum vulputate tincidunt. Sed vitae ligula felis.`; | |||
}); | |||
}); | |||
|
|||
describe("test disableMediaPreview", function () { | |||
beforeEach(function (done) { |
There was a problem hiding this comment.
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
.
"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? |
On Sun, Jul 19, 2020 at 08:16:22AM -0700, Pavel Djundik wrote:
"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."
At the moment this does not happen. It appears that the image size comes
as part of the preview. If I don't return a preview, there will be no
accompanied size. How would I achieve this?
|
Ah yeah you're right that we can't do that. In that case we can avoid the image thumbnail request here: thelounge/src/plugins/irc-events/link.js Lines 106 to 107 in b770c33
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). |
I added the test, and added a similar test for videos.
|
Thanks, that looks better now. Did you test that 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 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. |
On Mon, Jul 20, 2020 at 09:18:28AM -0700, Pavel Djundik wrote:
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.
Throw actually works. After all, our expect calls just throw when the
unexpected happens
(we end up getting a Timeout instead of an assertion failure, both with
expect and the throw)
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.
Yeah I couldn't figure out how to do that
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.
No worries. Tests are important!
|
This disables image previews iff prefetchStorage is disabled. This stops the client from making any requests to third-party sites.
There's a 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 |
On Tue, Jul 21, 2020 at 12:49:19AM -0700, Pavel Djundik wrote:
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
Yeah but I'm not sure about the part where I check that the preview was
removed.
|
Yeah that is a bit tricky. One solution I can imagine working is creating a |
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 equivalentto
false
.Help wih setting up tests would be appreciated. I couldn't figure out how to
test that a preview is not displayed.