useEmailFileUrls.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { find } from 'lodash-es'
  3. import { computed, type Ref, type MaybeRef, toValue } from 'vue'
  4. import type { TicketArticle } from '#shared/entities/ticket/types.ts'
  5. // TODO MaybeRef needed? Check...
  6. export const useEmailFileUrls = (
  7. ticketArticle: MaybeRef<TicketArticle>,
  8. ticketInternalId: Ref<number>,
  9. ) => {
  10. const article = computed(() => toValue(ticketArticle))
  11. const originalFormattingUrl = computed(() => {
  12. if (article.value.type?.name !== 'email') return
  13. const originalFormattingFile = find(
  14. article.value.attachmentsWithoutInline,
  15. (file) => {
  16. return file.preferences?.['original-format'] === true
  17. },
  18. )
  19. if (!originalFormattingFile) return
  20. return `/api/v1/ticket_attachment/${ticketInternalId.value}/${article.value.internalId}/${originalFormattingFile.internalId}?disposition=attachment`
  21. })
  22. const rawMessageUrl = computed(() => {
  23. if (article.value.type?.name !== 'email') return
  24. return `/api/v1/ticket_article_plain/${article.value.internalId}`
  25. })
  26. return { originalFormattingUrl, rawMessageUrl }
  27. }