Relax URL requirements when Mancer is enabled.

This commit is contained in:
50h100a
2023-08-08 16:12:03 -04:00
parent ef3a9a810e
commit 53e41bdda8
2 changed files with 10 additions and 4 deletions

View File

@@ -7774,9 +7774,9 @@ $(document).ready(function () {
$("#api_button_textgenerationwebui").click(async function (e) { $("#api_button_textgenerationwebui").click(async function (e) {
e.stopPropagation(); e.stopPropagation();
if ($("#textgenerationwebui_api_url_text").val() != "") { if ($("#textgenerationwebui_api_url_text").val() != "") {
let value = formatTextGenURL($("#textgenerationwebui_api_url_text").val().trim()) let value = formatTextGenURL($("#textgenerationwebui_api_url_text").val().trim(), api_use_mancer_webui);
if (!value) { if (!value) {
callPopup('Please enter a valid URL.<br/>WebUI URLs should end with <tt>/api</tt>', 'text'); callPopup("Please enter a valid URL.<br/>WebUI URLs should end with <tt>/api</tt><br/>Enable 'Relaxed API URLs' to allow other paths.", 'text');
return; return;
} }

View File

@@ -99,12 +99,18 @@ function selectPreset(name) {
saveSettingsDebounced(); saveSettingsDebounced();
} }
function formatTextGenURL(value) { function formatTextGenURL(value, use_mancer) {
try { try {
const url = new URL(value); const url = new URL(value);
if (!power_user.relaxed_api_urls) { if (!power_user.relaxed_api_urls) {
if (use_mancer) { // If Mancer is in use, only require the URL to *end* with `/api`.
if (!url.pathname.endsWith('/api')) {
return null;
}
} else {
url.pathname = '/api'; url.pathname = '/api';
} }
}
return url.toString(); return url.toString();
} catch { } // Just using URL as a validation check } catch { } // Just using URL as a validation check
return null; return null;