mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-23 01:35:23 +00:00
refac
This commit is contained in:
parent
fa924946b0
commit
a1155dfeb7
1 changed files with 11 additions and 34 deletions
|
|
@ -112,27 +112,21 @@
|
||||||
|
|
||||||
const clipboardItems = await navigator.clipboard.read();
|
const clipboardItems = await navigator.clipboard.read();
|
||||||
|
|
||||||
let imageUrl = null;
|
|
||||||
for (const item of clipboardItems) {
|
for (const item of clipboardItems) {
|
||||||
// Check for known image types
|
// Check for known image types
|
||||||
for (const type of item.types) {
|
for (const type of item.types) {
|
||||||
if (type.startsWith('image/')) {
|
if (type.startsWith('image/')) {
|
||||||
|
// get as file
|
||||||
const blob = await item.getType(type);
|
const blob = await item.getType(type);
|
||||||
imageUrl = URL.createObjectURL(blob);
|
const file = new File([blob], `clipboard-image.${type.split('/')[1]}`, {
|
||||||
|
type: type
|
||||||
|
});
|
||||||
|
|
||||||
|
inputFilesHandler([file]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imageUrl) {
|
|
||||||
files = [
|
|
||||||
...files,
|
|
||||||
{
|
|
||||||
type: 'image',
|
|
||||||
url: imageUrl
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
text = text.replaceAll('{{CLIPBOARD}}', clipboardText);
|
text = text.replaceAll('{{CLIPBOARD}}', clipboardText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -931,28 +925,11 @@
|
||||||
|
|
||||||
if (clipboardData && clipboardData.items) {
|
if (clipboardData && clipboardData.items) {
|
||||||
for (const item of clipboardData.items) {
|
for (const item of clipboardData.items) {
|
||||||
if (item.type.indexOf('image') !== -1) {
|
const file = item.getAsFile();
|
||||||
const blob = item.getAsFile();
|
if (file) {
|
||||||
const reader = new FileReader();
|
const _files = [file];
|
||||||
|
await inputFilesHandler(_files);
|
||||||
reader.onload = function (e) {
|
e.preventDefault();
|
||||||
files = [
|
|
||||||
...files,
|
|
||||||
{
|
|
||||||
type: 'image',
|
|
||||||
url: `${e.target.result}`
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
reader.readAsDataURL(blob);
|
|
||||||
} else if (item?.kind === 'file') {
|
|
||||||
const file = item.getAsFile();
|
|
||||||
if (file) {
|
|
||||||
const _files = [file];
|
|
||||||
await inputFilesHandler(_files);
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue