Use deepMerge to combine payloads
| @@ -18,7 +18,7 @@ import { | |||
| 18 | } from '../../../script.js'; | 18 | } from '../../../script.js'; |
| 19 | import { getApiUrl, getContext, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync, writeExtensionField } from '../../extensions.js'; | 19 | import { getApiUrl, getContext, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync, writeExtensionField } from '../../extensions.js'; |
| 20 | import { selected_group } from '../../group-chats.js'; | 20 | import { selected_group } from '../../group-chats.js'; |
| 21 | import { stringFormat, initScrollHeight, resetScrollHeight, getCharaFilename, saveBase64AsFile, getBase64Async, delay, isTrueBoolean, debounce, isFalseBoolean } from '../../utils.js'; | 21 | import { stringFormat, initScrollHeight, resetScrollHeight, getCharaFilename, saveBase64AsFile, getBase64Async, delay, isTrueBoolean, debounce, isFalseBoolean, deepMerge } from '../../utils.js'; |
| 22 | import { getMessageTimeStamp, humanizedDateTime } from '../../RossAscends-mods.js'; | 22 | import { getMessageTimeStamp, humanizedDateTime } from '../../RossAscends-mods.js'; |
| 23 | import { SECRET_KEYS, secret_state, writeSecret } from '../../secrets.js'; | 23 | import { SECRET_KEYS, secret_state, writeSecret } from '../../secrets.js'; |
| 24 | import { getNovelUnlimitedImageGeneration, getNovelAnlas, loadNovelSubscriptionData } from '../../nai-settings.js'; | 24 | import { getNovelUnlimitedImageGeneration, getNovelAnlas, loadNovelSubscriptionData } from '../../nai-settings.js'; |
| @@ -219,7 +219,7 @@ const defaultSettings = { | |||
| 219 | // Automatic1111/Horde exclusives | 219 | // Automatic1111/Horde exclusives |
| 220 | restore_faces: false, | 220 | restore_faces: false, |
| 221 | enable_hr: false, | 221 | enable_hr: false, |
| 222 | aiFaceDetailer: false, | 222 | adetailer_face: false, |
| 223 | 223 | ||
| 224 | // Horde settings | 224 | // Horde settings |
| 225 | horde: false, | 225 | horde: false, |
| @@ -436,7 +436,7 @@ async function loadSettings() { | |||
| 436 | $('#sd_horde_sanitize').prop('checked', extension_settings.sd.horde_sanitize); | 436 | $('#sd_horde_sanitize').prop('checked', extension_settings.sd.horde_sanitize); |
| 437 | $('#sd_restore_faces').prop('checked', extension_settings.sd.restore_faces); | 437 | $('#sd_restore_faces').prop('checked', extension_settings.sd.restore_faces); |
| 438 | $('#sd_enable_hr').prop('checked', extension_settings.sd.enable_hr); | 438 | $('#sd_enable_hr').prop('checked', extension_settings.sd.enable_hr); |
| 439 | $('#sd_aiFaceDetailer').prop('checked', extension_settings.sd.aiFaceDetailer); | 439 | $('#sd_adetailer_face').prop('checked', extension_settings.sd.adetailer_face); |
| 440 | $('#sd_refine_mode').prop('checked', extension_settings.sd.refine_mode); | 440 | $('#sd_refine_mode').prop('checked', extension_settings.sd.refine_mode); |
| 441 | $('#sd_multimodal_captioning').prop('checked', extension_settings.sd.multimodal_captioning); | 441 | $('#sd_multimodal_captioning').prop('checked', extension_settings.sd.multimodal_captioning); |
| 442 | $('#sd_auto_url').val(extension_settings.sd.auto_url); | 442 | $('#sd_auto_url').val(extension_settings.sd.auto_url); |
| @@ -855,8 +855,8 @@ function onSamplerChange() { | |||
| 855 | saveSettingsDebounced(); | 855 | saveSettingsDebounced(); |
| 856 | } | 856 | } |
| 857 | 857 | ||
| 858 | function onAiFaceDetailerChange() { | 858 | function onADetailerFaceChange() { |
| 859 | extension_settings.sd.aiFaceDetailer = $('#sd_aiFaceDetailer').prop('checked'); | 859 | extension_settings.sd.adetailer_face = !!$('#sd_adetailer_face').prop('checked'); |
| 860 | saveSettingsDebounced(); | 860 | saveSettingsDebounced(); |
| 861 | } | 861 | } |
| 862 | 862 | ||
| @@ -2955,20 +2955,22 @@ async function generateAutoImage(prompt, negativePrompt, signal) { | |||
| 2955 | do_not_save_grid: false, | 2955 | do_not_save_grid: false, |
| 2956 | do_not_save_samples: false, | 2956 | do_not_save_samples: false, |
| 2957 | }; | 2957 | }; |
| 2958 | // Conditionally add the ADetailer if aiFaceDetailer is enabled | 2958 | |
| 2959 | console.log('extension_settings.sd.aiFaceDetailer:', extension_settings.sd.aiFaceDetailer); | 2959 | // Conditionally add the ADetailer if adetailer_face is enabled |
| 2960 | if (extension_settings.sd.aiFaceDetailer) { | 2960 | if (extension_settings.sd.adetailer_face) { |
| 2961 | payload.alwayson_scripts = { | 2961 | payload = deepMerge(payload, { |
| 2962 | ADetailer: { | 2962 | alwayson_scripts: { |
| 2963 | args: [ | 2963 | ADetailer: { |
| 2964 | true, // ad_enable | 2964 | args: [ |
| 2965 | true, // skip_img2img | 2965 | true, // ad_enable |
| 2966 | { | 2966 | true, // skip_img2img |
| 2967 | "ad_model": "face_yolov8n.pt" | 2967 | { |
| 2968 | } | 2968 | 'ad_model': 'face_yolov8n.pt', |
| 2969 | ] | 2969 | }, |
| 2970 | } | 2970 | ], |
| 2971 | }; | 2971 | }, |
| 2972 | }, | ||
| 2973 | }); | ||
| 2972 | } | 2974 | } |
| 2973 | 2975 | ||
| 2974 | // Make the fetch call with the payload | 2976 | // Make the fetch call with the payload |
| @@ -2978,8 +2980,6 @@ async function generateAutoImage(prompt, negativePrompt, signal) { | |||
| 2978 | signal: signal, | 2980 | signal: signal, |
| 2979 | body: JSON.stringify(payload), | 2981 | body: JSON.stringify(payload), |
| 2980 | }); | 2982 | }); |
| 2981 | |||
| 2982 | |||
| 2983 | 2983 | ||
| 2984 | if (result.ok) { | 2984 | if (result.ok) { |
| 2985 | const data = await result.json(); | 2985 | const data = await result.json(); |
| @@ -4210,7 +4210,7 @@ jQuery(async () => { | |||
| 4210 | $('#sd_horde_sanitize').on('input', onHordeSanitizeInput); | 4210 | $('#sd_horde_sanitize').on('input', onHordeSanitizeInput); |
| 4211 | $('#sd_restore_faces').on('input', onRestoreFacesInput); | 4211 | $('#sd_restore_faces').on('input', onRestoreFacesInput); |
| 4212 | $('#sd_enable_hr').on('input', onHighResFixInput); | 4212 | $('#sd_enable_hr').on('input', onHighResFixInput); |
| 4213 | $('#sd_aiFaceDetailer').on('change', onAiFaceDetailerChange); | 4213 | $('#sd_adetailer_face').on('change', onADetailerFaceChange); |
| 4214 | $('#sd_refine_mode').on('input', onRefineModeInput); | 4214 | $('#sd_refine_mode').on('input', onRefineModeInput); |
| 4215 | $('#sd_character_prompt').on('input', onCharacterPromptInput); | 4215 | $('#sd_character_prompt').on('input', onCharacterPromptInput); |
| 4216 | $('#sd_character_negative_prompt').on('input', onCharacterNegativePromptInput); | 4216 | $('#sd_character_negative_prompt').on('input', onCharacterNegativePromptInput); |
| @@ -354,11 +354,16 @@ | |||
| 354 | <small data-i18n="Karras">Karras</small> | 354 | <small data-i18n="Karras">Karras</small> |
| 355 | <i class="fa-solid fa-info-circle fa-sm opacity50p" data-i18n="[title]Not all samplers supported." title="Not all samplers supported."></i> | 355 | <i class="fa-solid fa-info-circle fa-sm opacity50p" data-i18n="[title]Not all samplers supported." title="Not all samplers supported."></i> |
| 356 | </label> | 356 | </label> |
| 357 | <label for="sd_aiFaceDetailer" class="checkbox_label" data-i18n="[title]sd_aiFaceDetailer" title="Use AI Face Detailer in image generation."> | 357 | </div> |
| 358 | <input id="sd_aiFaceDetailer" type="checkbox" /> | ||
| 359 | <small data-i18n="sd_aiFaceDetailer">Use AI Face Detailer</small> | ||
| 360 | </label> | ||
| 361 | 358 | ||
| 359 | <div class="flex-container marginTopBot5" data-sd-source="auto"> | ||
| 360 | <label for="sd_adetailer_face" class="flex1 checkbox_label" data-i18n="[title]sd_adetailer_face" title="Use ADetailer with face model during the generation. The ADetailer extension must be installed on the backend."> | ||
| 361 | <input id="sd_adetailer_face" type="checkbox" /> | ||
| 362 | <small data-i18n="Use ADetailer (Face)">Use ADetailer (Face)</small> | ||
| 363 | </label> | ||
| 364 | <div class="flex1"> | ||
| 365 | <!-- I will be useful later! --> | ||
| 366 | </div> | ||
| 362 | </div> | 367 | </div> |
| 363 | 368 | ||
| 364 | <div class="flex-container marginTopBot5" data-sd-source="novel"> | 369 | <div class="flex-container marginTopBot5" data-sd-source="novel"> |
| @@ -23,6 +23,38 @@ export const navigation_option = { | |||
| 23 | previous: -1000, | 23 | previous: -1000, |
| 24 | }; | 24 | }; |
| 25 | 25 | ||
| 26 | /** | ||
| 27 | * Determines if a value is an object. | ||
| 28 | * @param {any} item The item to check. | ||
| 29 | * @returns {boolean} True if the item is an object, false otherwise. | ||
| 30 | */ | ||
| 31 | function isObject(item) { | ||
| 32 | return (item && typeof item === 'object' && !Array.isArray(item)); | ||
| 33 | } | ||
| 34 | |||
| 35 | /** | ||
| 36 | * Merges properties of two objects. If the property is an object, it will be merged recursively. | ||
| 37 | * @param {object} target The target object | ||
| 38 | * @param {object} source The source object | ||
| 39 | * @returns {object} Merged object | ||
| 40 | */ | ||
| 41 | export function deepMerge(target, source) { | ||
| 42 | let output = Object.assign({}, target); | ||
| 43 | if (isObject(target) && isObject(source)) { | ||
| 44 | Object.keys(source).forEach(key => { | ||
| 45 | if (isObject(source[key])) { | ||
| 46 | if (!(key in target)) | ||
| 47 | Object.assign(output, { [key]: source[key] }); | ||
| 48 | else | ||
| 49 | output[key] = deepMerge(target[key], source[key]); | ||
| 50 | } else { | ||
| 51 | Object.assign(output, { [key]: source[key] }); | ||
| 52 | } | ||
| 53 | }); | ||
| 54 | } | ||
| 55 | return output; | ||
| 56 | } | ||
| 57 | |||
| 26 | export function escapeHtml(str) { | 58 | export function escapeHtml(str) { |
| 27 | return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); | 59 | return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); |
| 28 | } | 60 | } |