From 3809d3d4ac5050d80802adb74b78515f8209b1a9 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Fri, 12 Jul 2024 00:15:42 +0300
Subject: [PATCH] Add import confirmation
---
public/scripts/openai.js | 40 +++++++++++++++++++++++++++++++---------
1 file changed, 31 insertions(+), 9 deletions(-)
diff --git a/public/scripts/openai.js b/public/scripts/openai.js
index 84c0ee02d..391c0ee19 100644
--- a/public/scripts/openai.js
+++ b/public/scripts/openai.js
@@ -204,6 +204,15 @@ const custom_prompt_post_processing_types = {
CLAUDE: 'claude',
};
+const sensitiveFields = [
+ 'reverse_proxy',
+ 'proxy_password',
+ 'custom_url',
+ 'custom_include_body',
+ 'custom_exclude_body',
+ 'custom_include_headers',
+];
+
function getPrefixMap() {
return selected_group ? {
assistant: '',
@@ -3515,6 +3524,27 @@ async function onPresetImportFileChange(e) {
return;
}
+ const fields = sensitiveFields.filter(field => presetBody[field]).map(field => `${field}`);
+ const shouldConfirm = fields.length > 0;
+
+ if (shouldConfirm) {
+ const textHeader = 'The imported preset contains proxy and/or custom endpoint settings.';
+ const textMessage = fields.join('
');
+ const cancelButton = { text: 'Cancel import', result: POPUP_RESULT.CANCELLED, appendAtEnd: true, action: () => popup.complete(POPUP_RESULT.CANCELLED) };
+ const popupOptions = { customButtons: [cancelButton], okButton: 'Remove them', cancelButton: 'Import as-is' };
+ const popup = new Popup(PopupUtils.BuildTextWithHeader(textHeader, textMessage), POPUP_TYPE.CONFIRM, '', popupOptions);
+ const popupResult = await popup.show();
+
+ if (popupResult === POPUP_RESULT.CANCELLED) {
+ console.log('Import cancelled by user');
+ return;
+ }
+
+ if (popupResult === POPUP_RESULT.AFFIRMATIVE) {
+ sensitiveFields.forEach(field => delete presetBody[field]);
+ }
+ }
+
if (name in openai_setting_names) {
const confirm = await callPopup('Preset name already exists. Overwrite?', 'confirm');
@@ -3560,19 +3590,11 @@ async function onExportPresetClick() {
}
const preset = structuredClone(openai_settings[openai_setting_names[oai_settings.preset_settings_openai]]);
- const sensitiveFields = [
- 'reverse_proxy',
- 'proxy_password',
- 'custom_url',
- 'custom_include_body',
- 'custom_exclude_body',
- 'custom_include_headers',
- ];
const fieldValues = sensitiveFields.filter(field => preset[field]).map(field => `${field}: ${preset[field]}
`);
const shouldConfirm = fieldValues.length > 0;
const textHeader = 'Your preset contains proxy and/or custom endpoint settings.';
- const textMessage = `