mirror of
https://github.com/open-webui/open-webui
synced 2024-11-25 13:29:53 +00:00
enh: make large text as file toggleable
This commit is contained in:
parent
11e78eac91
commit
9ea1c45641
@ -91,7 +91,7 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const uploadFileHandler = async (file) => {
|
const uploadFileHandler = async (file, fullContext: boolean = false) => {
|
||||||
if ($_user?.role !== 'admin' && !($_user?.permissions?.chat?.file_upload ?? true)) {
|
if ($_user?.role !== 'admin' && !($_user?.permissions?.chat?.file_upload ?? true)) {
|
||||||
toast.error($i18n.t('You do not have permission to upload files.'));
|
toast.error($i18n.t('You do not have permission to upload files.'));
|
||||||
return null;
|
return null;
|
||||||
@ -110,7 +110,8 @@
|
|||||||
status: 'uploading',
|
status: 'uploading',
|
||||||
size: file.size,
|
size: file.size,
|
||||||
error: '',
|
error: '',
|
||||||
itemId: tempItemId
|
itemId: tempItemId,
|
||||||
|
...(fullContext ? { context: 'full' } : {})
|
||||||
};
|
};
|
||||||
|
|
||||||
if (fileItem.size == 0) {
|
if (fileItem.size == 0) {
|
||||||
@ -619,6 +620,7 @@
|
|||||||
id="chat-input"
|
id="chat-input"
|
||||||
trim={true}
|
trim={true}
|
||||||
placeholder={placeholder ? placeholder : $i18n.t('Send a Message')}
|
placeholder={placeholder ? placeholder : $i18n.t('Send a Message')}
|
||||||
|
largeTextAsFile={$settings?.largeTextAsFile ?? false}
|
||||||
bind:value={prompt}
|
bind:value={prompt}
|
||||||
shiftEnter={!$mobile ||
|
shiftEnter={!$mobile ||
|
||||||
!(
|
!(
|
||||||
@ -773,6 +775,7 @@
|
|||||||
|
|
||||||
reader.readAsDataURL(blob);
|
reader.readAsDataURL(blob);
|
||||||
} else if (item.type === 'text/plain') {
|
} else if (item.type === 'text/plain') {
|
||||||
|
if ($settings?.largeTextAsFile ?? false) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const text = await clipboardData.getData('text/plain');
|
const text = await clipboardData.getData('text/plain');
|
||||||
|
|
||||||
@ -782,7 +785,8 @@
|
|||||||
type: 'text/plain'
|
type: 'text/plain'
|
||||||
});
|
});
|
||||||
|
|
||||||
await uploadFileHandler(file);
|
await uploadFileHandler(file, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -961,6 +965,7 @@
|
|||||||
|
|
||||||
reader.readAsDataURL(blob);
|
reader.readAsDataURL(blob);
|
||||||
} else if (item.type === 'text/plain') {
|
} else if (item.type === 'text/plain') {
|
||||||
|
if ($settings?.largeTextAsFile ?? false) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const text = await clipboardData.getData('text/plain');
|
const text = await clipboardData.getData('text/plain');
|
||||||
|
|
||||||
@ -970,7 +975,8 @@
|
|||||||
type: 'text/plain'
|
type: 'text/plain'
|
||||||
});
|
});
|
||||||
|
|
||||||
await uploadFileHandler(file);
|
await uploadFileHandler(file, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
let defaultModelId = '';
|
let defaultModelId = '';
|
||||||
let showUsername = false;
|
let showUsername = false;
|
||||||
let richTextInput = true;
|
let richTextInput = true;
|
||||||
|
let largeTextAsFile = false;
|
||||||
|
|
||||||
let landingPageMode = '';
|
let landingPageMode = '';
|
||||||
let chatBubble = true;
|
let chatBubble = true;
|
||||||
@ -139,6 +140,11 @@
|
|||||||
saveSettings({ richTextInput });
|
saveSettings({ richTextInput });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toggleLargeTextAsFile = async () => {
|
||||||
|
largeTextAsFile = !largeTextAsFile;
|
||||||
|
saveSettings({ largeTextAsFile });
|
||||||
|
};
|
||||||
|
|
||||||
const toggleResponseAutoCopy = async () => {
|
const toggleResponseAutoCopy = async () => {
|
||||||
const permission = await navigator.clipboard
|
const permission = await navigator.clipboard
|
||||||
.readText()
|
.readText()
|
||||||
@ -188,6 +194,8 @@
|
|||||||
voiceInterruption = $settings.voiceInterruption ?? false;
|
voiceInterruption = $settings.voiceInterruption ?? false;
|
||||||
|
|
||||||
richTextInput = $settings.richTextInput ?? true;
|
richTextInput = $settings.richTextInput ?? true;
|
||||||
|
largeTextAsFile = $settings.largeTextAsFile ?? false;
|
||||||
|
|
||||||
landingPageMode = $settings.landingPageMode ?? '';
|
landingPageMode = $settings.landingPageMode ?? '';
|
||||||
chatBubble = $settings.chatBubble ?? true;
|
chatBubble = $settings.chatBubble ?? true;
|
||||||
widescreenMode = $settings.widescreenMode ?? false;
|
widescreenMode = $settings.widescreenMode ?? false;
|
||||||
@ -480,6 +488,28 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div class=" py-0.5 flex w-full justify-between">
|
||||||
|
<div class=" self-center text-xs">
|
||||||
|
{$i18n.t('Paste Large Text as File')}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
class="p-1 px-3 text-xs flex rounded transition"
|
||||||
|
on:click={() => {
|
||||||
|
toggleLargeTextAsFile();
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
{#if largeTextAsFile === true}
|
||||||
|
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
||||||
|
{:else}
|
||||||
|
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class=" py-0.5 flex w-full justify-between">
|
<div class=" py-0.5 flex w-full justify-between">
|
||||||
<div class=" self-center text-xs">
|
<div class=" self-center text-xs">
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
export let className = 'input-prose';
|
export let className = 'input-prose';
|
||||||
export let shiftEnter = false;
|
export let shiftEnter = false;
|
||||||
|
export let largeTextAsFile = false;
|
||||||
|
|
||||||
export let id = '';
|
export let id = '';
|
||||||
export let value = '';
|
export let value = '';
|
||||||
@ -413,12 +414,14 @@
|
|||||||
// 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 (largeTextAsFile) {
|
||||||
if (plainText.length > PASTED_TEXT_CHARACTER_LIMIT) {
|
if (plainText.length > PASTED_TEXT_CHARACTER_LIMIT) {
|
||||||
// Dispatch paste event to parent component
|
// Dispatch paste event to parent component
|
||||||
eventDispatch('paste', { event });
|
eventDispatch('paste', { event });
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const modifiedText = handleTabIndentation(plainText);
|
const modifiedText = handleTabIndentation(plainText);
|
||||||
console.log(modifiedText);
|
console.log(modifiedText);
|
||||||
|
Loading…
Reference in New Issue
Block a user