Design system.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

description.ts 2.0 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const MIME_TYPE_DESCRIPTIONS = {
  2. 'image/gif': 'GIF Image',
  3. 'image/jpeg': 'JPEG Image',
  4. 'image/png': 'PNG Image',
  5. 'image/tiff': 'TIFF Image',
  6. 'image/svg+xml': 'SVG Image',
  7. 'image/webp': 'WEBP Image',
  8. 'audio/wav': 'WAVE Audio',
  9. 'audio/ogg': 'OGG Audio',
  10. 'audio/mpeg': 'MPEG Audio',
  11. 'audio/mid': 'MIDI Track',
  12. 'application/json': 'JSON Data',
  13. 'application/xml': 'XML Data',
  14. 'application/x-bittorrent': 'Torrent File',
  15. 'application/x-zip-compressed': 'Compressed ZIP Archive',
  16. 'application/x-x509-ca-cert': 'Certificate File',
  17. 'application/x-tar': 'Compressed TAR Archive',
  18. 'application/x-rar': 'Compressed RAR Archive',
  19. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'Workbook',
  20. 'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'Slideshow Presentation',
  21. 'application/msword': 'Microsoft Word Document',
  22. 'application/pdf': 'PDF Document',
  23. 'application/postscript': 'PostScript Document',
  24. 'application/epub+zip': 'EPUB Document',
  25. 'message/rfc822': 'Email Message',
  26. 'video/mp4': 'MP4 Video',
  27. } as const;
  28. const EXTENSION_DESCRIPTIONS = {
  29. rar: 'Compressed RAR Archive',
  30. '7z': 'Compressed 7-Zip Archive',
  31. psd: 'Adobe Photoshop Document',
  32. dmg: 'Disk Image',
  33. 'fb2k-component': 'foobar2000 Component',
  34. } as const;
  35. export const getFileDescription = (type?: string, filename?: string) => {
  36. if (typeof (type as unknown) !== 'string') {
  37. return '';
  38. }
  39. if (type === 'application/octet-stream' || type === '') {
  40. if (typeof filename === 'string' && filename.includes('.')) {
  41. const extension = filename.slice(filename.lastIndexOf('.') + '.'.length).toLowerCase();
  42. const {
  43. [extension as keyof typeof EXTENSION_DESCRIPTIONS]: extensionDescription = `${extension.toUpperCase()} File`,
  44. } = EXTENSION_DESCRIPTIONS;
  45. return extensionDescription;
  46. }
  47. return `${type} File`;
  48. }
  49. const {
  50. [type as keyof typeof MIME_TYPE_DESCRIPTIONS]: description = type,
  51. } = MIME_TYPE_DESCRIPTIONS;
  52. return description;
  53. };