enh: large pasted text as file

Co-Authored-By: Taylor Wilsdon <6508528+taylorwilsdon@users.noreply.github.com>
This commit is contained in:
Timothy Jaeryang Baek
2024-11-18 20:50:12 -08:00
parent 8bb3061101
commit 11e78eac91
3 changed files with 36 additions and 1 deletions

View File

@@ -23,7 +23,7 @@
import { uploadFile } from '$lib/apis/files';
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 InputMenu from './MessageInput/InputMenu.svelte';
@@ -772,6 +772,18 @@
};
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);
} 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);
}
}
}
}