improved ZIP import validation and error handling

This commit is contained in:
zadam
2022-12-29 10:25:49 +01:00
parent f4cf04232f
commit f150c223bc
3 changed files with 26 additions and 11 deletions

View File

@@ -231,6 +231,13 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
absUrl += `${absUrl.length > 0 ? '/' : ''}${url}`;
const {noteMeta} = getMeta(absUrl);
if (!noteMeta) {
log.info(`Could not find note meta for URL '${absUrl}'.`);
return null;
}
const targetNoteId = getNoteId(noteMeta, absUrl);
return targetNoteId;
}
@@ -312,6 +319,10 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
const targetNoteId = getNoteIdFromRelativeUrl(url, filePath);
if (!targetNoteId) {
return match;
}
return `src="api/images/${targetNoteId}/${path.basename(url)}"`;
});
@@ -329,6 +340,10 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
const targetNoteId = getNoteIdFromRelativeUrl(url, filePath);
if (!targetNoteId) {
return match;
}
return `href="#root/${targetNoteId}"`;
});