Add buttons to remove SD/translate secrets

1842a8ee6d0dca1d80d1467c1ad038f4dfc69bb6

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +26 -4Showing whitespace changes
public/scripts/extensions/stable-diffusion/index.js+13 -2
@@ -30,7 +30,7 @@ import { SlashCommand } from '../../slash-commands/SlashCommand.js';
30import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';30import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
31import { debounce_timeout } from '../../constants.js';31import { debounce_timeout } from '../../constants.js';
32import { SlashCommandEnumValue } from '../../slash-commands/SlashCommandEnumValue.js';32import { SlashCommandEnumValue } from '../../slash-commands/SlashCommandEnumValue.js';
33import { POPUP_TYPE, Popup, callGenericPopup } from '../../popup.js';33import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from '../../popup.js';
34export { MODULE_NAME };34export { MODULE_NAME };
3535
36const MODULE_NAME = 'sd';36const MODULE_NAME = 'sd';
@@ -1097,7 +1097,18 @@ function onComfyWorkflowChange() {
10971097
1098async function onStabilityKeyClick() {1098async function onStabilityKeyClick() {
1099 const popupText = 'Stability AI API Key:';1099 const popupText = 'Stability AI API Key:';
1100 const key = await callGenericPopup(popupText, POPUP_TYPE.INPUT);1100 const key = await callGenericPopup(popupText, POPUP_TYPE.INPUT, '', {
1101 customButtons: [{
1102 text: 'Remove Key',
1103 appendAtEnd: true,
1104 result: POPUP_RESULT.NEGATIVE,
1105 action: async () => {
1106 await writeSecret(SECRET_KEYS.STABILITY, '');
1107 toastr.success('API Key removed');
1108 await loadSettingOptions();
1109 },
1110 }],
1111 });
11011112
1102 if (!key) {1113 if (!key) {
1103 return;1114 return;
public/scripts/extensions/translate/index.js+13 -2
@@ -10,7 +10,7 @@ import {
10 updateMessageBlock,10 updateMessageBlock,
11} from '../../../script.js';11} from '../../../script.js';
12import { extension_settings, getContext, renderExtensionTemplateAsync } from '../../extensions.js';12import { extension_settings, getContext, renderExtensionTemplateAsync } from '../../extensions.js';
13import { POPUP_TYPE, callGenericPopup } from '../../popup.js';13import { POPUP_RESULT, POPUP_TYPE, callGenericPopup } from '../../popup.js';
14import { findSecret, secret_state, writeSecret } from '../../secrets.js';14import { findSecret, secret_state, writeSecret } from '../../secrets.js';
15import { SlashCommand } from '../../slash-commands/SlashCommand.js';15import { SlashCommand } from '../../slash-commands/SlashCommand.js';
16import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';16import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
@@ -621,7 +621,18 @@ jQuery(async () => {
621 const secretKey = extension_settings.translate.provider + '_url';621 const secretKey = extension_settings.translate.provider + '_url';
622 const savedUrl = secret_state[secretKey] ? await findSecret(secretKey) : '';622 const savedUrl = secret_state[secretKey] ? await findSecret(secretKey) : '';
623623
624 const url = await callGenericPopup(popupText, POPUP_TYPE.INPUT, savedUrl);624 const url = await callGenericPopup(popupText, POPUP_TYPE.INPUT, savedUrl,{
625 customButtons: [{
626 text: 'Remove URL',
627 appendAtEnd: true,
628 result: POPUP_RESULT.NEGATIVE,
629 action: async () => {
630 await writeSecret(secretKey, '');
631 toastr.success('API URL removed');
632 $('#translate_url_button').toggleClass('success', !!secret_state[secretKey]);
633 },
634 }],
635 });
625636
626 if (url == false || url == '') {637 if (url == false || url == '') {
627 return;638 return;