attachment preview, closes #210

This commit is contained in:
azivner 2018-11-16 18:40:58 +01:00
parent 94565e3ec0
commit 6b65592d7a
4 changed files with 30 additions and 2 deletions

View File

@ -8,6 +8,8 @@ const $component = $('#note-detail-file');
const $fileName = $("#file-filename"); const $fileName = $("#file-filename");
const $fileType = $("#file-filetype"); const $fileType = $("#file-filetype");
const $fileSize = $("#file-filesize"); const $fileSize = $("#file-filesize");
const $previewRow = $("#file-preview-row");
const $previewContent = $("#file-preview-content");
const $downloadButton = $("#file-download"); const $downloadButton = $("#file-download");
const $openButton = $("#file-open"); const $openButton = $("#file-open");
@ -22,6 +24,9 @@ async function show() {
$fileName.text(attributeMap.originalFileName || "?"); $fileName.text(attributeMap.originalFileName || "?");
$fileSize.text((attributeMap.fileSize || "?") + " bytes"); $fileSize.text((attributeMap.fileSize || "?") + " bytes");
$fileType.text(currentNote.mime); $fileType.text(currentNote.mime);
$previewRow.toggle(!!currentNote.content);
$previewContent.text(currentNote.content);
} }
$downloadButton.click(() => utils.download(getFileUrl())); $downloadButton.click(() => utils.download(getFileUrl()));

View File

@ -463,6 +463,14 @@ html.theme-dark body {
max-width: 100%; max-width: 100%;
} }
#file-preview-content {
background-color: #f6f6f6;
padding: 15px;
max-width: 600px;
max-height: 300px;
overflow: auto;
}
.pointer { .pointer {
cursor: pointer; cursor: pointer;
} }

View File

@ -13,9 +13,18 @@ async function getNote(req) {
} }
if (note.type === 'file' || note.type === 'image') { if (note.type === 'file' || note.type === 'image') {
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 // no need to transfer (potentially large) file/image payload for this request
note.content = null; note.content = null;
} }
}
return note; return note;
} }

View File

@ -12,6 +12,12 @@
<th>File size:</th> <th>File size:</th>
<td id="file-filesize"></td> <td id="file-filesize"></td>
</tr> </tr>
<tr id="file-preview-row">
<th>Preview:</th>
<td>
<pre id="file-preview-content"></pre>
</td>
</tr>
<tr> <tr>
<td> <td>
<button id="file-download" class="btn btn-primary" type="button">Download</button> <button id="file-download" class="btn btn-primary" type="button">Download</button>