remy / wm

webmention check service
https://webmention.app
103 stars 17 forks source link

POST to webapp reports wrong endpoints (GET does it right) #40

Closed petergoes closed 3 years ago

petergoes commented 3 years ago

Hi,

I have created a note on my site which I want to post to twitter with webmention.app and the webmention endpoints of brid.gy. The behaviour between a GET and a POST request to https://webmention.app/check seems different:

The GET Request When I perform this GET request: https://webmention.app/check?token=<MY_TOKEN>&url=https://petergoes.nl/notes/2021-05-31-20-18/ I get this response:

{
   "urls": [
     {
       "endpoint": {
         "url": "https://brid.gy/publish/webmention",
         "type": "webmention"
       },
       "source": "https://www.petergoes.nl/notes/2021-05-31-20-18/",
       "target": "https://brid.gy/publish/mastodon"
     },
     {
       "endpoint": {
         "url": "https://brid.gy/publish/webmention",
         "type": "webmention"
       },
       "source": "https://www.petergoes.nl/notes/2021-05-31-20-18/",
       "target": "https://brid.gy/publish/twitter"
     }
   ]
}

The POST Request When I perform this POST request: https://webmention.app/check?token=<MY_TOKEN>&url=https://petergoes.nl/notes/2021-05-31-20-18/ I get this response:

{
  "urls": [
    {
      "status": 201,
      "error": null,
      "source": "https://brid.gy/publish/mastodon",
      "target": "https://brid.gy/publish/webmention"
    },
    {
      "status": 201,
      "error": null,
      "source": "https://brid.gy/publish/twitter",
      "target": "https://brid.gy/publish/webmention"
    }
  ]
}

As with the GET request, I expected the POST request to have a target of https://brid.gy/publish/twitter, and not https://brid.gy/publish/webmention.

The status code in the POST requests are 201. So the post IS being posted to Twitter. So functionally it works.

The reason I am asking is that brid.gy is supposed to return the created tweet object when the target is https://brid.gy/publish/twitter. That Tweet object contains the created Tweet ID I need to create a rel="syndication" link back in the original post.

Other relevant things

I am really not sure where things go wrong. Maybe I should even ask @snarfed if it goes wrong on brid.gy?

I searched through the code to see if I could find it myself, but no luck so far.

petergoes commented 3 years ago

Ah!! This is a Nuxt project! Now it makes a little more sense to me.

Here is what I found: In lib/send/webmention.js the actual webmention is being send. And a reply back to the user is being constructed: https://github.com/remy/wm/blob/f61809c27d159607673ddb8c8ed009514bcd88d1/lib/send/webmention.js#L20-L25

But as line 23 states, the target and source get swapped in te reply. That is what tripped me up. But explains why it functionally did what is supposed to do.

The only thing I would like now, is to have the response from the endpoint reflected in the reply. Because that probably contains the tweet object (in my case).

I hope you are open to a PR. I will propose something right away

petergoes commented 3 years ago

I have played around with the idea a bit further. I realise it adds a significant amount of code to support my use case. I don't think it is wise to add that to this project. So I'll close this issue.

If anyone stumbles upon this, I am happy to give some directions to implement it yourself