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

Create an oEmbed endpoint for maps #1526

Merged
merged 1 commit into from Jan 29, 2024
Merged

Create an oEmbed endpoint for maps #1526

merged 1 commit into from Jan 29, 2024

Conversation

davidbgk
Copy link
Contributor

Fix #162

Based on https://oembed.com/

@davidbgk davidbgk force-pushed the oembed branch 2 times, most recently from 22b1725 to d2ce895 Compare January 11, 2024 20:02
Copy link
Member

@yohanboniface yohanboniface left a comment

Choose a reason for hiding this comment

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

Excellent!
Shame on me that I did not implement this earlier!

@@ -675,3 +675,63 @@ def test_download_my_map(client, map, datalayer):
# Test response is a json
j = json.loads(response.content.decode())
assert j["type"] == "umap"


@pytest.mark.parametrize("share_status", [Map.PRIVATE, Map.BLOCKED, Map.OPEN])
Copy link
Member

Choose a reason for hiding this comment

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

Not sure about the OPEN here. The purpose of the OPEN status, is that a map is not discoverable, but once you have a link you can view it normally, so why not allowing also the oEmbed in this case ?

j = json.loads(response.content.decode())
assert j["type"] == "rich"
assert j["version"] == "1.0"
assert j["width"] == 800
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, are those dimensions configurable by the caller ? Or should we have a relative width ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The spec says:

The width/height in pixels required to display the HTML.

And maybe it was before we can have more flexible dimensions?

format_ = request.GET.get("format", "json")
if format_ != "json":
response = HttpResponseServerError("Only `json` format is implemented.")
response.status_code = 501
Copy link
Member

Choose a reason for hiding this comment

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

Why not a 40x here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to stick to the spec as much as possible:

501 Not Implemented
The provider cannot return a response in the requested format. This should be sent when (for example) the request includes format=xml and the provider doesn't support XML responses. However, providers are encouraged to support both JSON and XML.

data["height"] = height
width = 800
data["width"] = width
# TODISCUSS: do we keep width=100% by default for the iframe?
Copy link
Member

Choose a reason for hiding this comment

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

Can't we keep both width in relative ?

@bristow
Copy link

bristow commented Jan 17, 2024

For the width, i give you 3 exemples : PeerTube, Youtube and osm.org

## PeerTube

<div data-oembed-url="https://tube-sciences-technologies.apps.education.fr/w/mhdTmfC5fgVq6WMjc5jp1g?start=10s"> 
 <div style="left:0;width:100%;height:0;position:relative;padding-bottom:56.25%"> 
  <iframe allowfullscreen="" src="https://tube-sciences-technologies.apps.education.fr/videos/embed/a43a9d48-75c0-4176-b336-3fd2b56e203b" style="top:0;left:0;width:100%;height:100%;position:absolute;border:0" tabindex="-1"></iframe> 
 </div> 
 
 ##Youtube
 <div data-oembed-url="https://www.youtube.com/watch?v=CHQrIMo0xak">
<div style="left: 0; width: 100%; height: 0; position: relative; padding-bottom: 56.25%;"><iframe allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share;" allowfullscreen="" scrolling="no" src="https://www.youtube.com/embed/CHQrIMo0xak?rel=0" style="top: 0; left: 0; width: 100%; height: 100%; position: absolute; border: 0;" tabindex="-1"></iframe></div>

## Openstreetmap
<div data-oembed-url="https://www.openstreetmap.org/#map=18/45.80318/4.83529">
<div style="left: 0; width: 100%; height: 0; position: relative; padding-bottom: 75%;"><iframe allowfullscreen="" src="https://www.openstreetmap.org/export/embed.html?bbox=4.832267761230469,45.80481138832744,4.835700988769531,45.80301636960864&amp;layer=mapnik" style="top: 0; left: 0; width: 100%; height: 100%; position: absolute; border: 0;" tabindex="-1"></iframe></div>
</div>

So 100% seems like a good choice

@davidbgk
Copy link
Contributor Author

@bristow thank you so much for these example!

Do you also have the raw responses from the oembed endpoints of these services to see how they deal with the width parameter? The spec states that it should be in pixels so I'm curious how they handled that :)

@bristow
Copy link

bristow commented Jan 18, 2024

@davidbgk
Copy link
Contributor Author

I hope this helps

Definitely!

I'm curious though because if you take the payload from https://peertube2.cpy.re/services/oembed?url=https%3A%2F%2Fpeertube2.cpy.re%2Fw%2F1zywKcr1ChzL7R9rG6yCnq
you have that value in the html key of the returned JSON:

<iframe width="560" height="315" 
  sandbox="allow-same-origin allow-scripts allow-popups" title="The Internet&#39;s Own Boy" 
  src="https://peertube2.cpy.re/videos/embed/04af977f-4201-4697-be67-a8d8cae6fa7a" 
  frameborder="0" allowfullscreen>
</iframe>

Which does not states width="100%" as previously mentioned. So where did you get previous HTML extracts?

@bristow
Copy link

bristow commented Jan 19, 2024

I took these codes from the source code of this site, which offers remote media integration via oEmbed.

@bristow
Copy link

bristow commented Jan 25, 2024

Will this feature be deployed in the near future?

I'm willing to test it on a pre-prod platform if need be.

Thank you!

@yohanboniface
Copy link
Member

yohanboniface commented Jan 25, 2024

Very soon!

We are in a Javascript refactor which prevents us to add more features to the deployment flow, but it seems we are close to getting back to normal life! Sorry for that :)

@yohanboniface yohanboniface merged commit dadcaa0 into master Jan 29, 2024
12 checks passed
@yohanboniface yohanboniface deleted the oembed branch January 29, 2024 11:44
@davidbgk
Copy link
Contributor Author

@bristow this is now deployed on the OSM instance 🤞

@bristow
Copy link

bristow commented Feb 10, 2024

Thank you so much!

But it doesn't seem to be working :/

Here's a capture of a render where I embed an umap link and below it an osm.org map link using the same method.

Sélection_1390

Any idea?

@bristow
Copy link

bristow commented Feb 10, 2024

I analysed the source code of an umap map.
You can see the oembed URL starting with: https://umap.openstreetmap.fr/map/oembed/
But this URL returns a 404 error, whereas on a Peertube instance you get a json return: https://tube.ac-lyon.fr/services/oembed with the message that it can't find the URL

Perhaps a clue...

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.

OEmbed support
3 participants