base64 preset support

This commit is contained in:
josc146 2023-10-27 13:35:29 +08:00
parent 6c73eae9f6
commit afd15ef2c5

View File

@ -168,8 +168,14 @@ export const ChatPresetEditor: FC<{
const importPreset = () => { const importPreset = () => {
ClipboardGetText().then((text) => { ClipboardGetText().then((text) => {
try { try {
if (!text.trim().startsWith('{'))
text = new TextDecoder().decode(
new Uint8Array(atob(text)
.split('')
.map((c) => c.charCodeAt(0))));
const preset = JSON.parse(text); const preset = JSON.parse(text);
setEditingPreset(preset); setEditingPreset(preset);
setEditingMessages(false);
toast(t('Imported successfully'), { toast(t('Imported successfully'), {
type: 'success', type: 'success',
autoClose: 1000 autoClose: 1000