Bug fix: save on no changes
Some checks failed
Create Release on Tag Push / build (push) Has been cancelled

This commit is contained in:
MassiveBox 2025-04-06 12:21:25 +02:00
parent 0bc89f4a72
commit f2801c9f1c
Signed by: massivebox
GPG key ID: 9B74D3A59181947D
2 changed files with 17 additions and 3 deletions

View file

@ -45,8 +45,18 @@ async function saveCallback(editor: Editor, fileID: string, oldSyncID: string, s
try {
newSyncID = (await uploadAsset(fileID, SVG_MIME, svgElem.outerHTML)).syncID;
await replaceSyncID(fileID, oldSyncID, newSyncID);
if(newSyncID != oldSyncID) {
const changed = await replaceSyncID(fileID, oldSyncID, newSyncID);
if(!changed) {
alert(
"Error replacing old sync ID with new one! You may need to manually replace the file path." +
"\nTry saving the drawing again. This is a bug, please open an issue as soon as you can." +
"\nIf your document doesn't show the drawing, you can recover it from the SiYuan workspace directory."
);
return oldSyncID;
}
await removeFile(DATA_PATH + IDsToAssetPath(fileID, oldSyncID));
}
saveButton.setDisabled(true);
setTimeout(() => { // @todo improve save button feedback
saveButton.setDisabled(false);

View file

@ -50,6 +50,7 @@ export async function replaceSyncID(fileID: string, oldSyncID: string, newSyncID
const search = encodeURI(IDsToAssetPath(fileID, oldSyncID)); // the API uses URI-encoded
// find blocks containing that image
const blocks = await findImageBlocks(search);
if(blocks.length === 0) return false;
for(const block of blocks) {
@ -62,8 +63,11 @@ export async function replaceSyncID(fileID: string, oldSyncID: string, newSyncID
for(const source of sources) {
const newSource = IDsToAssetPath(fileID, newSyncID);
await replaceBlockContent(block.id, source, newSource);
}
const changed = await replaceBlockContent(block.id, source, newSource);
if(!changed) return false
}
}
return true;
}