Add import confirmation
| @@ -204,6 +204,15 @@ const custom_prompt_post_processing_types = { | ||
| 204 | 204 | CLAUDE: 'claude', |
| 205 | 205 | }; |
| 206 | 206 | |
| 207 | +const sensitiveFields = [ | |
| 208 | + 'reverse_proxy', | |
| 209 | + 'proxy_password', | |
| 210 | + 'custom_url', | |
| 211 | + 'custom_include_body', | |
| 212 | + 'custom_exclude_body', | |
| 213 | + 'custom_include_headers', | |
| 214 | +]; | |
| 215 | + | |
| 207 | 216 | function getPrefixMap() { |
| 208 | 217 | return selected_group ? { |
| 209 | 218 | assistant: '', |
| @@ -3515,6 +3524,27 @@ async function onPresetImportFileChange(e) { | ||
| 3515 | 3524 | return; |
| 3516 | 3525 | } |
| 3517 | 3526 | |
| 3527 | + const fields = sensitiveFields.filter(field => presetBody[field]).map(field => `<b>${field}</b>`); | |
| 3528 | + const shouldConfirm = fields.length > 0; | |
| 3529 | + | |
| 3530 | + if (shouldConfirm) { | |
| 3531 | + const textHeader = 'The imported preset contains proxy and/or custom endpoint settings.'; | |
| 3532 | + const textMessage = fields.join('<br>'); | |
| 3533 | + const cancelButton = { text: 'Cancel import', result: POPUP_RESULT.CANCELLED, appendAtEnd: true, action: () => popup.complete(POPUP_RESULT.CANCELLED) }; | |
| 3534 | + const popupOptions = { customButtons: [cancelButton], okButton: 'Remove them', cancelButton: 'Import as-is' }; | |
| 3535 | + const popup = new Popup(PopupUtils.BuildTextWithHeader(textHeader, textMessage), POPUP_TYPE.CONFIRM, '', popupOptions); | |
| 3536 | + const popupResult = await popup.show(); | |
| 3537 | + | |
| 3538 | + if (popupResult === POPUP_RESULT.CANCELLED) { | |
| 3539 | + console.log('Import cancelled by user'); | |
| 3540 | + return; | |
| 3541 | + } | |
| 3542 | + | |
| 3543 | + if (popupResult === POPUP_RESULT.AFFIRMATIVE) { | |
| 3544 | + sensitiveFields.forEach(field => delete presetBody[field]); | |
| 3545 | + } | |
| 3546 | + } | |
| 3547 | + | |
| 3518 | 3548 | if (name in openai_setting_names) { |
| 3519 | 3549 | const confirm = await callPopup('Preset name already exists. Overwrite?', 'confirm'); |
| 3520 | 3550 | |
| @@ -3560,19 +3590,11 @@ async function onExportPresetClick() { | ||
| 3560 | 3590 | } |
| 3561 | 3591 | |
| 3562 | 3592 | const preset = structuredClone(openai_settings[openai_setting_names[oai_settings.preset_settings_openai]]); |
| 3563 | - const sensitiveFields = [ | |
| 3564 | - 'reverse_proxy', | |
| 3565 | - 'proxy_password', | |
| 3566 | - 'custom_url', | |
| 3567 | - 'custom_include_body', | |
| 3568 | - 'custom_exclude_body', | |
| 3569 | - 'custom_include_headers', | |
| 3570 | - ]; | |
| 3571 | 3593 | |
| 3572 | 3594 | const fieldValues = sensitiveFields.filter(field => preset[field]).map(field => `<b>${field}</b>: <code>${preset[field]}</code>`); |
| 3573 | 3595 | const shouldConfirm = fieldValues.length > 0; |
| 3574 | 3596 | const textHeader = 'Your preset contains proxy and/or custom endpoint settings.'; |
| 3575 | 3597 | const textMessage = `<div>Do you want to remove these fields before exporting?</div><br>${DOMPurify.sanitize(fieldValues.join('<br>'))}`; |
| 3576 | 3598 | const cancelButton = { text: 'Cancel', result: POPUP_RESULT.CANCELLED, appendAtEnd: true, action: () => popup.complete(POPUP_RESULT.CANCELLED) }; |
| 3577 | 3599 | const popupOptions = { customButtons: [cancelButton] }; |
| 3578 | 3600 | const popup = new Popup(PopupUtils.BuildTextWithHeader(textHeader, textMessage), POPUP_TYPE.CONFIRM, '', popupOptions); |