mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Invert conditions
This commit is contained in:
@@ -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,22 +6743,26 @@ 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) {
|
||||||
const errorData = await result.json();
|
return;
|
||||||
if (errorData?.error === 'integrity' && !force) {
|
}
|
||||||
const forceSaveConfirmed = await Popup.show.confirm(
|
|
||||||
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.`,
|
|
||||||
{ okButton: t`Yes, overwrite`, cancelButton: t`No, cancel` },
|
|
||||||
) === POPUP_RESULT.AFFIRMATIVE;
|
|
||||||
|
|
||||||
if (forceSaveConfirmed) {
|
const errorData = await result.json();
|
||||||
await saveChat({ chatName, withMetadata, mesId, force: true });
|
const isIntegrityError = errorData?.error === 'integrity' && !force;
|
||||||
}
|
if (!isIntegrityError) {
|
||||||
}
|
throw new Error(result.statusText);
|
||||||
|
}
|
||||||
|
|
||||||
|
const forceSaveConfirmed = await Popup.show.confirm(
|
||||||
|
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.`,
|
||||||
|
{ okButton: t`Yes, overwrite`, cancelButton: t`No, cancel` },
|
||||||
|
) === POPUP_RESULT.AFFIRMATIVE;
|
||||||
|
|
||||||
|
if (forceSaveConfirmed) {
|
||||||
|
await saveChat({ chatName, withMetadata, mesId, force: true });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
Reference in New Issue
Block a user