Invert conditions

This commit is contained in:
Cohee
2025-03-16 21:49:36 +02:00
parent 5145e30be3
commit 8bd17de2f3

View File

@@ -6734,6 +6734,7 @@ export async function saveChat({ chatName, withMetadata, mesId, force = false }
try { try {
const result = await fetch('/api/chats/save', { const result = await fetch('/api/chats/save', {
method: 'POST', method: 'POST',
cache: 'no-cache',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ body: JSON.stringify({
ch_name: characters[this_chid].name, ch_name: characters[this_chid].name,
@@ -6742,12 +6743,18 @@ export async function saveChat({ chatName, withMetadata, mesId, force = false }
avatar_url: characters[this_chid].avatar, avatar_url: characters[this_chid].avatar,
force: force, force: force,
}), }),
cache: 'no-cache',
}); });
if (!result.ok) { if (result.ok) {
return;
}
const errorData = await result.json(); const errorData = await result.json();
if (errorData?.error === 'integrity' && !force) { const isIntegrityError = errorData?.error === 'integrity' && !force;
if (!isIntegrityError) {
throw new Error(result.statusText);
}
const forceSaveConfirmed = await Popup.show.confirm( const forceSaveConfirmed = await Popup.show.confirm(
t`Chat integrity check failed, continuing the operation may result in data loss.`, t`Chat integrity check failed, continuing the operation may result in data loss.`,
t`Would you like to overwrite the chat file anyway? Pressing "NO" will cancel the save operation.`, t`Would you like to overwrite the chat file anyway? Pressing "NO" will cancel the save operation.`,
@@ -6757,8 +6764,6 @@ export async function saveChat({ chatName, withMetadata, mesId, force = false }
if (forceSaveConfirmed) { if (forceSaveConfirmed) {
await saveChat({ chatName, withMetadata, mesId, force: true }); await saveChat({ chatName, withMetadata, mesId, force: true });
} }
}
}
} catch (error) { } catch (error) {
console.error(error); console.error(error);
toastr.error(t`Check the server connection and reload the page to prevent data loss.`, t`Chat could not be saved`); toastr.error(t`Check the server connection and reload the page to prevent data loss.`, t`Chat could not be saved`);