Invert conditions

8bd17de2f392451117d23931e246a324c559398d

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +10 -5Showing whitespace changes
public/script.js+10 -5
@@ -6734,6 +6734,7 @@ export async function saveChat({ chatName, withMetadata, mesId, force = false }
6734 try {6734 try {
6735 const result = await fetch('/api/chats/save', {6735 const result = await fetch('/api/chats/save', {
6736 method: 'POST',6736 method: 'POST',
6737 cache: 'no-cache',
6737 headers: getRequestHeaders(),6738 headers: getRequestHeaders(),
6738 body: JSON.stringify({6739 body: JSON.stringify({
6739 ch_name: characters[this_chid].name,6740 ch_name: characters[this_chid].name,
@@ -6742,12 +6743,18 @@ export async function saveChat({ chatName, withMetadata, mesId, force = false }
6742 avatar_url: characters[this_chid].avatar,6743 avatar_url: characters[this_chid].avatar,
6743 force: force,6744 force: force,
6744 }),6745 }),
6745 cache: 'no-cache',
6746 });6746 });
67476747
6748 if (!result.ok) {6748 if (result.ok) {
6749 return;
6750 }
6751
6749 const errorData = await result.json();6752 const errorData = await result.json();
6750 if (errorData?.error === 'integrity' && !force) {6753 const isIntegrityError = errorData?.error === 'integrity' && !force;
6754 if (!isIntegrityError) {
6755 throw new Error(result.statusText);
6756 }
6757
6751 const forceSaveConfirmed = await Popup.show.confirm(6758 const forceSaveConfirmed = await Popup.show.confirm(
6752 t`Chat integrity check failed, continuing the operation may result in data loss.`,6759 t`Chat integrity check failed, continuing the operation may result in data loss.`,
6753 t`Would you like to overwrite the chat file anyway? Pressing "NO" will cancel the save operation.`,6760 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 }
6757 if (forceSaveConfirmed) {6764 if (forceSaveConfirmed) {
6758 await saveChat({ chatName, withMetadata, mesId, force: true });6765 await saveChat({ chatName, withMetadata, mesId, force: true });
6759 }6766 }
6760 }
6761 }
6762 } catch (error) {6767 } catch (error) {
6763 console.error(error);6768 console.error(error);
6764 toastr.error(t`Check the server connection and reload the page to prevent data loss.`, t`Chat could not be saved`);6769 toastr.error(t`Check the server connection and reload the page to prevent data loss.`, t`Chat could not be saved`);