#dev 2021-12-03

2021-12-03 UTC
[KevinMarks], [tw2113_Slack_], sayanarijit[d], Seirdy, KartikPrabhu, gRegor, [jeremycherfas], jjuran, kogepan, tetov-irc, P1000[d], doosboox and [Paul_Walk] joined the channel
#
[Paul_Walk]
I have a question about Micropub's handling of "media". I have implemented a Micropub server in Go - I have the authorisation using IndieAuth working, and posting and updating posts using IAWriter as a client is working too.
#
[Paul_Walk]
This is all correct as far as the Micropub spec goes.
#
[Paul_Walk]
I have now turned my attention to implementing a media endpoint. I have managed to get this working per the specification, and IAWriter will correctly upload an image, receive the URL, and re-write the posts's link to use this new image URL.
#
[Paul_Walk]
The Micropub handling of media uploads would seem to prevent me from continuing to store images alongside posts, since there does not seem to be any way in the Micropub media-endpoint HTTP POST operation to know anything about the associated post (from which I would be able to derive the location to store the image).
#
[Paul_Walk]
However.... I am using this to drive my blog which is arranged around each post being in its own directory together with any supplementary files, images etc. I'm very happy with this arrangement since each folder is essentially a logical package of all the (local) content related to that post, and I've been running this since 2003.
#
[Paul_Walk]
If I have understood correctly, Micropub seems to isolate the storing of the media from the storing of the post by design.
#
[Paul_Walk]
Have I got this right? It feels like a show-stopper for me, which is unfortunate since the rest of it is working well!
#
sknebel
nothing is stopping your endpoint from moving the file to the post folder
#
sknebel
once a post is made
#
[Paul_Walk]
And then re-parsing the post to rewrite the image arc url…
#
[Paul_Walk]
src
#
sknebel
I guess if its put in the html source, yes.
#
[Paul_Walk]
Ok - thanks for confirming my understanding. I guess Micropub is less of a fit for my use-case than I first thought. I also have posts with multiple images which does not seem to be supported (possibly a limitation in the client though).
#
capjamesg[d]
You can also use the Location header sent by the media endpoint to get the location of the file.
#
capjamesg[d]
That's what I do in my client.
#
capjamesg[d]
If I upload an image, the client sends a POST request to the Media Endpoint. The media endpoint processes the request and then sends back the location of the new image. The client sends that location alongside the actual post information -- title, contents, image alt text, etc. -- to the server to be turned into a post.
#
capjamesg[d]
That way I can upload media and a post at the same time and connect the URL of the image (which is generated by the server) in the original request without doing any post-processing once the content file (note, blog post, etc.) has been created.
Sanhero[d] joined the channel
#
sknebel
micropub supports multiple images just fine
#
[KevinMarks]
So you could upload to a holding directory and transfer to the post one afterwards?
#
sknebel
thats what I already suggested
#
[KevinMarks]
Hm. Is each post's directory keyed by slug or index for the day? If the latter you could make the upload directory be, say, /2021/12/02/1 to start with and increment the 1 to 2 when the post succeeds
#
[Paul_Walk]
The post directory is a slug based on the `name` in the `h-entry`.
#
[Paul_Walk]
It would be viable to transfer the image fro a holding directory to the post’s directory as the post was being created. I could certainly live with that. The irritating thing is that the client is rewriting the src url of the image to the location returned by the media-endpoint, so I would also have to re-parse and replace that src URL with the new one. It's possible, but hacky in my view.
#
[Paul_Walk]
↩️ Ok - thanks - I need to revisit this then
#
aaronpk
That's basically exactly how my site works. The media endpoint is essentially a temporary location that photos are put when the post is being authored, and then my site moves the files into the post's folder when it's created
#
[Paul_Walk]
Although, having read this from @capjamesg[d]
#
[Paul_Walk]
> The client sends that location alongside the actual post information -- title, contents, image alt text, etc. -- to the server to be turned into a post.
#
[Paul_Walk]
Perhaps this is not so gnarly if the temp URLs for images are sent as discrete metadata items
#
[Paul_Walk]
So, to be clear, I should expect to see an array of image URLs in the HTTP POST that sends the actual 'post' (the text) ?
#
aaronpk
For photo posts yes. But if you're authoring a blog post with images inline, the client will send that as img tags inside the html content property
#
[Paul_Walk]
Ah, yes that's what's happening now
#
[Paul_Walk]
OK - it's obviously not impossible to search and replace those URLs after moving the images, it's just a few more moving parts than I was expecting to need :-)
#
[Paul_Walk]
1. publish with client
#
[Paul_Walk]
2. client sends images to media-endpoint
#
[Paul_Walk]
4. client re-writes post content to use new, temporary image locations
#
[Paul_Walk]
3. media server stores images in temporary location, return these to the client
#
[Paul_Walk]
5. client posts the h-entry to the server
#
[Paul_Walk]
6. the server process builds a new post from the h-entry (I'm using Hugo nowadays), creating the 'slug' directory for this.
#
[Paul_Walk]
7. the server process parses the new post looking for image locations that match the media-server's storage location
#
[Paul_Walk]
8. the server process moves any such images to the local, post folder
#
[Paul_Walk]
9. the server process re-writes the image src URLs in the post content to reflect the new location
#
[Paul_Walk]
If I use a single temp location and UUID for the image names, then step 9 becomes simple - just remove the predictable host/path and make the URL 'relative' (i.e. just "./UUID.jpg" or whatever
#
[Paul_Walk]
Of course this depends on the media server storing the file synchronously and returning HTTP 201, but that's in my control so fine.
#
[Paul_Walk]
Thanks for all the advice and for helping me think this through 👍
#
[Paul_Walk]
I'll be sharing my code and write up soon
balupton[d] joined the channel
#
jamietanna[m]
Thanks GWG I'll have a look when I get a chance
#
GWG
jamietanna[m]: Shouldn't I be thanking you?
#
jamietanna[m]
I've not done anything yet 🙃
#
GWG
jamietanna[m]: For agreeing to do it?
#
GWG
jamietanna[m]: Got feedback from a WordPressy POV. But need spec POV
Darius_Dunlap[d], KartikPrabhu and jjuran joined the channel
#
GWG
jamietanna[m]: Forgot to mention I left auth off the introspection endpoint for now
gRegor joined the channel
#
GWG
gRegor: What is the site using to determine supported properties?
#
GWG
I know I proposed a few things, but we never settled.
#
gRegor
Yeah, visibility is proposed. IBC is looking for `visiblity` in the mc config response, like https://github.com/indieweb/micropub-extensions/issues/8#issuecomment-536301952
#
gRegor
So if your mp endpoint doesn't have that, you shouldn't see any visibility options on IBC, which is fine.
#
Loqi
[aaronpk] I implemented initial support in Quill for this. Quill now looks for the following object in the `q=config` response: ```json "visibility": ["public","unlisted","private"] ``` The reasoning for this is I want clients to be aware of the mean...
#
gRegor
I don't really need that part tested, was just thinking if you had it you could try it.
#
GWG
I'll see about adding that in the next revision
#
GWG
But I did post a want to read option
#
GWG
Did it satisfy your need?
#
gRegor
Looks like your mp publish request returned 400 btw. Settings page in IBC will show the last mp response.
#
gRegor
Funny book title btw, haha
#
gRegor
I think it's all good for now. Can't test the mp delete since the publish didn't work.
#
GWG
I'll see about the other thing
#
gRegor
I've tested them quite a bit; the mp requests go through for me, but I don't support visibility or delete yet, so I was just logging those requests on my site. They all look good per the spec / proposed properties
#
GWG
On a positive note, wpdev is running my test upgraded endpoint, so I didn't break anything there
#
GWG
Next time, I'm going to finish my newly minted book
#
gRegor
Nice! And IndieAuth with PKCE worked for you as well, so I think IBC is ready to go.
#
gRegor
Thanks for testing GWG++
#
Loqi
GWG has 15 karma in this channel over the last year (77 in all channels)
[chrisaldrich] joined the channel
#
GWG
gRegor: Glad to help
kogepan_, Seirdy, gRegor and tetov-irc joined the channel