Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd93992b42 | ||
|
|
e82dca9b79 | ||
|
|
f4c3f5095e | ||
|
|
103b48b50f | ||
|
|
5bc8467450 | ||
|
|
b35592b319 | ||
|
|
adf9213ba1 | ||
|
|
80b0326e16 | ||
|
|
11e55d2d2c | ||
|
|
30f23fa70f |
@@ -1,7 +1,9 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed } from 'vue';
|
import { computed, onMounted } from 'vue';
|
||||||
import BaseBubble from './Base.vue';
|
import BaseBubble from './Base.vue';
|
||||||
import AudioChip from 'next/message/chips/Audio.vue';
|
import AudioChip from 'next/message/chips/Audio.vue';
|
||||||
|
import Icon from 'next/icon/Icon.vue';
|
||||||
|
import { useLoadWithRetry } from 'dashboard/composables/loadWithRetry';
|
||||||
import { useMessageContext } from '../provider.js';
|
import { useMessageContext } from '../provider.js';
|
||||||
|
|
||||||
const { attachments } = useMessageContext();
|
const { attachments } = useMessageContext();
|
||||||
@@ -9,11 +11,28 @@ const { attachments } = useMessageContext();
|
|||||||
const attachment = computed(() => {
|
const attachment = computed(() => {
|
||||||
return attachments.value[0];
|
return attachments.value[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { isLoaded, hasError, loadWithRetry } = useLoadWithRetry({
|
||||||
|
mediaType: 'audio',
|
||||||
|
});
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (attachment.value?.dataUrl) {
|
||||||
|
loadWithRetry(attachment.value.dataUrl);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<BaseBubble class="bg-transparent" data-bubble-name="audio">
|
<BaseBubble class="bg-transparent" data-bubble-name="audio">
|
||||||
|
<div v-if="hasError" class="flex items-center gap-1 text-center rounded-lg">
|
||||||
|
<Icon icon="i-lucide-circle-off" class="text-n-slate-11" />
|
||||||
|
<p class="mb-0 text-n-slate-11">
|
||||||
|
{{ $t('COMPONENTS.MEDIA.AUDIO_UNAVAILABLE') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
<AudioChip
|
<AudioChip
|
||||||
|
v-else-if="isLoaded"
|
||||||
:attachment="attachment"
|
:attachment="attachment"
|
||||||
class="p-2 text-n-slate-12 skip-context-menu"
|
class="p-2 text-n-slate-12 skip-context-menu"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
export const useLoadWithRetry = (config = {}) => {
|
export const useLoadWithRetry = (config = {}) => {
|
||||||
const maxRetry = config.max_retry || 3;
|
const maxRetry = (config.max_retry ?? config.maxRetry) || 3;
|
||||||
const backoff = config.backoff || 1000;
|
const backoff = (config.backoff ?? config.backOff) || 1000;
|
||||||
|
const mediaType = (config.mediaType ?? config.media_type) || 'image';
|
||||||
|
|
||||||
const isLoaded = ref(false);
|
const isLoaded = ref(false);
|
||||||
const hasError = ref(false);
|
const hasError = ref(false);
|
||||||
@@ -10,19 +11,25 @@ export const useLoadWithRetry = (config = {}) => {
|
|||||||
const loadWithRetry = async url => {
|
const loadWithRetry = async url => {
|
||||||
const attemptLoad = () => {
|
const attemptLoad = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const img = new Image();
|
const onSuccess = () => {
|
||||||
|
|
||||||
img.onload = () => {
|
|
||||||
isLoaded.value = true;
|
isLoaded.value = true;
|
||||||
hasError.value = false;
|
hasError.value = false;
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
img.onerror = () => {
|
let element;
|
||||||
reject(new Error('Failed to load image'));
|
if (mediaType === 'audio') {
|
||||||
};
|
element = new Audio();
|
||||||
|
element.preload = 'metadata';
|
||||||
img.src = url;
|
element.onloadedmetadata = onSuccess;
|
||||||
|
} else {
|
||||||
|
element = new Image();
|
||||||
|
element.onload = onSuccess;
|
||||||
|
}
|
||||||
|
element.onerror = () => reject(new Error('Failed to load resource'));
|
||||||
|
const cacheBustedUrl = new URL(url);
|
||||||
|
cacheBustedUrl.searchParams.set('t', Date.now());
|
||||||
|
element.src = cacheBustedUrl.toString();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -296,6 +296,7 @@
|
|||||||
},
|
},
|
||||||
"MEDIA": {
|
"MEDIA": {
|
||||||
"IMAGE_UNAVAILABLE": "This image is no longer available.",
|
"IMAGE_UNAVAILABLE": "This image is no longer available.",
|
||||||
|
"AUDIO_UNAVAILABLE": "This audio is no longer available.",
|
||||||
"LOADING_FAILED": "Loading failed"
|
"LOADING_FAILED": "Loading failed"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user