mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2026-02-02 13:51:40 -08:00
Fix linting errors.
This commit is contained in:
parent
8b27a00d45
commit
7eb032586e
2 changed files with 86 additions and 66 deletions
|
|
@ -36,7 +36,7 @@ var extra_networks_refresh_internal_debounce_timer;
|
|||
|
||||
/** Boolean flags used along with utils.js::waitForBool(). */
|
||||
// Set true when we first load the UI options.
|
||||
const initialUiOptionsLoaded = { state: false };
|
||||
const initialUiOptionsLoaded = {state: false};
|
||||
|
||||
const _debounce = (handler, timeout_ms) => {
|
||||
/** Debounces a function call.
|
||||
|
|
@ -72,11 +72,15 @@ class ExtraNetworksError extends Error {
|
|||
}
|
||||
}
|
||||
class ExtraNetworksPageReadyError extends Error {
|
||||
constructor(...args) { super(...args); }
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
}
|
||||
}
|
||||
|
||||
class ExtraNetworksDataReadyError extends Error {
|
||||
constructor(...args) { super(...args); }
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
}
|
||||
}
|
||||
|
||||
class ExtraNetworksTab {
|
||||
|
|
@ -103,7 +107,7 @@ class ExtraNetworksTab {
|
|||
show_neg_prompt = true;
|
||||
compact_prompt_en = false;
|
||||
refresh_in_progress = false;
|
||||
constructor({ tabname, extra_networks_tabname }) {
|
||||
constructor({tabname, extra_networks_tabname}) {
|
||||
this.tabname = tabname;
|
||||
this.extra_networks_tabname = extra_networks_tabname;
|
||||
this.tabname_full = `${tabname}_${extra_networks_tabname}`;
|
||||
|
|
@ -364,20 +368,22 @@ class ExtraNetworksTab {
|
|||
* before giving up. If set to 0, will attempt forever.
|
||||
*/
|
||||
timeout_ms = timeout_ms || EXTRA_NETWORKS_WAIT_FOR_PAGE_READY_TIMEOUT_MS;
|
||||
const response_handler = (response) => new Promise(async (resolve, reject) => {
|
||||
const response_handler = (response) => new Promise((resolve, reject) => {
|
||||
if (!response.ok) {
|
||||
return reject(response);
|
||||
}
|
||||
const json = await response.json();
|
||||
if (!json.ready) {
|
||||
return reject(`page not ready: ${this.extra_networks_tabname}`);
|
||||
}
|
||||
return resolve(json);
|
||||
|
||||
response.json().then(json => {
|
||||
if (!json.ready) {
|
||||
return reject(`page not ready: ${this.extra_networks_tabname}`);
|
||||
}
|
||||
return resolve(json);
|
||||
});
|
||||
});
|
||||
|
||||
const url = "./sd_extra_networks/page-is-ready";
|
||||
const payload = { extra_networks_tabname: this.extra_networks_tabname };
|
||||
const opts = { timeout_ms: timeout_ms, response_handler: response_handler };
|
||||
const payload = {extra_networks_tabname: this.extra_networks_tabname};
|
||||
const opts = {timeout_ms: timeout_ms, response_handler: response_handler};
|
||||
return await fetchWithRetryAndBackoff(url, payload, opts);
|
||||
}
|
||||
|
||||
|
|
@ -389,21 +395,22 @@ class ExtraNetworksTab {
|
|||
return {};
|
||||
}
|
||||
|
||||
const response_handler = (response) => new Promise(async (resolve, reject) => {
|
||||
const response_handler = (response) => new Promise((resolve, reject) => {
|
||||
if (!response.ok) {
|
||||
return reject(response);
|
||||
}
|
||||
const json = await response.json();
|
||||
if (!json.ready) {
|
||||
return reject(`data not ready: ${this.extra_networks_tabname}`);
|
||||
}
|
||||
return resolve(json);
|
||||
response.json().then(json => {
|
||||
if (!json.ready) {
|
||||
return reject(`data not ready: ${this.extra_networks_tabname}`);
|
||||
}
|
||||
return resolve(json);
|
||||
});
|
||||
});
|
||||
|
||||
const url = "./sd_extra_networks/init-cards-data";
|
||||
const payload = { tabname: this.tabname, extra_networks_tabname: this.extra_networks_tabname };
|
||||
const payload = {tabname: this.tabname, extra_networks_tabname: this.extra_networks_tabname};
|
||||
const timeout_ms = EXTRA_NETWORKS_INIT_DATA_TIMEOUT_MS;
|
||||
const opts = { timeout_ms: timeout_ms, response_handler: response_handler };
|
||||
const opts = {timeout_ms: timeout_ms, response_handler: response_handler};
|
||||
try {
|
||||
const response = await fetchWithRetryAndBackoff(url, payload, opts);
|
||||
return response.data;
|
||||
|
|
@ -421,21 +428,22 @@ class ExtraNetworksTab {
|
|||
return {};
|
||||
}
|
||||
|
||||
const response_handler = (response) => new Promise(async (resolve, reject) => {
|
||||
const response_handler = (response) => new Promise((resolve, reject) => {
|
||||
if (!response.ok) {
|
||||
return reject(response);
|
||||
}
|
||||
const json = await response.json();
|
||||
if (!json.ready) {
|
||||
return reject(`data not ready: ${this.extra_networks_tabname}`);
|
||||
}
|
||||
return resolve(json);
|
||||
response.json().then(json => {
|
||||
if (!json.ready) {
|
||||
return reject(`data not ready: ${this.extra_networks_tabname}`);
|
||||
}
|
||||
return resolve(json);
|
||||
});
|
||||
});
|
||||
|
||||
const url = "./sd_extra_networks/init-tree-data";
|
||||
const payload = { tabname: this.tabname, extra_networks_tabname: this.extra_networks_tabname };
|
||||
const payload = {tabname: this.tabname, extra_networks_tabname: this.extra_networks_tabname};
|
||||
const timeout_ms = EXTRA_NETWORKS_INIT_DATA_TIMEOUT_MS;
|
||||
const opts = { timeout_ms: timeout_ms, response_handler: response_handler }
|
||||
const opts = {timeout_ms: timeout_ms, response_handler: response_handler};
|
||||
try {
|
||||
const response = await fetchWithRetryAndBackoff(url, payload, opts);
|
||||
return response.data;
|
||||
|
|
@ -447,9 +455,9 @@ class ExtraNetworksTab {
|
|||
|
||||
async onFetchCardsData(div_ids) {
|
||||
const url = "./sd_extra_networks/fetch-cards-data";
|
||||
const payload = { extra_networks_tabname: this.extra_networks_tabname, div_ids: div_ids };
|
||||
const payload = {extra_networks_tabname: this.extra_networks_tabname, div_ids: div_ids};
|
||||
const timeout_ms = EXTRA_NETWORKS_FETCH_DATA_TIMEOUT_MS;
|
||||
const opts = { timeout_ms: timeout_ms };
|
||||
const opts = {timeout_ms: timeout_ms};
|
||||
try {
|
||||
const response = await fetchWithRetryAndBackoff(url, payload, opts);
|
||||
if (response.missing_div_ids.length) {
|
||||
|
|
@ -464,9 +472,9 @@ class ExtraNetworksTab {
|
|||
|
||||
async onFetchTreeData(div_ids) {
|
||||
const url = "./sd_extra_networks/fetch-tree-data";
|
||||
const payload = { extra_networks_tabname: this.extra_networks_tabname, div_ids: div_ids };
|
||||
const payload = {extra_networks_tabname: this.extra_networks_tabname, div_ids: div_ids};
|
||||
const timeout_ms = EXTRA_NETWORKS_FETCH_DATA_TIMEOUT_MS;
|
||||
const opts = { timeout_ms: timeout_ms };
|
||||
const opts = {timeout_ms: timeout_ms};
|
||||
try {
|
||||
const response = await fetchWithRetryAndBackoff(url, payload, opts);
|
||||
if (response.missing_div_ids.length) {
|
||||
|
|
@ -813,8 +821,8 @@ function extraNetworksFetchMetadata(extra_networks_tabname, card_name) {
|
|||
|
||||
requestGet(
|
||||
"./sd_extra_networks/metadata",
|
||||
{ extra_networks_tabname: extra_networks_tabname, item: card_name },
|
||||
function (data) {
|
||||
{extra_networks_tabname: extra_networks_tabname, item: card_name},
|
||||
function(data) {
|
||||
if (data && data.metadata) {
|
||||
extraNetworksShowMetadata(data.metadata);
|
||||
} else {
|
||||
|
|
@ -841,7 +849,7 @@ function extraNetworksUnrelatedTabSelected(tabname) {
|
|||
|
||||
async function extraNetworksTabSelected(tabname_full, show_prompt, show_neg_prompt) {
|
||||
/** called from python when user selects an extra networks tab */
|
||||
await waitForKeyInObject({ obj: extra_networks_tabs, k: tabname_full });
|
||||
await waitForKeyInObject({obj: extra_networks_tabs, k: tabname_full});
|
||||
for (const [k, v] of Object.entries(extra_networks_tabs)) {
|
||||
if (k === tabname_full) {
|
||||
v.load(show_prompt, show_neg_prompt);
|
||||
|
|
@ -873,7 +881,7 @@ function extraNetworksControlSearchClearOnClick(event, tabname_full) {
|
|||
txt_search_elem.dispatchEvent(
|
||||
new CustomEvent(
|
||||
"extra-network-control--search-clear",
|
||||
{ bubbles: true, detail: { tabname_full: tabname_full } },
|
||||
{bubbles: true, detail: {tabname_full: tabname_full}},
|
||||
)
|
||||
);
|
||||
|
||||
|
|
@ -998,7 +1006,7 @@ function extraNetworksControlRefreshOnClick(event, tabname_full) {
|
|||
event.stopPropagation();
|
||||
|
||||
clearTimeout(extra_networks_refresh_internal_debounce_timer);
|
||||
extra_networks_refresh_internal_debounce_timer = setTimeout(async () => {
|
||||
extra_networks_refresh_internal_debounce_timer = setTimeout(async() => {
|
||||
const tab = extra_networks_tabs[tabname_full];
|
||||
// We want to reset tab lists on refresh click so that the viewing area
|
||||
// shows that it is loading new data.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/** Collators used for sorting. */
|
||||
const INT_COLLATOR = new Intl.Collator([], { numeric: true });
|
||||
const STR_COLLATOR = new Intl.Collator("en", { numeric: true, sensitivity: "base" });
|
||||
const INT_COLLATOR = new Intl.Collator([], {numeric: true});
|
||||
const STR_COLLATOR = new Intl.Collator("en", {numeric: true, sensitivity: "base"});
|
||||
|
||||
/** Helper functions for checking types and simplifying logging/error handling. */
|
||||
function isNumber(x) {
|
||||
|
|
@ -344,7 +344,7 @@ function waitForValueInObject(o, timeout_ms) {
|
|||
return reject(`timed out waiting for value: ${o.k}: ${o.v}`);
|
||||
}, timeout_ms);
|
||||
}
|
||||
waitForKeyInObject({ k: o.k, obj: o.obj }, timeout_ms).then(() => {
|
||||
waitForKeyInObject({k: o.k, obj: o.obj}, timeout_ms).then(() => {
|
||||
(function _waitForValueInObject() {
|
||||
|
||||
if (o.k in o.obj && o.obj[o.k] == o.v) {
|
||||
|
|
@ -368,23 +368,33 @@ class FetchError extends Error {
|
|||
}
|
||||
|
||||
class Fetch4xxError extends FetchError {
|
||||
constructor(...args) { super(...args); }
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
}
|
||||
}
|
||||
|
||||
class Fetch5xxError extends FetchError {
|
||||
constructor(...args) { super(...args); }
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
}
|
||||
}
|
||||
|
||||
class FetchRetryLimitError extends FetchError {
|
||||
constructor(...args) { super(...args); }
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
}
|
||||
}
|
||||
|
||||
class FetchTimeoutError extends FetchError {
|
||||
constructor(...args) { super(...args); }
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
}
|
||||
}
|
||||
|
||||
class FetchWithRetryAndBackoffTimeoutError extends FetchError {
|
||||
constructor(...args) { super(...args); }
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchWithRetryAndBackoff(url, data, opts = {}) {
|
||||
|
|
@ -414,18 +424,20 @@ async function fetchWithRetryAndBackoff(url, data, opts = {}) {
|
|||
opts.max_delay_ms = opts.max_delay_ms || 3000;
|
||||
opts.fetch_timeout_ms = opts.fetch_timeout_ms || 10000;
|
||||
// The default response handler function for `fetch` call responses.
|
||||
const response_handler = (response) => new Promise(async (resolve, reject) => {
|
||||
const response_handler = (response) => new Promise((resolve, reject) => {
|
||||
if (response.ok) {
|
||||
const json = await response.json();
|
||||
return resolve(json);
|
||||
return response.json().then(json => {
|
||||
return resolve(json);
|
||||
});
|
||||
} else {
|
||||
if (response.status >= 400 && response.status < 500) {
|
||||
throw new Fetch4xxError("client error:", response);
|
||||
}
|
||||
if (response.status >= 500 && response.status < 600) {
|
||||
throw new Fetch5xxError("server error:", response);
|
||||
}
|
||||
return reject(response);
|
||||
}
|
||||
if (response.status >= 400 && response.status < 500) {
|
||||
throw new Fetch4xxError("client error:", response);
|
||||
}
|
||||
if (response.status >= 500 && response.status < 600) {
|
||||
throw new Fetch5xxError("server error:", response);
|
||||
}
|
||||
return reject(response);
|
||||
});
|
||||
opts.response_handler = opts.response_handler || response_handler;
|
||||
|
||||
|
|
@ -439,10 +451,10 @@ async function fetchWithRetryAndBackoff(url, data, opts = {}) {
|
|||
|
||||
const randrange = (min, max) => {
|
||||
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||
}
|
||||
};
|
||||
const get_jitter = (base, max, prev) => {
|
||||
return Math.min(max, randrange(base, prev * 3));
|
||||
}
|
||||
};
|
||||
|
||||
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
|
|
@ -468,7 +480,7 @@ async function fetchWithRetryAndBackoff(url, data, opts = {}) {
|
|||
});
|
||||
};
|
||||
|
||||
const run = async (delay_ms) => {
|
||||
const run = async(delay_ms) => {
|
||||
if (!retry) {
|
||||
// Retry is controlled externally via `run_timeout`. This function's promise
|
||||
// is also handled via that timeout so we can just return here.
|
||||
|
|
@ -476,7 +488,7 @@ async function fetchWithRetryAndBackoff(url, data, opts = {}) {
|
|||
}
|
||||
try {
|
||||
controller = new AbortController();
|
||||
const fetch_opts = { method: opts.method, signal: controller.signal };
|
||||
const fetch_opts = {method: opts.method, signal: controller.signal};
|
||||
const response = await fetch_timeout(opts.fetch_timeout_ms, fetch(url, fetch_opts));
|
||||
return await opts.response_handler(response);
|
||||
} catch (error) {
|
||||
|
|
@ -497,18 +509,18 @@ async function fetchWithRetryAndBackoff(url, data, opts = {}) {
|
|||
await delay(delay_ms);
|
||||
return await run(delay_ms);
|
||||
}
|
||||
}
|
||||
};
|
||||
return await run_timeout(opts.timeout_ms, run(opts.min_delay_ms));
|
||||
}
|
||||
|
||||
function requestGet(url, data, handler, errorHandler) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
var args = Object.keys(data).map(function (k) {
|
||||
var args = Object.keys(data).map(function(k) {
|
||||
return encodeURIComponent(k) + '=' + encodeURIComponent(data[k]);
|
||||
}).join('&');
|
||||
xhr.open("GET", url + "?" + args, true);
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
try {
|
||||
|
|
@ -545,18 +557,18 @@ function requestGetPromise(url, data, timeout_ms) {
|
|||
|
||||
xhr.onload = () => {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
return resolve({ status: xhr.status, response: JSON.parse(xhr.responseText) });
|
||||
return resolve({status: xhr.status, response: JSON.parse(xhr.responseText)});
|
||||
} else {
|
||||
return reject({ status: xhr.status, response: JSON.parse(xhr.responseText) });
|
||||
return reject({status: xhr.status, response: JSON.parse(xhr.responseText)});
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = () => {
|
||||
return reject({ status: xhr.status, response: JSON.parse(xhr.responseText) });
|
||||
return reject({status: xhr.status, response: JSON.parse(xhr.responseText)});
|
||||
};
|
||||
|
||||
xhr.ontimeout = () => {
|
||||
return reject({ status: 408, response: { detail: `Request timeout: ${url}` } });
|
||||
return reject({status: 408, response: {detail: `Request timeout: ${url}`}});
|
||||
};
|
||||
|
||||
const payload = JSON.stringify(data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue