image.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. module Service
  3. class Image
  4. include ApplicationLib
  5. =begin
  6. lookup user image based on email address
  7. file = Service::Image.user('skywalker@zammad.org')
  8. returns
  9. {
  10. content: content,
  11. mime_type: mime_type,
  12. }
  13. =end
  14. def self.user(address)
  15. # load backend
  16. backend = load_adapter_by_setting('image_backend')
  17. return if !backend
  18. backend.user(address)
  19. end
  20. =begin
  21. lookup organization image based on domain
  22. file = Service::Image.organization('edenhofer.de')
  23. file = Service::Image.organization('user@edenhofer.de') # will just use domain
  24. returns
  25. {
  26. content: content,
  27. mime_type: mime_type,
  28. }
  29. =end
  30. def self.organization(domain)
  31. # load backend
  32. backend = load_adapter_by_setting('image_backend')
  33. return if !backend
  34. backend.organization(domain)
  35. end
  36. =begin
  37. find organization image suggestion and store it as app logo
  38. result = Service::Image.organization_suggest('edenhofer.de')
  39. returns
  40. true # or false
  41. =end
  42. def self.organization_suggest(domain)
  43. # load backend
  44. backend = load_adapter_by_setting('image_backend')
  45. return if !backend
  46. result = backend.organization_suggest(domain)
  47. # sync logo to assets folder
  48. if result
  49. StaticAssets.sync
  50. end
  51. result
  52. end
  53. end
  54. end