mirror of
https://github.com/open-webui/open-webui
synced 2024-11-25 13:29:53 +00:00
enh: large pasted text as file
Co-Authored-By: Taylor Wilsdon <6508528+taylorwilsdon@users.noreply.github.com>
This commit is contained in:
parent
8bb3061101
commit
11e78eac91
@ -23,7 +23,7 @@
|
|||||||
import { uploadFile } from '$lib/apis/files';
|
import { uploadFile } from '$lib/apis/files';
|
||||||
import { getTools } from '$lib/apis/tools';
|
import { getTools } from '$lib/apis/tools';
|
||||||
|
|
||||||
import { WEBUI_BASE_URL, WEBUI_API_BASE_URL } from '$lib/constants';
|
import { WEBUI_BASE_URL, WEBUI_API_BASE_URL, PASTED_TEXT_CHARACTER_LIMIT } from '$lib/constants';
|
||||||
|
|
||||||
import Tooltip from '../common/Tooltip.svelte';
|
import Tooltip from '../common/Tooltip.svelte';
|
||||||
import InputMenu from './MessageInput/InputMenu.svelte';
|
import InputMenu from './MessageInput/InputMenu.svelte';
|
||||||
@ -772,6 +772,18 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
reader.readAsDataURL(blob);
|
reader.readAsDataURL(blob);
|
||||||
|
} else if (item.type === 'text/plain') {
|
||||||
|
e.preventDefault();
|
||||||
|
const text = await clipboardData.getData('text/plain');
|
||||||
|
|
||||||
|
if (text.length > PASTED_TEXT_CHARACTER_LIMIT) {
|
||||||
|
const blob = new Blob([text], { type: 'text/plain' });
|
||||||
|
const file = new File([blob], `Pasted_Text_${Date.now()}.txt`, {
|
||||||
|
type: 'text/plain'
|
||||||
|
});
|
||||||
|
|
||||||
|
await uploadFileHandler(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -948,6 +960,18 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
reader.readAsDataURL(blob);
|
reader.readAsDataURL(blob);
|
||||||
|
} else if (item.type === 'text/plain') {
|
||||||
|
e.preventDefault();
|
||||||
|
const text = await clipboardData.getData('text/plain');
|
||||||
|
|
||||||
|
if (text.length > PASTED_TEXT_CHARACTER_LIMIT) {
|
||||||
|
const blob = new Blob([text], { type: 'text/plain' });
|
||||||
|
const file = new File([blob], `Pasted_Text_${Date.now()}.txt`, {
|
||||||
|
type: 'text/plain'
|
||||||
|
});
|
||||||
|
|
||||||
|
await uploadFileHandler(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
import { keymap } from 'prosemirror-keymap';
|
import { keymap } from 'prosemirror-keymap';
|
||||||
import { baseKeymap, chainCommands } from 'prosemirror-commands';
|
import { baseKeymap, chainCommands } from 'prosemirror-commands';
|
||||||
import { DOMParser, DOMSerializer, Schema, Fragment } from 'prosemirror-model';
|
import { DOMParser, DOMSerializer, Schema, Fragment } from 'prosemirror-model';
|
||||||
|
import { PASTED_TEXT_CHARACTER_LIMIT } from '$lib/constants';
|
||||||
|
|
||||||
export let className = 'input-prose';
|
export let className = 'input-prose';
|
||||||
export let shiftEnter = false;
|
export let shiftEnter = false;
|
||||||
@ -412,6 +413,13 @@
|
|||||||
// Extract plain text from clipboard and paste it without formatting
|
// Extract plain text from clipboard and paste it without formatting
|
||||||
const plainText = event.clipboardData.getData('text/plain');
|
const plainText = event.clipboardData.getData('text/plain');
|
||||||
if (plainText) {
|
if (plainText) {
|
||||||
|
if (plainText.length > PASTED_TEXT_CHARACTER_LIMIT) {
|
||||||
|
// Dispatch paste event to parent component
|
||||||
|
eventDispatch('paste', { event });
|
||||||
|
event.preventDefault();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const modifiedText = handleTabIndentation(plainText);
|
const modifiedText = handleTabIndentation(plainText);
|
||||||
console.log(modifiedText);
|
console.log(modifiedText);
|
||||||
|
|
||||||
|
@ -95,6 +95,9 @@ export const SUPPORTED_FILE_EXTENSIONS = [
|
|||||||
'msg'
|
'msg'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
export const PASTED_TEXT_CHARACTER_LIMIT = 1000;
|
||||||
|
|
||||||
// Source: https://kit.svelte.dev/docs/modules#$env-static-public
|
// Source: https://kit.svelte.dev/docs/modules#$env-static-public
|
||||||
// This feature, akin to $env/static/private, exclusively incorporates environment variables
|
// This feature, akin to $env/static/private, exclusively incorporates environment variables
|
||||||
// that are prefixed with config.kit.env.publicPrefix (usually set to PUBLIC_).
|
// that are prefixed with config.kit.env.publicPrefix (usually set to PUBLIC_).
|
||||||
|
Loading…
Reference in New Issue
Block a user