diff --git a/package.json b/package.json index 10549929d..88f5b2b73 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "electron-window-state": "5.0.3", "express": "4.17.1", "express-session": "1.17.1", - "file-type": "16.0.0", "fs-extra": "9.0.1", "helmet": "4.1.1", "html": "1.0.0", diff --git a/src/services/import/enex.js b/src/services/import/enex.js index f78994934..e80224af0 100644 --- a/src/services/import/enex.js +++ b/src/services/import/enex.js @@ -1,5 +1,4 @@ const sax = require("sax"); -const FileType = require('file-type'); const stream = require('stream'); const log = require("../log"); const utils = require("../utils"); @@ -138,17 +137,6 @@ function importEnex(taskContext, file, parentNote) { } else if (currentTag === 'mime') { resource.mime = text.toLowerCase(); - - if (text.startsWith("image/")) { - resource.title = "image"; - - // images don't have "file-name" tag so we'll create attribute here - resource.attributes.push({ - type: 'label', - name: 'originalFileName', - value: resource.title + "." + text.substr(6) // extension from mime type - }); - } } } else if (previousTag === 'note') { @@ -243,11 +231,7 @@ function importEnex(taskContext, file, parentNote) { const mediaRegex = new RegExp(`]*>`, 'g'); - const fileTypeFromBuffer = FileType.fromBuffer(resource.content); - if (fileTypeFromBuffer) { - // If fileType returns something for buffer, then set the mime given - resource.mime = fileTypeFromBuffer.mime; - } + resource.mime = resource.mime || "application/octet-stream"; const createFileNote = () => { const resourceNote = noteService.createNewNote({ @@ -260,7 +244,7 @@ function importEnex(taskContext, file, parentNote) { }).note; for (const attr of resource.attributes) { - noteEntity.addAttribute(attr.type, attr.name, attr.value); + resourceNote.addAttribute(attr.type, attr.name, attr.value); } updateDates(resourceNote.noteId, utcDateCreated, utcDateModified); @@ -274,10 +258,18 @@ function importEnex(taskContext, file, parentNote) { if (resource.mime && resource.mime.startsWith('image/')) { try { - const originalName = "image." + resource.mime.substr(6); + const originalName = (resource.title && resource.title !== 'resource') + ? resource.title + : `image.${resource.mime.substr(6)}`; // default if real name is not present const {url, note: imageNote} = imageService.saveImage(noteEntity.noteId, resource.content, originalName, taskContext.data.shrinkImages); + for (const attr of resource.attributes) { + if (attr.name !== 'originalFileName') { // this one is already saved in imageService + imageNote.addAttribute(attr.type, attr.name, attr.value); + } + } + updateDates(imageNote.noteId, utcDateCreated, utcDateModified); const imageLink = ``;