mirror of
https://github.com/lingble/chatwoot.git
synced 2025-12-06 21:05:29 +00:00
We are using `audio` component for rendering audio files in dashboard.
```
<audio v-else-if="isAudio" controls>
<source :src="`${dataUrl}?t=${Date.now()}`" />
</audio>
```
We have added the timestamp for every audio URL for cache busting. For
Instagram, we are getting a signature URL. When we add any value and
access the URL, it results in an "Invalid signature. If I remove the
timestamp, the audio is rendering properly. This PR will change the
logic to construct the URL properly instead of direct string
manipulation.
127 lines
2.8 KiB
Vue
127 lines
2.8 KiB
Vue
<script>
|
|
import { mapGetters } from 'vuex';
|
|
import { hasPressedCommand } from 'shared/helpers/KeyboardHelpers';
|
|
import GalleryView from '../components/GalleryView.vue';
|
|
import { timeStampAppendedURL } from 'dashboard/helper/URLHelper';
|
|
|
|
const ALLOWED_FILE_TYPES = {
|
|
IMAGE: 'image',
|
|
VIDEO: 'video',
|
|
AUDIO: 'audio',
|
|
IG_REEL: 'ig_reel',
|
|
};
|
|
|
|
export default {
|
|
components: {
|
|
GalleryView,
|
|
},
|
|
props: {
|
|
attachment: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
},
|
|
data() {
|
|
return {
|
|
show: false,
|
|
isImageError: false,
|
|
};
|
|
},
|
|
computed: {
|
|
...mapGetters({
|
|
currentChatAttachments: 'getSelectedChatAttachments',
|
|
}),
|
|
isImage() {
|
|
return this.attachment.file_type === ALLOWED_FILE_TYPES.IMAGE;
|
|
},
|
|
isVideo() {
|
|
return (
|
|
this.attachment.file_type === ALLOWED_FILE_TYPES.VIDEO ||
|
|
this.attachment.file_type === ALLOWED_FILE_TYPES.IG_REEL
|
|
);
|
|
},
|
|
isAudio() {
|
|
return this.attachment.file_type === ALLOWED_FILE_TYPES.AUDIO;
|
|
},
|
|
timeStampURL() {
|
|
return timeStampAppendedURL(this.dataUrl);
|
|
},
|
|
attachmentTypeClasses() {
|
|
return {
|
|
image: this.isImage,
|
|
video: this.isVideo,
|
|
};
|
|
},
|
|
filteredCurrentChatAttachments() {
|
|
const attachments = this.currentChatAttachments.filter(attachment =>
|
|
['image', 'video', 'audio'].includes(attachment.file_type)
|
|
);
|
|
return attachments;
|
|
},
|
|
dataUrl() {
|
|
return this.attachment.data_url;
|
|
},
|
|
imageWidth() {
|
|
return this.attachment.width ? `${this.attachment.width}px` : 'auto';
|
|
},
|
|
imageHeight() {
|
|
return this.attachment.height ? `${this.attachment.height}px` : 'auto';
|
|
},
|
|
},
|
|
watch: {
|
|
attachment() {
|
|
this.isImageError = false;
|
|
},
|
|
},
|
|
methods: {
|
|
onClose() {
|
|
this.show = false;
|
|
},
|
|
onClick(e) {
|
|
if (hasPressedCommand(e)) {
|
|
window.open(this.attachment.data_url, '_blank');
|
|
return;
|
|
}
|
|
this.show = true;
|
|
},
|
|
onImgError() {
|
|
this.isImageError = true;
|
|
this.$emit('error');
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div class="message-text__wrap" :class="attachmentTypeClasses">
|
|
<img
|
|
v-if="isImage && !isImageError"
|
|
class="bg-woot-200 dark:bg-woot-900"
|
|
:src="dataUrl"
|
|
:width="imageWidth"
|
|
:height="imageHeight"
|
|
@click="onClick"
|
|
@error="onImgError"
|
|
/>
|
|
<video
|
|
v-if="isVideo"
|
|
:src="dataUrl"
|
|
muted
|
|
playsInline
|
|
@error="onImgError"
|
|
@click="onClick"
|
|
/>
|
|
<audio v-else-if="isAudio" controls class="skip-context-menu mb-0.5">
|
|
<source :src="timeStampURL" />
|
|
</audio>
|
|
<GalleryView
|
|
v-if="show"
|
|
:show.sync="show"
|
|
:attachment="attachment"
|
|
:all-attachments="filteredCurrentChatAttachments"
|
|
@error="onImgError"
|
|
@close="onClose"
|
|
/>
|
|
</div>
|
|
</template>
|