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

Site Metadata: resolve relative URLs for embedded images/videos #3338

Merged
merged 4 commits into from Jun 26, 2023

Conversation

orottier
Copy link
Contributor

Hey I'm the maintainer of the webpage crate you are using to fetch metadata about submitted urls.
An issue was raised orottier/webpage-rs#8 (comment) about relative URLs which I think should be fixed on your end.
This pull request contains the fix, and I also changed the dependency to opt into future 1.x versions of the lib. The linked issue contains some other stuff that I will probably fix in the 1.6+ versions.

let og_embed_url = page
.opengraph
.videos
.first()
.and_then(|v| Url::parse(&v.url).ok());
.and_then(|v| url.join(&v.url).ok());
Copy link
Member

Choose a reason for hiding this comment

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

This would break if a site links to an external domain for images/videos. Not sure how common that is, but it could already happen in case of using cdn.example.com for media. So this should probably be conditional, and only use join if url.domain() is None (or maybe theres a better way to check it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps surprisingly, this works fine. join on an absolute URL will result in that URL.
I have added a comment and a test for this.

Copy link
Member

Choose a reason for hiding this comment

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

Great, thanks!

@Nutomic Nutomic merged commit 62c8ac1 into LemmyNet:main Jun 26, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants