useArticleAttachments.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. import { useApplicationStore } from '@shared/stores/application'
  3. import type { ComputedRef } from 'vue'
  4. import { computed } from 'vue'
  5. import type { TicketArticleAttachment } from '@shared/entities/ticket/types'
  6. import { getArticleAttachmentsLinks } from '@shared/entities/ticket-article/composables/getArticleAttachmentsLinks'
  7. interface AttachmentsOptions {
  8. ticketInternalId: number
  9. articleInternalId: number
  10. attachments: ComputedRef<TicketArticleAttachment[]>
  11. }
  12. export const useArticleAttachments = (options: AttachmentsOptions) => {
  13. const application = useApplicationStore()
  14. const attachments = computed(() => {
  15. return options.attachments.value.map((attachment) => {
  16. const { previewUrl, canDownload, downloadUrl } =
  17. getArticleAttachmentsLinks(
  18. {
  19. ticketInternalId: options.ticketInternalId,
  20. articleInternalId: options.articleInternalId,
  21. internalId: attachment.internalId,
  22. type: attachment.type,
  23. },
  24. application.config,
  25. )
  26. return {
  27. ...attachment,
  28. preview: previewUrl,
  29. canDownload,
  30. downloadUrl,
  31. }
  32. })
  33. })
  34. return {
  35. attachments,
  36. }
  37. }