plebbit / plebbit-js

A Javascript API to build applications using plebbit
GNU General Public License v2.0
41 stars 7 forks source link

implement subplebbit.features.requirePostLinkIsMedia #27

Closed estebanabaroa closed 10 months ago

estebanabaroa commented 11 months ago

I think it should be implemented in 2 parts

subplebbit.features,requireCommentLink // comment.link must be defined

and

subplebbit.features.requireCommentLinkIsMedia // comment.link must be a direct link to media, ie end in .jpg or something like that

Rinse12 commented 10 months ago

With subplebbit.features.requireCommentLinkIsMedia are we fetching the link and verifying if it's an image?

with subplebbit.features,requireCommentLink I assume we're just checking if it's a valid URL, no need for fetching?

estebanabaroa commented 10 months ago

With subplebbit.features.requireCommentLinkIsMedia are we fetching the link and verifying if it's an image?

I think there's no need for fetching, you can use the same code we use in the front end

import extName from 'ext-name'

const getCommentLinkMediaType = (link) => {
  if (!link) return
  let mime
  try {
    mime = extName(new URL(link).pathname.toLowerCase().replace('/', ''))[0]?.mime
  } catch (e) {
    return
  }
  if (mime?.startsWith('image')) return 'image'
  if (mime?.startsWith('video')) return 'video'
  if (mime?.startsWith('audio')) return 'audio'
}

if this doesn't work well maybe we change it to fetching at some point

with subplebbit.features,requireCommentLink I assume we're just checking if it's a valid URL, no need for fetching?

correct, maybe try{new URL(link).protocol === 'https:'} catch (e) {} or something

Rinse12 commented 10 months ago

Does the requirement for link and media apply for both posts and replies?

estebanabaroa commented 10 months ago

Does the requirement for link and media apply for both posts and replies?

I guess it should rather be called subplebbit.features.requirePostLink and subplebbit.features.requirePostLinkIsMedia

because for now we only want to do posts so it's like 4chan, but we might want to do replies at some point

Rinse12 commented 10 months ago

Implemented with bb51719b9249af7e22101f37afe30567e2b5a1b4