vipickering / mastr-cntrl

A Micropub Microservice
MIT License
26 stars 2 forks source link

Micropub image posts wrong url #74

Closed vipickering closed 4 years ago

vipickering commented 5 years ago

Image posts are returning the wrong url e.g. https://vincentp.me/notes/2019/03/15/15-12/

instead of: https://vincentp.me/photos/2019/03/15/15-12/

vipickering commented 5 years ago

This is because the micropub endpoint returns the url of the micropub type. Which is correct. It is a note. The problem is that I return images in a different location, despite the fact they are notes.

This is a non-critical bug and only affects the place a Micropub redirects to after publish.

paulrobertlloyd commented 5 years ago

I solved this by checking if there was an uploaded file, and if so, deriving the post type from the file’s mimetype (which is provided by Multer):

const deriveMediaType = mimetype => {
  if (mimetype.includes('audio/')) {
    return 'audio';
  }

  if (mimetype.includes('image/')) {
    return 'photo';
  }

  if (mimetype.includes('video/')) {
    return 'video';
  }
};
vipickering commented 5 years ago

Awesome thanks!