Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement useCommentMedia #5

Open
estebanabaroa opened this issue Sep 7, 2023 · 0 comments
Open

implement useCommentMedia #5

estebanabaroa opened this issue Sep 7, 2023 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@estebanabaroa
Copy link
Member

the API should be something like

export interface UseCommentMediaOptions extends Options {
  comment?: Comment
}
export interface UseCommentMediaResult extends Result {
  mediaType?: 'image' | 'video' | 'audio'
  mediaUrl?: string
  thumbnailUrl?: string
}

the media type can be gotten and should be cached like this:

import extName from 'ext-name'
import memoize from 'memoizee'

// cache media type because it takes on average 5ms
const getCommentLinkMediaTypeNoCache = (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'
}
export const getCommentLinkMediaType = memoize(getCommentLinkMediaTypeNoCache, {max: 1000})

the thumbnailUrl can be calculated from the comment.link for a 3 special cases:

youtube: https://img.youtube.com/vi/${videoId}/sddefault.jpg

bitchute: https://static-3.bitchute.com/live/cover_images/F61vWF4shy8s/${videoId}_640x360.jpg

streamable: https://cdn-cf-east.streamable.com/image/${videoId}.jpg

@estebanabaroa estebanabaroa added good first issue Good for newcomers help wanted Extra attention is needed enhancement New feature or request labels Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant