@webitel/ui-chats 26.12.3 → 26.12.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@
14
14
  @click="gallery?.open(key)"
15
15
  >
16
16
  <img
17
- :src="image.url"
17
+ :src="toSafeAttachmentUrl(image.url)"
18
18
  alt=""
19
19
  loading="lazy"
20
20
  >
@@ -22,13 +22,13 @@
22
22
  </div>
23
23
 
24
24
  <template
25
- v-for="{ key, document, kind } of attachments.media"
25
+ v-for="{ key, document, kind, playerSrc } of media"
26
26
  :key="key"
27
27
  >
28
28
  <wt-vidstack-player
29
29
  v-if="kind === 'video'"
30
30
  class="message-attachments__media"
31
- :src="document.url"
31
+ :src="toPlayableAttachmentUrl(document.url)"
32
32
  :mime="document.mime"
33
33
  :title="document.name"
34
34
  :size="ComponentSize.SM"
@@ -40,7 +40,7 @@
40
40
  <wt-player
41
41
  v-else
42
42
  class="message-attachments__media"
43
- :src="document.url"
43
+ :src="playerSrc"
44
44
  :autoplay="false"
45
45
  :closable="false"
46
46
  countdown-time-mode
@@ -53,9 +53,9 @@
53
53
  v-for="file of attachments.files"
54
54
  :key="file.key"
55
55
  class="message-attachments__file"
56
- :href="file.url"
56
+ :href="toSafeAttachmentUrl(file.url)"
57
57
  target="_blank"
58
- rel="noopener"
58
+ rel="noopener noreferrer"
59
59
  download
60
60
  :title="t('history.download')"
61
61
  >
@@ -75,7 +75,10 @@ import { WtIcon, WtPlayer, WtVidstackPlayer } from '@webitel/ui-sdk/components';
75
75
  import { ComponentSize } from '@webitel/ui-sdk/enums';
76
76
  import { prettifyFileSize } from '@webitel/ui-sdk/scripts';
77
77
  import { computed, inject } from 'vue';
78
-
78
+ import {
79
+ toPlayableAttachmentUrl,
80
+ toSafeAttachmentUrl,
81
+ } from '../../../../shared/scripts/isSafeAttachmentUrl';
79
82
  import { useChatsV2I18n } from '../../../locale/useChatsV2I18n';
80
83
  import { classifyAttachments } from '../../../scripts/attachments';
81
84
  import type { ChatImage, MessageModel } from '../../../types';
@@ -88,8 +91,20 @@ const props = defineProps<{
88
91
  const { t } = useChatsV2I18n();
89
92
  const gallery = inject(ChatGalleryKey, null);
90
93
 
94
+ // classifyAttachments already filters; the template re-checks on purpose
91
95
  const attachments = computed(() => classifyAttachments(props.message));
92
96
 
97
+ // typed source: with no MIME Vidstack would turn a youtube url into an embed
98
+ const media = computed(() =>
99
+ attachments.value.media.map((item) => ({
100
+ ...item,
101
+ playerSrc: {
102
+ src: toPlayableAttachmentUrl(item.document.url),
103
+ type: item.document.mime ?? '',
104
+ },
105
+ })),
106
+ );
107
+
93
108
  // Reserve the box before the image loads, so a late load cannot shift the
94
109
  // scroll position.
95
110
  const aspectRatio = (image: ChatImage) => ({