From dfab4b8ea2ae513d42e1b7109529ce4c915f21a9 Mon Sep 17 00:00:00 2001 From: RossAscends <124905043+RossAscends@users.noreply.github.com> Date: Wed, 19 Jul 2023 22:20:01 +0900 Subject: [PATCH 1/3] attempted slow cure for poe --- src/poe-client.js | 106 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 99 insertions(+), 7 deletions(-) diff --git a/src/poe-client.js b/src/poe-client.js index 548408058..22a14548d 100644 --- a/src/poe-client.js +++ b/src/poe-client.js @@ -266,20 +266,112 @@ function generate_payload(query, variables) { } async function request_with_retries(method, attempts = 10) { - const url = ''; for (let i = 0; i < attempts; i++) { + try { + var ResponseHasFreeSocket = false; const response = await method(); if (response.status === 200) { + + const circularReference = new Set(); + const responseString = JSON.stringify(response, function (key, value) { + if (typeof value === 'object' && value !== null) { + if (circularReference.has(value)) { + return; + } + circularReference.add(value); + } + if (key === 'data' && typeof value === 'object' && value !== null) { + return '[removed data spam]'; + } + if (typeof value === 'object' && value !== null) { + return Array.isArray(value) ? value : { ...value }; + } + + if (key === "freeSockets" && key.length) { + ResponseHasFreeSocket = true; + } + if (key === "Cookie" || key === "set-cookie" || key === "Set-Cookie") { + return "[PB COOKIE DATA REDACTED BY ST CODE]" + } + if (typeof value === 'string' && value.includes('p-b=')) { + const startIndex = value.indexOf('p-b='); + const endIndex = value.indexOf(';', startIndex); + if (endIndex === -1) { + return value.substring(0, startIndex) + '[P-B COOKIE REDACTED BY ST]'; + } + return value.substring(0, startIndex) + '[P-B COOKIE REDACTED BY ST]' + value.substring(endIndex); + } + if (typeof value === 'string' && value.includes('__cf_bm=')) { + const startIndex = value.indexOf('__cf_bm='); + const endIndex = value.indexOf(';', startIndex); + if (endIndex === -1) { + return value.substring(0, startIndex) + '[Cloudflare COOKIE REDACTED BY ST]'; + } + return value.substring(0, startIndex) + '[CloudFlare COOKIE REDACTED BY ST]' + value.substring(endIndex); + } + + + return value; + }, 4); + fs.writeFile('poe-success.log', responseString, 'utf-8', () => { + //console.log('Successful query logged to poe-success.log'); + }); + + return response; } - logger.warn(`Server returned a status code of ${response.status} while downloading ${url}. Retrying (${i + 1}/${attempts})...`); - } - catch (err) { - console.log(err); + + //this never actually gets seen as any non-200 response jumps to the catch code + logger.warn(`Server returned a status code of ${response.status} while downloading. Retrying (${i + 1}/${attempts})...`); + } catch (err) { + var ErrorHasFreeSocket = false; + const circularReference = new Set(); + //const errStringRaw = JSON.stringify(err, null, 4) + const errString = JSON.stringify(err, function (key, value) { + if (key === 'data' && Array.isArray(value)) { + return '[removed data spam]'; + } else if (typeof value === 'object' && value !== null) { + if (circularReference.has(value)) { + return '[Circular]'; + } + circularReference.add(value); + } + if (key === "Cookie" || key === "set-cookie" || key === "Set-Cookie") { + return "[PB COOKIE DATA REDACTED BY ST CODE]" + } + if (typeof value === 'string' && value.includes('p-b=')) { + const startIndex = value.indexOf('p-b='); + const endIndex = value.indexOf(';', startIndex); + if (endIndex === -1) { + return value.substring(0, startIndex) + '[P-B COOKIE REDACTED BY ST]'; + } + return value.substring(0, startIndex) + '[P-B COOKIE REDACTED BY ST]' + value.substring(endIndex); + } + if (typeof value === 'string' && value.includes('__cf_bm=')) { + const startIndex = value.indexOf('__cf_bm='); + const endIndex = value.indexOf(';', startIndex); + if (endIndex === -1) { + return value.substring(0, startIndex) + '[Cloudflare COOKIE REDACTED BY ST]'; + } + return value.substring(0, startIndex) + '[CloudFlare COOKIE REDACTED BY ST]' + value.substring(endIndex); + } + if (key === "freeSockets" && key.length) { + ErrorHasFreeSocket = true; + } + return value; + }, 4); + //fs.writeFile('poe-error-raw.log', errStringRaw, 'utf-8', (err) => { + // console.log(`Error saved to poe-error-raw.log`); + //}); + fs.writeFile('poe-error.log', errString, 'utf-8', (err) => { + if (err) throw err; + console.log(`Error saved to poe-error.log Free socket? ${ErrorHasFreeSocket}`); + }); + await delay(3000) } } - throw new Error(`Failed to download ${url} too many times.`); + throw new Error(`Failed to download too many times.`); } function findKey(obj, key, path = []) { @@ -381,7 +473,7 @@ class Client { await this.connect_ws(); console.log('Client initialized.'); } - + get_device_id() { const user_id = this.viewer["poeUser"]["id"]; From 4c3aafa3a8c3a90f956f660bc91a875771e86548 Mon Sep 17 00:00:00 2001 From: Cohee Date: Wed, 19 Jul 2023 18:27:14 +0300 Subject: [PATCH 2/3] Add support for API keys to extras colab --- colab/GPU.ipynb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/colab/GPU.ipynb b/colab/GPU.ipynb index 7c470e6bb..a1ab0207d 100644 --- a/colab/GPU.ipynb +++ b/colab/GPU.ipynb @@ -32,6 +32,8 @@ }, "outputs": [], "source": [ + "#@markdown (RECOMMENDED) Generates an API key for you to use with the API\n", + "secure = False #@param {type:\"boolean\"}\n", "#@markdown Enables hosting of extensions backend for SillyTavern Extras\n", "use_cpu = False #@param {type:\"boolean\"}\n", "#@markdown Allows to run SillyTavern Extras on CPU (use if you're out of daily GPU allowance)\n", @@ -80,6 +82,8 @@ " params.append('--cpu')\n", "if use_sd_cpu:\n", " params.append('--sd-cpu')\n", + "if secure:\n", + " params.append('--secure')\n", "params.append('--share')\n", "ExtrasModules = []\n", "\n", From c6a6a8352dd7f4abf3aad50cbdf3c29ae0a7e7fd Mon Sep 17 00:00:00 2001 From: Cohee Date: Wed, 19 Jul 2023 18:40:28 +0300 Subject: [PATCH 3/3] Fix textarea sanitation. Fix extensions promise never resolving on 404 --- public/script.js | 3 ++- public/scripts/extensions.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/public/script.js b/public/script.js index f22757020..f6970e1d0 100644 --- a/public/script.js +++ b/public/script.js @@ -7522,8 +7522,9 @@ $(document).ready(function () { .closest(".mes_block") .find(".mes_text") .append( - `` + `` ); + $('#curEditTextarea').val(text); let edit_textarea = $(this) .closest(".mes_block") .find(".edit_textarea"); diff --git a/public/scripts/extensions.js b/public/scripts/extensions.js index d4c1ea947..f52aae76d 100644 --- a/public/scripts/extensions.js +++ b/public/scripts/extensions.js @@ -159,6 +159,8 @@ async function getManifests(names) { const json = await response.json(); obj[name] = json; resolve(); + } else { + reject(); } }).catch(err => reject() && console.log('Could not load manifest.json for ' + name, err)); });