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';
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;
@@ -2693,15 +2704,15 @@ async function generateBlockEntropyImage(prompt, negativePrompt, signal) {
26932704
2694 if (result.ok) {2705 if (result.ok) {
2695 const data = await result.json();2706 const data = await result.json();
2696 2707
2697 // Default format is 'jpg'2708 // Default format is 'jpg'
2698 let format = 'jpg';2709 let format = 'jpg';
2699 2710
2700 // Check if a format is specified in the result2711 // Check if a format is specified in the result
2701 if (data.format) {2712 if (data.format) {
2702 format = data.format.toLowerCase();2713 format = data.format.toLowerCase();
2703 }2714 }
2704 2715
2705 return { format: format, data: data.images[0] };2716 return { format: format, data: data.images[0] };
2706 } else {2717 } else {
2707 const text = await result.text();2718 const text = await result.text();
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;