diff --git a/src/lib/components/channel/MessageInput.svelte b/src/lib/components/channel/MessageInput.svelte index ff432ae89a..c7db91a448 100644 --- a/src/lib/components/channel/MessageInput.svelte +++ b/src/lib/components/channel/MessageInput.svelte @@ -24,7 +24,7 @@ import { getSessionUser } from '$lib/apis/auths'; import { uploadFile } from '$lib/apis/files'; - import { WEBUI_API_BASE_URL } from '$lib/constants'; + import { WEBUI_API_BASE_URL, PASTED_TEXT_CHARACTER_LIMIT } from '$lib/constants'; import { getSuggestionRenderer } from '../common/RichTextInput/suggestions'; import CommandSuggestionList from '../chat/MessageInput/CommandSuggestionList.svelte'; @@ -971,10 +971,26 @@ if (clipboardData && clipboardData.items) { for (const item of clipboardData.items) { - const file = item.getAsFile(); - if (file) { - await inputFilesHandler([file]); - e.preventDefault(); + if (item.type === 'text/plain') { + if ($settings?.largeTextAsFile ?? false) { + const text = clipboardData.getData('text/plain'); + + if (text.length > PASTED_TEXT_CHARACTER_LIMIT) { + e.preventDefault(); + const blob = new Blob([text], { type: 'text/plain' }); + const file = new File([blob], `Pasted_Text_${Date.now()}.txt`, { + type: 'text/plain' + }); + + await uploadFileHandler(file); + } + } + } else { + const file = item.getAsFile(); + if (file) { + await inputFilesHandler([file]); + e.preventDefault(); + } } } }