This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Use attrs internally for the URL preview code & add documentation. #10753
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
17ad24e
Use attrs internally for the url preview code.
clokep cbde755
Add some documentation on the flow.
clokep f146c27
Newsfragment
clokep 6686c1c
Document MediaInfo.
clokep e74dcd3
Merge remote-tracking branch 'origin/develop' into clokep/oembed-stuff
clokep 801a9e0
Lint
clokep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Use `attrs` internally for the URL preview code & update documentation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
URL Previews | ||
============ | ||
|
||
The `GET /_matrix/media/r0/preview_url` endpoint provides a generic preview API | ||
for URLs which outputs [Open Graph](https://ogp.me/) responses (with some Matrix | ||
specific additions). | ||
|
||
This does have trade-offs compared to other designs: | ||
|
||
* Pros: | ||
* Simple and flexible; can be used by any clients at any point | ||
* Cons: | ||
* If each homeserver provides one of these independently, all the HSes in a | ||
room may needlessly DoS the target URI | ||
* The URL metadata must be stored somewhere, rather than just using Matrix | ||
itself to store the media. | ||
* Matrix cannot be used to distribute the metadata between homeservers. | ||
|
||
When Synapse is asked to preview a URL it does the following: | ||
|
||
1. Checks against a URL blacklist (defined as `url_preview_url_blacklist` in the | ||
config). | ||
2. Checks the in-memory cache by URLs and returns the result if it exists. (This | ||
is also used to de-duplicate processing of multiple in-flight requests at once.) | ||
3. Kicks off a background process to generate a preview: | ||
1. Checks the database cache by URL and timestamp and returns the result if it | ||
has not expired and was successful (a 2xx return code). | ||
2. Checks if the URL matches an oEmbed pattern. If it does, fetch the oEmbed | ||
response. If this is an image, replace the URL to fetch and continue. If | ||
if it is HTML content, use the HTML as the document and continue. | ||
3. If it doesn't match an oEmbed pattern, downloads the URL and stores it | ||
into a file via the media storage provider and saves the local media | ||
metadata. | ||
5. If the media is an image: | ||
1. Generates thumbnails. | ||
2. Generates an Open Graph response based on image properties. | ||
6. If the media is HTML: | ||
1. Decodes the HTML via the stored file. | ||
2. Generates an Open Graph response from the HTML. | ||
3. If an image exists in the Open Graph response: | ||
1. Downloads the URL and stores it into a file via the media storage | ||
provider and saves the local media metadata. | ||
2. Generates thumbnails. | ||
3. Updates the Open Graph response based on image properties. | ||
7. Stores the result in the database cache. | ||
4. Returns the result. | ||
|
||
The in-memory cache expires after 1 hour. | ||
|
||
Expired entries in the database cache (and their associated media files) are | ||
deleted every 10 seconds. The default expiration time is 1 hour from download. |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.