Merge branch 'master' into dev

# Conflicts:
#	src/services/import/zip.js
This commit is contained in:
zadam 2022-12-29 10:27:23 +01:00
commit b9b8b35342
4 changed files with 28 additions and 13 deletions

View File

@ -85,7 +85,7 @@ function isValidEntityId(obj) {
return; return;
} }
if (typeof obj !== 'string' || !/^[A-Za-z0-9]{4,32}$/.test(obj)) { if (typeof obj !== 'string' || !/^[A-Za-z0-9_]{4,128}$/.test(obj)) {
return `'${obj}' is not a valid entityId. Only alphanumeric characters are allowed of length 4 to 32.`; return `'${obj}' is not a valid entityId. Only alphanumeric characters are allowed of length 4 to 32.`;
} }
} }

View File

@ -214,13 +214,13 @@ function exportToZip(taskContext, branch, format, res) {
} }
function findLinks(content, noteMeta) { function findLinks(content, noteMeta) {
content = content.replace(/src="[^"]*api\/images\/([a-zA-Z0-9]+)\/[^"]*"/g, (match, targetNoteId) => { content = content.replace(/src="[^"]*api\/images\/([a-zA-Z0-9_]+)\/[^"]*"/g, (match, targetNoteId) => {
const url = getTargetUrl(targetNoteId, noteMeta); const url = getTargetUrl(targetNoteId, noteMeta);
return url ? `src="${url}"` : match; return url ? `src="${url}"` : match;
}); });
content = content.replace(/href="[^"]*#root[a-zA-Z0-9\/]*\/([a-zA-Z0-9]+)\/?"/g, (match, targetNoteId) => { content = content.replace(/href="[^"]*#root[a-zA-Z0-9_\/]*\/([a-zA-Z0-9_]+)\/?"/g, (match, targetNoteId) => {
const url = getTargetUrl(targetNoteId, noteMeta); const url = getTargetUrl(targetNoteId, noteMeta);
return url ? `href="${url}"` : match; return url ? `href="${url}"` : match;

View File

@ -115,7 +115,7 @@ function importEnex(taskContext, file, parentNote) {
let labelName = currentTag; let labelName = currentTag;
if (labelName === 'source-url') { if (labelName === 'source-url') {
labelName = 'sourceUrl'; labelName = 'pageUrl';
} }
labelName = sanitizeAttributeName(labelName); labelName = sanitizeAttributeName(labelName);
@ -139,7 +139,7 @@ function importEnex(taskContext, file, parentNote) {
else if (currentTag === 'source-url') { else if (currentTag === 'source-url') {
resource.attributes.push({ resource.attributes.push({
type: 'label', type: 'label',
name: 'sourceUrl', name: 'pageUrl',
value: text value: text
}); });
} }

View File

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