#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!
# [Paul_Walk] And then re-parsing the post to rewrite the image arc url…
# [Paul_Walk] src
# [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
# [KevinMarks] So you could upload to a holding directory and transfer to the post one afterwards?
# [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
# [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) ?
# [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
# petermolnar this is semi-indieweb: https://make.wordpress.org/openverse/
# jamietanna[m] Thanks GWG I'll have a look when I get a chance
# jamietanna[m] I've not done anything yet 🙃
Darius_Dunlap[d], KartikPrabhu and jjuran joined the channel
gRegor joined the channel
# 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
[chrisaldrich] joined the channel
kogepan_, Seirdy, gRegor and tetov-irc joined the channel