mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-12 10:00:36 +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);
|
||||
});
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
try {
|
||||
const tokenResponse = await fetch('/csrf-token');
|
||||
@ -3082,6 +3105,15 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
|
||||
}
|
||||
|
||||
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.
|
||||
hideSwipeButtons();
|
||||
// If generated any message, set the flag to indicate it can't be recreated again.
|
||||
|
Loading…
x
Reference in New Issue
Block a user