Bug fix: save on no changes
Some checks failed
Create Release on Tag Push / build (push) Has been cancelled
Some checks failed
Create Release on Tag Push / build (push) Has been cancelled
This commit is contained in:
parent
0bc89f4a72
commit
f2801c9f1c
2 changed files with 17 additions and 3 deletions
|
@ -45,8 +45,18 @@ async function saveCallback(editor: Editor, fileID: string, oldSyncID: string, s
|
||||||
|
|
||||||
try {
|
try {
|
||||||
newSyncID = (await uploadAsset(fileID, SVG_MIME, svgElem.outerHTML)).syncID;
|
newSyncID = (await uploadAsset(fileID, SVG_MIME, svgElem.outerHTML)).syncID;
|
||||||
await replaceSyncID(fileID, oldSyncID, newSyncID);
|
if(newSyncID != oldSyncID) {
|
||||||
await removeFile(DATA_PATH + IDsToAssetPath(fileID, 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);
|
saveButton.setDisabled(true);
|
||||||
setTimeout(() => { // @todo improve save button feedback
|
setTimeout(() => { // @todo improve save button feedback
|
||||||
saveButton.setDisabled(false);
|
saveButton.setDisabled(false);
|
||||||
|
|
|
@ -50,6 +50,7 @@ export async function replaceSyncID(fileID: string, oldSyncID: string, newSyncID
|
||||||
const search = encodeURI(IDsToAssetPath(fileID, oldSyncID)); // the API uses URI-encoded
|
const search = encodeURI(IDsToAssetPath(fileID, oldSyncID)); // the API uses URI-encoded
|
||||||
// find blocks containing that image
|
// find blocks containing that image
|
||||||
const blocks = await findImageBlocks(search);
|
const blocks = await findImageBlocks(search);
|
||||||
|
if(blocks.length === 0) return false;
|
||||||
|
|
||||||
for(const block of blocks) {
|
for(const block of blocks) {
|
||||||
|
|
||||||
|
@ -62,8 +63,11 @@ export async function replaceSyncID(fileID: string, oldSyncID: string, newSyncID
|
||||||
|
|
||||||
for(const source of sources) {
|
for(const source of sources) {
|
||||||
const newSource = IDsToAssetPath(fileID, newSyncID);
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue