From f4b57f4c5733bfc3c2650b55ab453e8de735c7b7 Mon Sep 17 00:00:00 2001 From: azivner Date: Thu, 1 Mar 2018 22:30:06 -0500 Subject: [PATCH] Allow attachments to be included in the scripts, closes #66 --- src/entities/note.js | 3 ++- src/routes/api/script.js | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/entities/note.js b/src/entities/note.js index 3014b15b1..86bdb1679 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -24,7 +24,8 @@ class Note extends Entity { } isJavaScript() { - return this.type === "code" && this.mime === "application/javascript"; + return (this.type === "code" || this.type === "file") + && (this.mime === "application/javascript" || this.mime === "application/x-javascript"); } async getAttributes() { diff --git a/src/routes/api/script.js b/src/routes/api/script.js index b1674d8e6..cb3848b34 100644 --- a/src/routes/api/script.js +++ b/src/routes/api/script.js @@ -63,8 +63,10 @@ async function getSubTreeScripts(parentId, includedNoteIds, repository, isJavaSc SELECT notes.* FROM notes JOIN note_tree USING(noteId) WHERE note_tree.isDeleted = 0 AND notes.isDeleted = 0 - AND note_tree.parentNoteId = ? AND notes.type = 'code' - AND (notes.mime = 'application/javascript' OR notes.mime = 'text/html')`, [parentId]); + AND note_tree.parentNoteId = ? AND (notes.type = 'code' OR notes.type = 'file') + AND (notes.mime = 'application/javascript' + OR notes.mime = 'application/x-javascript' + OR notes.mime = 'text/html')`, [parentId]); let script = "\r\n"; @@ -77,7 +79,7 @@ async function getSubTreeScripts(parentId, includedNoteIds, repository, isJavaSc script += await getSubTreeScripts(child.noteId, includedNoteIds, repository); - if (!isJavaScript && child.mime === 'application/javascript') { + if (!isJavaScript && child.isJavaScript()) { child.content = ''; }