Add buttons to remove SD/translate secrets

1842a8ee6d0dca1d80d1467c1ad038f4dfc69bb6

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

2 files changed, +29 -7Ignore whitespace
public/scripts/extensions/stable-diffusion/index.js+16 -5
@@ -30,7 +30,7 @@ import { SlashCommand } from '../../slash-commands/SlashCommand.js';
3030import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
3131import { debounce_timeout } from '../../constants.js';
3232import { SlashCommandEnumValue } from '../../slash-commands/SlashCommandEnumValue.js';
3333import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from '../../popup.js';
3434export { MODULE_NAME };
3535
3636const MODULE_NAME = 'sd';
@@ -1097,7 +1097,18 @@ function onComfyWorkflowChange() {
10971097
10981098async function onStabilityKeyClick() {
10991099 const popupText = 'Stability AI API Key:';
11001100 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
11021113 if (!key) {
11031114 return;
@@ -2693,15 +2704,15 @@ async function generateBlockEntropyImage(prompt, negativePrompt, signal) {
26932704
26942705 if (result.ok) {
26952706 const data = await result.json();
2696-
2707+
26972708 // Default format is 'jpg'
26982709 let format = 'jpg';
2699-
2710+
27002711 // Check if a format is specified in the result
27012712 if (data.format) {
27022713 format = data.format.toLowerCase();
27032714 }
2704-
2715+
27052716 return { format: format, data: data.images[0] };
27062717 } else {
27072718 const text = await result.text();
public/scripts/extensions/translate/index.js+13 -2
@@ -10,7 +10,7 @@ import {
1010 updateMessageBlock,
1111} from '../../../script.js';
1212import { extension_settings, getContext, renderExtensionTemplateAsync } from '../../extensions.js';
1313import { POPUP_RESULT, POPUP_TYPE, callGenericPopup } from '../../popup.js';
1414import { findSecret, secret_state, writeSecret } from '../../secrets.js';
1515import { SlashCommand } from '../../slash-commands/SlashCommand.js';
1616import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
@@ -621,7 +621,18 @@ jQuery(async () => {
621621 const secretKey = extension_settings.translate.provider + '_url';
622622 const savedUrl = secret_state[secretKey] ? await findSecret(secretKey) : '';
623623
624624 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
626637 if (url == false || url == '') {
627638 return;