fix: turn a large channel paste into a file when Paste Large Text as File is on (#31366)

This commit is contained in:
G30 2026-09-30 11:42:46 -04:00 • committed by GitHub
parent bff0492b5f
commit 3d46a59b2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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();
}
}
}
}