whatsapp.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Whatsapp
  3. MIME_TYPES = {
  4. 'text/plain': 'txt',
  5. 'application/pdf': 'pdf',
  6. 'application/vnd.ms-powerpoint': 'ppt',
  7. 'application/msword': 'doc',
  8. 'application/vnd.ms-excel': 'xls',
  9. 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',
  10. 'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'pptx',
  11. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
  12. 'image/jpeg': 'jpeg',
  13. 'image/png': 'png',
  14. 'image/webp': 'webp',
  15. 'video/mp4': 'mp4',
  16. 'video/3gp': '3gp',
  17. 'audio/aac': 'aac',
  18. 'audio/mp4': 'm4a',
  19. 'audio/mpeg': 'mp3',
  20. 'audio/amr': 'amr',
  21. 'audio/ogg': 'ogg',
  22. }.freeze
  23. def self.file_suffix(mime_type:)
  24. identified_mime_type = Whatsapp::MIME_TYPES[mime_type.to_sym]
  25. return identified_mime_type if identified_mime_type.present?
  26. identified_mime_type = MIME::Types[mime_type]&.first
  27. return identified_mime_type.preferred_extension if identified_mime_type.present? && identified_mime_type.preferred_extension.present?
  28. 'dat'
  29. end
  30. end