icons.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. export const getIconByContentType = (type?: Maybe<string>) => {
  3. if (!type) return 'file'
  4. const contentType = type.replace(/^(.+?\/.+?)(\b|\s).+?$/, '$1')
  5. const icons: Record<string, string> = {
  6. // image
  7. 'image/jpeg': 'photos',
  8. 'image/jpg': 'photos',
  9. 'image/png': 'photos',
  10. 'image/svg': 'photos',
  11. 'image/gif': 'photos',
  12. 'image/webp': 'photos',
  13. // audio
  14. 'audio/aac': 'audio',
  15. 'audio/mp4': 'audio',
  16. 'audio/mpeg': 'audio',
  17. 'audio/amr': 'audio',
  18. 'audio/ogg': 'audio',
  19. // video
  20. 'video/mp4': 'video',
  21. 'video/3gp': 'video',
  22. // documents
  23. 'application/pdf': 'library',
  24. 'application/msword': 'template', // .doc, .dot
  25. 'application/vnd.ms-word': 'template',
  26. 'application/vnd.oasis.opendocument.text': 'template',
  27. 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
  28. 'template', // .docx
  29. 'application/vnd.openxmlformats-officedocument.wordprocessingml.template':
  30. 'template', // .dotx
  31. 'application/vnd.ms-excel': 'file', // .xls
  32. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'file', // .xlsx
  33. 'application/vnd.oasis.opendocument.spreadsheet': 'file',
  34. 'application/vnd.ms-powerpoint': 'file', // .ppt
  35. 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
  36. 'file', // .pptx
  37. 'application/vnd.oasis.opendocument.presentation': 'file',
  38. // code
  39. 'text/html': 'template',
  40. 'application/json': 'template',
  41. 'message/rfc822': 'mail-file',
  42. // text
  43. 'text/plain': 'template',
  44. 'text/rtf': 'template',
  45. 'text/calendar': 'calendar',
  46. // archives
  47. 'application/gzip': 'attachment',
  48. 'application/zip': 'attachment',
  49. }
  50. return icons[contentType] || 'file'
  51. }