logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

file_type.service.js (1096B)


  1. // TODO this func might as well take the entire file and use its mimetype
  2. // or the entire service could be just mimetype service that only operates
  3. // on mimetypes and not files. Currently the naming is confusing.
  4. export const fileType = mimetype => {
  5. if (mimetype.match(/flash/)) {
  6. return 'flash'
  7. }
  8. if (mimetype.match(/text\/html/)) {
  9. return 'html'
  10. }
  11. if (mimetype.match(/image/)) {
  12. return 'image'
  13. }
  14. if (mimetype.match(/video/)) {
  15. return 'video'
  16. }
  17. if (mimetype.match(/audio/)) {
  18. return 'audio'
  19. }
  20. return 'unknown'
  21. }
  22. export const fileTypeExt = url => {
  23. if (url.match(/\.(a?png|jpe?g|gif|webp|avif)$/)) {
  24. return 'image'
  25. }
  26. if (url.match(/\.(ogv|mp4|webm|mov)$/)) {
  27. return 'video'
  28. }
  29. if (url.match(/\.(it|s3m|mod|umx|mp3|aac|m4a|flac|alac|ogg|oga|opus|wav|ape|midi?)$/)) {
  30. return 'audio'
  31. }
  32. return 'unknown'
  33. }
  34. export const fileMatchesSomeType = (types, file) =>
  35. types.some(type => fileType(file.mimetype) === type)
  36. const fileTypeService = {
  37. fileType,
  38. fileTypeExt,
  39. fileMatchesSomeType
  40. }
  41. export default fileTypeService