From 5e12985c529c1acec7d31185b6df1df296302227 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sun, 16 Feb 2025 17:54:21 -0500 Subject: [PATCH] configurable request timeout Signed-off-by: Vladimir Mandic --- CHANGELOG.md | 1 + javascript/logger.js | 10 ++++------ modules/shared.py | 1 + wiki | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4110af98..a20011288 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ We're back with another update with over 50 commits! - [localization](https://vladmandic.github.io/sdnext-docs/Locale/) documentation - **UI** - force browser cache-invalidate on page load + - configurable request timeout - **Docs** - New [Outpaint](https://vladmandic.github.io/sdnext-docs/Outpaint/) step-by-step guide - Updated [Docker](https://github.com/vladmandic/sdnext/wiki/Docker) guide diff --git a/javascript/logger.js b/javascript/logger.js index 111899005..d917178bb 100644 --- a/javascript/logger.js +++ b/javascript/logger.js @@ -1,5 +1,3 @@ -const timeout = 30000; - const scrollBottom = async (el) => { const lastChild = el.lastElementChild; if (lastChild) lastChild.scrollIntoView({ behavior: 'smooth' }); @@ -37,7 +35,7 @@ const error = async (...msg) => { // if (!txt.includes('asctime') && !txt.includes('xhr.')) xhrPost('/sdapi/v1/log', { error: txt }); // eslint-disable-line no-use-before-define }; -const xhrInternal = (xhrObj, data, handler = undefined, errorHandler = undefined, ignore = false, serverTimeout = timeout) => { +const xhrInternal = (xhrObj, data, handler = undefined, errorHandler = undefined, ignore = false, serverTimeout = opts.ui_request_timeout || 30000) => { const err = (msg) => { if (!ignore) { error(`${msg}: state=${xhrObj.readyState} status=${xhrObj.status} response=${xhrObj.responseText}`); @@ -46,7 +44,7 @@ const xhrInternal = (xhrObj, data, handler = undefined, errorHandler = undefined }; xhrObj.setRequestHeader('Content-Type', 'application/json'); - xhrObj.timeout = timeout; + xhrObj.timeout = opts.ui_request_timeout || 30000; xhrObj.ontimeout = () => err('xhr.ontimeout'); xhrObj.onerror = () => err('xhr.onerror'); xhrObj.onabort = () => err('xhr.onabort'); @@ -68,14 +66,14 @@ const xhrInternal = (xhrObj, data, handler = undefined, errorHandler = undefined xhrObj.send(req); }; -const xhrGet = (url, data, handler = undefined, errorHandler = undefined, ignore = false, serverTimeout = timeout) => { +const xhrGet = (url, data, handler = undefined, errorHandler = undefined, ignore = false, serverTimeout = opts.ui_request_timeout || 30000) => { const xhr = new XMLHttpRequest(); const args = Object.keys(data).map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(data[k])}`).join('&'); xhr.open('GET', `${url}?${args}`, true); xhrInternal(xhr, data, handler, errorHandler, ignore, serverTimeout); }; -function xhrPost(url, data, handler = undefined, errorHandler = undefined, ignore = false, serverTimeout = timeout) { +function xhrPost(url, data, handler = undefined, errorHandler = undefined, ignore = false, serverTimeout = opts.ui_request_timeout || 30000) { const xhr = new XMLHttpRequest(); xhr.open('POST', url, true); xhrInternal(xhr, data, handler, errorHandler, ignore, serverTimeout); diff --git a/modules/shared.py b/modules/shared.py index 9d8633eeb..1b36a2e83 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -799,6 +799,7 @@ options_templates.update(options_section(('ui', "User Interface"), { "aspect_ratios": OptionInfo("1:1, 4:3, 3:2, 16:9, 16:10, 21:9, 2:3, 3:4, 9:16, 10:16, 9:21", "Allowed aspect ratios"), "logmonitor_show": OptionInfo(True, "Show log view"), "logmonitor_refresh_period": OptionInfo(5000, "Log view update period", gr.Slider, {"minimum": 0, "maximum": 30000, "step": 25}), + "ui_request_timeout": OptionInfo(30000, "UI request timeout", gr.Slider, {"minimum": 1000, "maximum": 120000, "step": 10}), "motd": OptionInfo(False, "Show MOTD"), "compact_view": OptionInfo(False, "Compact view"), "return_grid": OptionInfo(True, "Show grid in results"), diff --git a/wiki b/wiki index d50484b80..a04284d61 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit d50484b80f9dd3d7968f76763cf0bec84f29d0de +Subproject commit a04284d619efada82760889a8116db8576bb1f71