mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-14 19:20:40 +01:00
Require a ping call before generation
This commit is contained in:
parent
a93777e3b7
commit
7b472f13af
@ -816,6 +816,29 @@ $.ajaxPrefilter((options, originalOptions, xhr) => {
|
|||||||
xhr.setRequestHeader('X-CSRF-Token', token);
|
xhr.setRequestHeader('X-CSRF-Token', token);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pings the STserver to check if it is reachable.
|
||||||
|
* @returns {Promise<boolean>} True if the server is reachable.
|
||||||
|
* @throws {Error} If the server is unreachable.
|
||||||
|
*/
|
||||||
|
export async function pingServer() {
|
||||||
|
try {
|
||||||
|
const result = await fetch('api/ping', {
|
||||||
|
method: 'GET',
|
||||||
|
headers: getRequestHeaders(),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.ok) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error pinging server', error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function firstLoadInit() {
|
async function firstLoadInit() {
|
||||||
try {
|
try {
|
||||||
const tokenResponse = await fetch('/csrf-token');
|
const tokenResponse = await fetch('/csrf-token');
|
||||||
@ -3082,6 +3105,15 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!dryRun) {
|
if (!dryRun) {
|
||||||
|
// Ping server to make sure it is still alive
|
||||||
|
const pingResult = await pingServer();
|
||||||
|
|
||||||
|
if (!pingResult) {
|
||||||
|
unblockGeneration(type);
|
||||||
|
toastr.error('Verify that the server is running and accessible.', 'ST Server cannot be reached' );
|
||||||
|
throw new Error('Server unreachable');
|
||||||
|
}
|
||||||
|
|
||||||
// Hide swipes if not in a dry run.
|
// Hide swipes if not in a dry run.
|
||||||
hideSwipeButtons();
|
hideSwipeButtons();
|
||||||
// If generated any message, set the flag to indicate it can't be recreated again.
|
// If generated any message, set the flag to indicate it can't be recreated again.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user