| 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 | }); |
| 6747 | | 6747 | |
| 6748 | if (!result.ok) { | 6748 | if (result.ok) { |
| 6749 | const errorData = await result.json(); | 6749 | return; |
| 6750 | if (errorData?.error === 'integrity' && !force) { | 6750 | } |
| 6751 | const forceSaveConfirmed = await Popup.show.confirm( | 6751 | |
| 6752 | t`Chat integrity check failed, continuing the operation may result in data loss.`, | 6752 | const errorData = await result.json(); |
| 6753 | t`Would you like to overwrite the chat file anyway? Pressing "NO" will cancel the save operation.`, | 6753 | const isIntegrityError = errorData?.error === 'integrity' && !force; |
| 6754 | { okButton: t`Yes, overwrite`, cancelButton: t`No, cancel` }, | 6754 | if (!isIntegrityError) { |
| 6755 | ) === POPUP_RESULT.AFFIRMATIVE; | 6755 | throw new Error(result.statusText); |
| 6756 | | 6756 | } |
| 6757 | if (forceSaveConfirmed) { | 6757 | |
| 6758 | await saveChat({ chatName, withMetadata, mesId, force: true }); | 6758 | const forceSaveConfirmed = await Popup.show.confirm( |
| 6759 | } | 6759 | t`Chat integrity check failed, continuing the operation may result in data loss.`, |
| 6760 | } | 6760 | t`Would you like to overwrite the chat file anyway? Pressing "NO" will cancel the save operation.`, |
| | 6761 | { okButton: t`Yes, overwrite`, cancelButton: t`No, cancel` }, |
| | 6762 | ) === POPUP_RESULT.AFFIRMATIVE; |
| | 6763 | |
| | 6764 | if (forceSaveConfirmed) { |
| | 6765 | await saveChat({ chatName, withMetadata, mesId, force: true }); |
| 6761 | } | 6766 | } |
| 6762 | } catch (error) { | 6767 | } catch (error) { |
| 6763 | console.error(error); | 6768 | console.error(error); |