1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop, Cli: Remove unnecessary warning when importing ENEX file

This commit is contained in:
Laurent Cozic 2023-12-17 12:00:05 +00:00
parent bb47c59414
commit 7e50b117ed

View File

@ -151,18 +151,22 @@ interface ExtractedNote extends NoteEntity {
tags?: string[]; tags?: string[];
title?: string; title?: string;
bodyXml?: string; bodyXml?: string;
// is_todo?: boolean;
} }
// At this point we have the resource has it's been parsed from the XML, but additional // At this point we have the resource as it's been parsed from the XML, but
// processing needs to be done to get the final resource file, its size, MD5, etc. // additional processing needs to be done to get the final resource file, its
// size, MD5, etc.
async function processNoteResource(resource: ExtractedResource) { async function processNoteResource(resource: ExtractedResource) {
if (!resource.hasData) { const handleNoDataResource = async (resource: ExtractedResource, setId: boolean) => {
// Some resources have no data, go figure, so we need a special case for this. if (setId) resource.id = md5(Date.now() + Math.random());
resource.id = md5(Date.now() + Math.random());
resource.size = 0; resource.size = 0;
resource.dataFilePath = `${Setting.value('tempDir')}/${resource.id}.empty`; resource.dataFilePath = `${Setting.value('tempDir')}/${resource.id}.empty`;
await fs.writeFile(resource.dataFilePath, ''); await fs.writeFile(resource.dataFilePath, '');
};
if (!resource.hasData) {
// Some resources have no data, go figure, so we need a special case for this.
await handleNoDataResource(resource, true);
} else { } else {
if (resource.dataEncoding === 'base64') { if (resource.dataEncoding === 'base64') {
const decodedFilePath = `${resource.dataFilePath}.decoded`; const decodedFilePath = `${resource.dataFilePath}.decoded`;
@ -176,16 +180,19 @@ async function processNoteResource(resource: ExtractedResource) {
resource.size = stats.size; resource.size = stats.size;
if (!resource.id) { if (!resource.id) {
// If no resource ID is present, the resource ID is actually the MD5 of the data. // If no resource ID is present, the resource ID is actually the MD5
// This ID will match the "hash" attribute of the corresponding <en-media> tag. // of the data. This ID will match the "hash" attribute of the
// resourceId = md5(decodedData); // corresponding <en-media> tag. resourceId = md5(decodedData);
resource.id = await md5File(resource.dataFilePath); resource.id = await md5File(resource.dataFilePath);
} }
if (!resource.id || !resource.size) { if (!resource.id || !resource.size) {
const debugTemp = { ...resource }; // Don't throw an error because it happens semi-frequently,
debugTemp.data = debugTemp.data ? `${debugTemp.data.substr(0, 32)}...` : debugTemp.data; // especially on notes that comes from the Evernote Web Clipper and
throw new Error(`This resource was not added because it has no ID or no content: ${JSON.stringify(debugTemp)}`); // we can't do anything about it. Previously we would throw the
// error "This resource was not added because it has no ID or no
// content".
await handleNoDataResource(resource, !resource.id);
} }
} }