Use custom fetchApi as workaround to comfys not working
This commit is contained in:
@@ -3,18 +3,7 @@ import { app } from '../../../scripts/app.js';
|
||||
import { api } from '../../../scripts/api.js';
|
||||
|
||||
async function fetchExtensionSettings() {
|
||||
try {
|
||||
const response = await api.fetchApi(
|
||||
'/extensions/ComfyUI-Sn0w-Scripts/settings/sn0w_settings.json'
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok ' + response.statusText);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('There was a problem with the fetch operation:', error);
|
||||
}
|
||||
return SettingUtils.fetchApi("/extensions/ComfyUI-Sn0w-Scripts/settings/sn0w_settings.json");
|
||||
}
|
||||
|
||||
const sn0wSettings = await fetchExtensionSettings();
|
||||
|
||||
+33
-7
@@ -19,6 +19,23 @@ export class SettingUtils {
|
||||
}
|
||||
}
|
||||
|
||||
static async fetchApi(route, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
if (!options.headers) {
|
||||
options.headers = {};
|
||||
}
|
||||
const url = `${location.protocol}//${location.host}${route}`;
|
||||
try {
|
||||
const response = await fetch(url, options);
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('There was a problem with the fetch operation:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Callback function to add or remove the filename from the settings list
|
||||
static async toggleFavourite(existingList, filename, setting) {
|
||||
try {
|
||||
@@ -54,28 +71,26 @@ export class SettingUtils {
|
||||
textarea.id = uniqueId;
|
||||
textarea.value = value;
|
||||
const maxLines = 10;
|
||||
const lineHeight = 15;
|
||||
// Function to set the height based on the number of lines
|
||||
const adjustHeight = () => {
|
||||
textarea.style.height = ''; // Allow to shrink
|
||||
const lines = textarea.value.split('\n').length;
|
||||
const scrollHeight = textarea.scrollHeight + 3;
|
||||
if (lines > maxLines) {
|
||||
const height = (scrollHeight / lines) * maxLines
|
||||
textarea.setAttribute(
|
||||
'style',
|
||||
`width: 100%; height: ${lineHeight * maxLines}px; resize: none;`
|
||||
`width: 100%; height: ${height}px; resize: none;`
|
||||
);
|
||||
return;
|
||||
}
|
||||
const height = lines * lineHeight;
|
||||
textarea.setAttribute('style', `width: 100%; height: ${height}px; resize: none;`);
|
||||
textarea.setAttribute('style', `width: 100%; height: ${scrollHeight}px; resize: none;`);
|
||||
};
|
||||
|
||||
adjustHeight();
|
||||
textarea.onchange = () => setter(textarea.value);
|
||||
textarea.addEventListener('input', adjustHeight);
|
||||
|
||||
// Apply event handler
|
||||
textarea.onchange = () => setter(textarea.value);
|
||||
|
||||
// Apply additional attributes
|
||||
for (const [key, val] of Object.entries(attrs)) {
|
||||
textarea.setAttribute(key, val);
|
||||
@@ -94,6 +109,17 @@ export class SettingUtils {
|
||||
label.className = 'comfy-tooltip-indicator';
|
||||
}
|
||||
|
||||
// Update height when settings are opened
|
||||
const dialog = document.getElementById('comfy-settings-dialog');
|
||||
const observer = new MutationObserver(mutations => {
|
||||
mutations.forEach(mutation => {
|
||||
if (mutation.type === 'attributes' && mutation.attributeName === 'open') {
|
||||
adjustHeight();
|
||||
}
|
||||
});
|
||||
});
|
||||
observer.observe(dialog, { attributes: true });
|
||||
|
||||
return tr;
|
||||
}
|
||||
|
||||
|
||||
+2
-8
@@ -464,15 +464,9 @@ app.registerExtension({
|
||||
}
|
||||
|
||||
async function getValidFiles(type) {
|
||||
const apiRequest = await api.fetchApi(`${SettingUtils.API_PREFIX}/${type}`, {
|
||||
return await SettingUtils.fetchApi(`${SettingUtils.API_PREFIX}/${type}`, {
|
||||
method: "GET",
|
||||
})
|
||||
if (!apiRequest.ok) {
|
||||
console.error('API request failed:', apiRequest.statusText);
|
||||
} else {
|
||||
const responseBody = await apiRequest.json();
|
||||
return responseBody;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
nodeType.prototype.onNodeCreated = function () {
|
||||
|
||||
Reference in New Issue
Block a user