diff --git a/src/public/javascripts/services/note_detail_file.js b/src/public/javascripts/services/note_detail_file.js index 342df3e31..dcdbc3c2c 100644 --- a/src/public/javascripts/services/note_detail_file.js +++ b/src/public/javascripts/services/note_detail_file.js @@ -8,6 +8,8 @@ const $component = $('#note-detail-file'); const $fileName = $("#file-filename"); const $fileType = $("#file-filetype"); const $fileSize = $("#file-filesize"); +const $previewRow = $("#file-preview-row"); +const $previewContent = $("#file-preview-content"); const $downloadButton = $("#file-download"); const $openButton = $("#file-open"); @@ -22,6 +24,9 @@ async function show() { $fileName.text(attributeMap.originalFileName || "?"); $fileSize.text((attributeMap.fileSize || "?") + " bytes"); $fileType.text(currentNote.mime); + + $previewRow.toggle(!!currentNote.content); + $previewContent.text(currentNote.content); } $downloadButton.click(() => utils.download(getFileUrl())); diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index dbe5db813..6f5b0677d 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -463,6 +463,14 @@ html.theme-dark body { max-width: 100%; } +#file-preview-content { + background-color: #f6f6f6; + padding: 15px; + max-width: 600px; + max-height: 300px; + overflow: auto; +} + .pointer { cursor: pointer; } diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js index 6b57cc5c4..225a7d261 100644 --- a/src/routes/api/notes.js +++ b/src/routes/api/notes.js @@ -13,8 +13,17 @@ async function getNote(req) { } if (note.type === 'file' || note.type === 'image') { - // no need to transfer (potentially large) file/image payload for this request - note.content = null; + if (note.type === 'file' && note.mime.startsWith('text/')) { + note.content = note.content.toString("UTF-8"); + + if (note.content.length > 10000) { + note.content = note.content.substr(0, 10000) + "..."; + } + } + else { + // no need to transfer (potentially large) file/image payload for this request + note.content = null; + } } return note; diff --git a/src/views/details/file.ejs b/src/views/details/file.ejs index cf17eed9c..a0363aedb 100644 --- a/src/views/details/file.ejs +++ b/src/views/details/file.ejs @@ -12,6 +12,12 @@