mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 03:57:52 +00:00
chore: Always display the extension of an attached file (#10806)
This commit is contained in:
@@ -16,15 +16,41 @@ const { t } = useI18n();
|
|||||||
|
|
||||||
const fileName = computed(() => {
|
const fileName = computed(() => {
|
||||||
const url = attachment.dataUrl;
|
const url = attachment.dataUrl;
|
||||||
if (url) {
|
if (!url) return t('CONVERSATION.UNKNOWN_FILE_TYPE');
|
||||||
const filename = url.substring(url.lastIndexOf('/') + 1);
|
|
||||||
return filename || t('CONVERSATION.UNKNOWN_FILE_TYPE');
|
try {
|
||||||
|
const encodedFilename = url.substring(url.lastIndexOf('/') + 1);
|
||||||
|
return decodeURIComponent(encodedFilename);
|
||||||
|
} catch {
|
||||||
|
return t('CONVERSATION.UNKNOWN_FILE_TYPE');
|
||||||
}
|
}
|
||||||
return t('CONVERSATION.UNKNOWN_FILE_TYPE');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const fileType = computed(() => {
|
const fileType = computed(() => fileName.value.split('.').pop()?.toLowerCase());
|
||||||
return fileName.value.split('.').pop();
|
|
||||||
|
const fileNameWithoutExt = computed(() => {
|
||||||
|
const parts = fileName.value.split('.');
|
||||||
|
|
||||||
|
// If there's no extension (no dots in filename)
|
||||||
|
if (parts.length === 1) {
|
||||||
|
return fileName.value.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Take all parts except the last one (extension)
|
||||||
|
const nameWithoutExt = parts.slice(0, -1).join('.');
|
||||||
|
return nameWithoutExt.trim();
|
||||||
|
});
|
||||||
|
|
||||||
|
const displayFileName = computed(() => {
|
||||||
|
const name = fileNameWithoutExt.value;
|
||||||
|
const truncatedName = (str, maxLength, hasExt) =>
|
||||||
|
str.length > maxLength
|
||||||
|
? `${str.substring(0, maxLength).trimEnd()}${hasExt ? '..' : '...'}`
|
||||||
|
: str;
|
||||||
|
|
||||||
|
return fileType.value
|
||||||
|
? `${truncatedName(name, 14, true)}.${fileType.value}`
|
||||||
|
: truncatedName(name, 16, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
const textColorClass = computed(() => {
|
const textColorClass = computed(() => {
|
||||||
@@ -53,15 +79,19 @@ const textColorClass = computed(() => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="h-9 bg-n-alpha-white gap-2 items-center flex px-2 rounded-lg border border-n-container"
|
class="h-9 bg-n-alpha-white gap-2 overflow-hidden items-center flex px-2 rounded-lg border border-n-container"
|
||||||
>
|
>
|
||||||
<FileIcon class="flex-shrink-0" :file-type="fileType" />
|
<FileIcon class="flex-shrink-0" :file-type="fileType" />
|
||||||
<span class="mr-1 max-w-32 truncate" :class="textColorClass">
|
<span
|
||||||
{{ fileName }}
|
class="flex-1 min-w-0 text-sm max-w-36"
|
||||||
|
:title="fileName"
|
||||||
|
:class="textColorClass"
|
||||||
|
>
|
||||||
|
{{ displayFileName }}
|
||||||
</span>
|
</span>
|
||||||
<a
|
<a
|
||||||
v-tooltip="t('CONVERSATION.DOWNLOAD')"
|
v-tooltip="t('CONVERSATION.DOWNLOAD')"
|
||||||
class="flex-shrink-0 h-9 grid place-content-center cursor-pointer text-n-slate-11"
|
class="flex-shrink-0 size-9 grid place-content-center cursor-pointer text-n-slate-11 hover:text-n-slate-12 transition-colors"
|
||||||
:href="attachment.dataUrl"
|
:href="attachment.dataUrl"
|
||||||
rel="noreferrer noopener nofollow"
|
rel="noreferrer noopener nofollow"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
|
|||||||
Reference in New Issue
Block a user