You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
All: Fixes #1405: Handle invalid resource tags that contain no data when importing ENEX
This commit is contained in:
@ -362,6 +362,9 @@ class Application extends BaseApplication {
|
|||||||
importOptions.path = path;
|
importOptions.path = path;
|
||||||
importOptions.format = module.format;
|
importOptions.format = module.format;
|
||||||
importOptions.destinationFolderId = !module.isNoteArchive && moduleSource === 'file' ? selectedFolderId : null;
|
importOptions.destinationFolderId = !module.isNoteArchive && moduleSource === 'file' ? selectedFolderId : null;
|
||||||
|
importOptions.onError = (error) => {
|
||||||
|
console.warn(error);
|
||||||
|
}
|
||||||
|
|
||||||
const service = new InteropService();
|
const service = new InteropService();
|
||||||
try {
|
try {
|
||||||
|
@ -95,6 +95,8 @@ async function saveNoteResources(note) {
|
|||||||
let resourcesCreated = 0;
|
let resourcesCreated = 0;
|
||||||
for (let i = 0; i < note.resources.length; i++) {
|
for (let i = 0; i < note.resources.length; i++) {
|
||||||
let resource = note.resources[i];
|
let resource = note.resources[i];
|
||||||
|
if (!resource.id) continue;
|
||||||
|
|
||||||
let toSave = Object.assign({}, resource);
|
let toSave = Object.assign({}, resource);
|
||||||
delete toSave.data;
|
delete toSave.data;
|
||||||
|
|
||||||
@ -358,6 +360,7 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
|
|||||||
noteResourceRecognition = null;
|
noteResourceRecognition = null;
|
||||||
} else if (n == 'resource-attributes') {
|
} else if (n == 'resource-attributes') {
|
||||||
noteResource.filename = noteResourceAttributes['file-name'];
|
noteResource.filename = noteResourceAttributes['file-name'];
|
||||||
|
if (noteResourceAttributes['source-url']) noteResource.sourceUrl = noteResourceAttributes['source-url'];
|
||||||
noteResourceAttributes = null;
|
noteResourceAttributes = null;
|
||||||
} else if (n == 'note-attributes') {
|
} else if (n == 'note-attributes') {
|
||||||
note.latitude = noteAttributes.latitude;
|
note.latitude = noteAttributes.latitude;
|
||||||
@ -389,7 +392,7 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
importOptions.onError(error);
|
importOptions.onError(error);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (noteResource.dataEncoding) {
|
||||||
importOptions.onError(new Error('Cannot decode resource with encoding: ' + noteResource.dataEncoding));
|
importOptions.onError(new Error('Cannot decode resource with encoding: ' + noteResource.dataEncoding));
|
||||||
decodedData = noteResource.data; // Just put the encoded data directly in the file so it can, potentially, be manually decoded later
|
decodedData = noteResource.data; // Just put the encoded data directly in the file so it can, potentially, be manually decoded later
|
||||||
}
|
}
|
||||||
@ -400,6 +403,11 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
|
|||||||
resourceId = md5(decodedData);
|
resourceId = md5(decodedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!resourceId || !noteResource.data) {
|
||||||
|
const debugTemp = Object.assign({}, noteResource);
|
||||||
|
debugTemp.data = debugTemp.data ? debugTemp.data.substr(0, 32) + '...' : debugTemp.data;
|
||||||
|
importOptions.onError(new Error('This resource was not added because it has no ID or no content: ' + JSON.stringify(debugTemp)));
|
||||||
|
} else {
|
||||||
let r = {
|
let r = {
|
||||||
id: resourceId,
|
id: resourceId,
|
||||||
data: decodedData,
|
data: decodedData,
|
||||||
@ -409,6 +417,8 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
note.resources.push(r);
|
note.resources.push(r);
|
||||||
|
}
|
||||||
|
|
||||||
noteResource = null;
|
noteResource = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user