mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-11 17:40:14 +01:00
Rename URL validation util function
This commit is contained in:
parent
0f15d2d45b
commit
5b954a3584
@ -31,7 +31,7 @@ import {
|
|||||||
SECRET_KEYS,
|
SECRET_KEYS,
|
||||||
secret_state,
|
secret_state,
|
||||||
} from "./secrets.js";
|
} from "./secrets.js";
|
||||||
import { debounce, delay, getStringHash, isUrlOrAPIKey, waitUntilCondition } from "./utils.js";
|
import { debounce, delay, getStringHash, isValidUrl, waitUntilCondition } from "./utils.js";
|
||||||
import { chat_completion_sources, oai_settings } from "./openai.js";
|
import { chat_completion_sources, oai_settings } from "./openai.js";
|
||||||
import { getTokenCount } from "./tokenizers.js";
|
import { getTokenCount } from "./tokenizers.js";
|
||||||
|
|
||||||
@ -394,7 +394,7 @@ function RA_autoconnect(PrevApi) {
|
|||||||
if (online_status === "no_connection" && LoadLocalBool('AutoConnectEnabled')) {
|
if (online_status === "no_connection" && LoadLocalBool('AutoConnectEnabled')) {
|
||||||
switch (main_api) {
|
switch (main_api) {
|
||||||
case 'kobold':
|
case 'kobold':
|
||||||
if (api_server && isUrlOrAPIKey(api_server)) {
|
if (api_server && isValidUrl(api_server)) {
|
||||||
$("#api_button").click();
|
$("#api_button").click();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -404,7 +404,7 @@ function RA_autoconnect(PrevApi) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'textgenerationwebui':
|
case 'textgenerationwebui':
|
||||||
if (api_server_textgenerationwebui && isUrlOrAPIKey(api_server_textgenerationwebui)) {
|
if (api_server_textgenerationwebui && isValidUrl(api_server_textgenerationwebui)) {
|
||||||
$("#api_button_textgenerationwebui").click();
|
$("#api_button_textgenerationwebui").click();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { saveSettingsDebounced } from "../script.js";
|
import { saveSettingsDebounced } from "../script.js";
|
||||||
import { power_user } from "./power-user.js";
|
import { power_user } from "./power-user.js";
|
||||||
import { isUrlOrAPIKey } from "./utils.js";
|
import { isValidUrl } from "./utils.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {{ term: string; }} request
|
* @param {{ term: string; }} request
|
||||||
@ -64,7 +64,7 @@ function onServerConnectClick() {
|
|||||||
const value = String($(`[data-server-history="${serverLabel}"]`).val()).toLowerCase().trim();
|
const value = String($(`[data-server-history="${serverLabel}"]`).val()).toLowerCase().trim();
|
||||||
|
|
||||||
// Don't save empty values or invalid URLs
|
// Don't save empty values or invalid URLs
|
||||||
if (!value || !isUrlOrAPIKey(value)) {
|
if (!value || !isValidUrl(value)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ export function escapeHtml(str) {
|
|||||||
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isUrlOrAPIKey(value) {
|
export function isValidUrl(value) {
|
||||||
try {
|
try {
|
||||||
new URL(value);
|
new URL(value);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user