Use deepMerge to combine payloads
| @@ -18,7 +18,7 @@ import { | ||
| 18 | 18 | } from '../../../script.js'; |
| 19 | 19 | import { getApiUrl, getContext, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync, writeExtensionField } from '../../extensions.js'; |
| 20 | 20 | import { selected_group } from '../../group-chats.js'; |
| 21 | 21 | import { stringFormat, initScrollHeight, resetScrollHeight, getCharaFilename, saveBase64AsFile, getBase64Async, delay, isTrueBoolean, debounce, isFalseBoolean, deepMerge } from '../../utils.js'; |
| 22 | 22 | import { getMessageTimeStamp, humanizedDateTime } from '../../RossAscends-mods.js'; |
| 23 | 23 | import { SECRET_KEYS, secret_state, writeSecret } from '../../secrets.js'; |
| 24 | 24 | import { getNovelUnlimitedImageGeneration, getNovelAnlas, loadNovelSubscriptionData } from '../../nai-settings.js'; |
| @@ -219,7 +219,7 @@ const defaultSettings = { | ||
| 219 | 219 | // Automatic1111/Horde exclusives |
| 220 | 220 | restore_faces: false, |
| 221 | 221 | enable_hr: false, |
| 222 | 222 | aiFaceDetailer adetailer_face: false, |
| 223 | 223 | |
| 224 | 224 | // Horde settings |
| 225 | 225 | horde: false, |
| @@ -436,7 +436,7 @@ async function loadSettings() { | ||
| 436 | 436 | $('#sd_horde_sanitize').prop('checked', extension_settings.sd.horde_sanitize); |
| 437 | 437 | $('#sd_restore_faces').prop('checked', extension_settings.sd.restore_faces); |
| 438 | 438 | $('#sd_enable_hr').prop('checked', extension_settings.sd.enable_hr); |
| 439 | 439 | $('#sd_aiFaceDetailersd_adetailer_face').prop('checked', extension_settings.sd.aiFaceDetaileradetailer_face); |
| 440 | 440 | $('#sd_refine_mode').prop('checked', extension_settings.sd.refine_mode); |
| 441 | 441 | $('#sd_multimodal_captioning').prop('checked', extension_settings.sd.multimodal_captioning); |
| 442 | 442 | $('#sd_auto_url').val(extension_settings.sd.auto_url); |
| @@ -855,8 +855,8 @@ function onSamplerChange() { | ||
| 855 | 855 | saveSettingsDebounced(); |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | function onAiFaceDetailerChangeonADetailerFaceChange() { |
| 859 | 859 | extension_settings.sd.aiFaceDetaileradetailer_face = !!$('#sd_aiFaceDetailersd_adetailer_face').prop('checked'); |
| 860 | 860 | saveSettingsDebounced(); |
| 861 | 861 | } |
| 862 | 862 | |
| @@ -2955,20 +2955,22 @@ async function generateAutoImage(prompt, negativePrompt, signal) { | ||
| 2955 | 2955 | do_not_save_grid: false, |
| 2956 | 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 | 2960 | if (extension_settings.sd.aiFaceDetaileradetailer_face) { |
| 2961 | 2961 | payload.alwayson_scripts = deepMerge(payload, { |
| 2962 | + alwayson_scripts: { | |
| 2962 | 2963 | ADetailer: { |
| 2963 | 2964 | args: [ |
| 2964 | 2965 | true, // ad_enable |
| 2965 | 2966 | true, // skip_img2img |
| 2966 | 2967 | { |
| 2967 | 2968 | " 'ad_model"': "'face_yolov8n.pt"', |
| 2968 | - } | |
| 2969 | + }, | |
| 2969 | - ] | |
| 2970 | + ], | |
| 2970 | - } | |
| 2971 | + }, | |
| 2971 | - }; | |
| 2972 | + }, | |
| 2973 | + }); | |
| 2972 | 2974 | } |
| 2973 | 2975 | |
| 2974 | 2976 | // Make the fetch call with the payload |
| @@ -2979,8 +2981,6 @@ async function generateAutoImage(prompt, negativePrompt, signal) { | ||
| 2979 | 2981 | body: JSON.stringify(payload), |
| 2980 | 2982 | }); |
| 2981 | 2983 | |
| 2982 | - | |
| 2983 | - | |
| 2984 | 2984 | if (result.ok) { |
| 2985 | 2985 | const data = await result.json(); |
| 2986 | 2986 | return { format: 'png', data: data.images[0] }; |
| @@ -4210,7 +4210,7 @@ jQuery(async () => { | ||
| 4210 | 4210 | $('#sd_horde_sanitize').on('input', onHordeSanitizeInput); |
| 4211 | 4211 | $('#sd_restore_faces').on('input', onRestoreFacesInput); |
| 4212 | 4212 | $('#sd_enable_hr').on('input', onHighResFixInput); |
| 4213 | 4213 | $('#sd_aiFaceDetailersd_adetailer_face').on('change', onAiFaceDetailerChangeonADetailerFaceChange); |
| 4214 | 4214 | $('#sd_refine_mode').on('input', onRefineModeInput); |
| 4215 | 4215 | $('#sd_character_prompt').on('input', onCharacterPromptInput); |
| 4216 | 4216 | $('#sd_character_negative_prompt').on('input', onCharacterNegativePromptInput); |
| @@ -354,11 +354,16 @@ | ||
| 354 | 354 | <small data-i18n="Karras">Karras</small> |
| 355 | 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 | 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 | 367 | </div> |
| 363 | 368 | |
| 364 | 369 | <div class="flex-container marginTopBot5" data-sd-source="novel"> |
| @@ -23,6 +23,38 @@ export const navigation_option = { | ||
| 23 | 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 | 58 | export function escapeHtml(str) { |
| 27 | 59 | return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); |
| 28 | 60 | } |