diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.js index 560f0d1f3..8ffe1a6f8 100644 --- a/src/public/javascripts/services/entrypoints.js +++ b/src/public/javascripts/services/entrypoints.js @@ -1,7 +1,7 @@ import utils from "./utils.js"; import treeService from "./tree.js"; import linkService from "./link.js"; -import attachmentService from "./attachment.js"; +import fileService from "./file.js"; import noteRevisionsDialog from "../dialogs/note_revisions.js"; import settingsDialog from "../dialogs/settings.js"; import addLinkDialog from "../dialogs/add_link.js"; @@ -125,7 +125,7 @@ function registerEntrypoints() { $("#note-title").bind('keydown', 'return', () => $("#note-detail-text").focus()); - $("#upload-attachment-button").click(attachmentService.uploadAttachment); + $("#upload-file-button").click(fileService.uploadFile); } export default { diff --git a/src/public/javascripts/services/attachment.js b/src/public/javascripts/services/file.js similarity index 70% rename from src/public/javascripts/services/attachment.js rename to src/public/javascripts/services/file.js index 20689f354..20052e110 100644 --- a/src/public/javascripts/services/attachment.js +++ b/src/public/javascripts/services/file.js @@ -2,16 +2,16 @@ import noteDetailService from "./note_detail.js"; import treeService from "./tree.js"; import server from "./server.js"; -function uploadAttachment() { - $("#attachment-upload").trigger('click'); +function uploadFile() { + $("#file-upload").trigger('click'); } -$("#attachment-upload").change(async function() { +$("#file-upload").change(async function() { const formData = new FormData(); formData.append('upload', this.files[0]); const resp = await $.ajax({ - url: baseApiUrl + 'attachments/upload/' + noteDetailService.getCurrentNoteId(), + url: baseApiUrl + 'files/upload/' + noteDetailService.getCurrentNoteId(), headers: server.getHeaders(), data: formData, type: 'POST', @@ -25,5 +25,5 @@ $("#attachment-upload").change(async function() { }); export default { - uploadAttachment + uploadFile } \ No newline at end of file diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index 081e6d3f3..c8725880b 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -10,7 +10,7 @@ import treeCache from "./tree_cache.js"; import NoteFull from "../entities/note_full.js"; import noteDetailCode from './note_detail_code.js'; import noteDetailText from './note_detail_text.js'; -import noteDetailAttachment from './note_detail_attachment.js'; +import noteDetailFile from './note_detail_file.js'; import noteDetailSearch from './note_detail_search.js'; import noteDetailRender from './note_detail_render.js'; @@ -34,7 +34,7 @@ let isNoteChanged = false; const components = { 'code': noteDetailCode, 'text': noteDetailText, - 'file': noteDetailAttachment, + 'file': noteDetailFile, 'search': noteDetailSearch, 'render': noteDetailRender }; diff --git a/src/public/javascripts/services/note_detail_attachment.js b/src/public/javascripts/services/note_detail_attachment.js deleted file mode 100644 index f6a9ceb71..000000000 --- a/src/public/javascripts/services/note_detail_attachment.js +++ /dev/null @@ -1,50 +0,0 @@ -import utils from "./utils.js"; -import server from "./server.js"; -import protectedSessionHolder from "./protected_session_holder.js"; -import noteDetailService from "./note_detail.js"; - -const $noteDetailAttachment = $('#note-detail-attachment'); - -const $attachmentFileName = $("#attachment-filename"); -const $attachmentFileType = $("#attachment-filetype"); -const $attachmentFileSize = $("#attachment-filesize"); -const $attachmentDownload = $("#attachment-download"); -const $attachmentOpen = $("#attachment-open"); - -async function show() { - const currentNote = noteDetailService.getCurrentNote(); - - const labels = await server.get('notes/' + currentNote.noteId + '/labels'); - const labelMap = utils.toObject(labels, l => [l.name, l.value]); - - $noteDetailAttachment.show(); - - $attachmentFileName.text(labelMap.original_file_name); - $attachmentFileSize.text(labelMap.file_size + " bytes"); - $attachmentFileType.text(currentNote.mime); -} - -$attachmentDownload.click(() => utils.download(getAttachmentUrl())); - -$attachmentOpen.click(() => { - if (utils.isElectron()) { - const open = require("open"); - - open(getAttachmentUrl()); - } - else { - window.location.href = getAttachmentUrl(); - } -}); - -function getAttachmentUrl() { - // electron needs absolute URL so we extract current host, port, protocol - return utils.getHost() + "/api/attachments/download/" + noteDetailService.getCurrentNoteId() - + "?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId()); -} - -export default { - show, - getContent: () => null, - focus: () => null -} \ No newline at end of file diff --git a/src/public/javascripts/services/note_detail_file.js b/src/public/javascripts/services/note_detail_file.js new file mode 100644 index 000000000..84a03f6be --- /dev/null +++ b/src/public/javascripts/services/note_detail_file.js @@ -0,0 +1,50 @@ +import utils from "./utils.js"; +import server from "./server.js"; +import protectedSessionHolder from "./protected_session_holder.js"; +import noteDetailService from "./note_detail.js"; + +const $noteDetailFile = $('#note-detail-file'); + +const $fileFileName = $("#file-filename"); +const $fileFileType = $("#file-filetype"); +const $fileFileSize = $("#file-filesize"); +const $fileDownload = $("#file-download"); +const $fileOpen = $("#file-open"); + +async function show() { + const currentNote = noteDetailService.getCurrentNote(); + + const labels = await server.get('notes/' + currentNote.noteId + '/labels'); + const labelMap = utils.toObject(labels, l => [l.name, l.value]); + + $noteDetailFile.show(); + + $fileFileName.text(labelMap.original_file_name); + $fileFileSize.text(labelMap.file_size + " bytes"); + $fileFileType.text(currentNote.mime); +} + +$fileDownload.click(() => utils.download(getFileUrl())); + +$fileOpen.click(() => { + if (utils.isElectron()) { + const open = require("open"); + + open(getFileUrl()); + } + else { + window.location.href = getFileUrl(); + } +}); + +function getFileUrl() { + // electron needs absolute URL so we extract current host, port, protocol + return utils.getHost() + "/api/files/download/" + noteDetailService.getCurrentNoteId() + + "?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId()); +} + +export default { + show, + getContent: () => null, + focus: () => null +} \ No newline at end of file diff --git a/src/public/javascripts/services/note_type.js b/src/public/javascripts/services/note_type.js index 8ae1b2f47..83c5dfe92 100644 --- a/src/public/javascripts/services/note_type.js +++ b/src/public/javascripts/services/note_type.js @@ -69,7 +69,7 @@ function NoteTypeModel() { return 'Render HTML note'; } else if (type === 'file') { - return 'Attachment'; + return 'File'; } else if (type === 'search') { // ignore and do nothing, "type" will be hidden since it's not possible to switch to and from search diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index a7aff3af8..fa3dd610c 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -285,7 +285,7 @@ div.ui-tooltip { margin-right: 5px; } -#attachment-table th, #attachment-table td { +#file-table th, #file-table td { padding: 10px; font-size: large; } \ No newline at end of file diff --git a/src/routes/api/export.js b/src/routes/api/export.js index a4775d02b..657a3154c 100644 --- a/src/routes/api/export.js +++ b/src/routes/api/export.js @@ -22,7 +22,7 @@ router.get('/:noteId/', auth.checkApiAuthOrElectron, wrap(async (req, res, next) pack.finalize(); - res.setHeader('Content-Disposition', 'attachment; filename="' + name + '.tar"'); + res.setHeader('Content-Disposition', 'file; filename="' + name + '.tar"'); res.setHeader('Content-Type', 'application/tar'); pack.pipe(res); diff --git a/src/routes/api/attachments.js b/src/routes/api/file_upload.js similarity index 96% rename from src/routes/api/attachments.js rename to src/routes/api/file_upload.js index deb3de4b3..6567c2193 100644 --- a/src/routes/api/attachments.js +++ b/src/routes/api/file_upload.js @@ -65,7 +65,7 @@ router.get('/download/:noteId', auth.checkApiAuthOrElectron, wrap(async (req, re const labelMap = await labels.getNoteLabelMap(noteId); const fileName = labelMap.original_file_name ? labelMap.original_file_name : note.title; - res.setHeader('Content-Disposition', 'attachment; filename=' + fileName); + res.setHeader('Content-Disposition', 'file; filename=' + fileName); res.setHeader('Content-Type', note.mime); res.send(note.content); diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js index f49e476a9..9b9bebc43 100644 --- a/src/routes/api/notes.js +++ b/src/routes/api/notes.js @@ -26,7 +26,7 @@ router.get('/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => { protected_session.decryptNote(req, detail); if (detail.type === 'file') { - // no need to transfer (potentially large) attachment payload for this request + // no need to transfer (potentially large) file payload for this request detail.content = null; } diff --git a/src/routes/routes.js b/src/routes/routes.js index 9abb82a74..e2a5ebf43 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -29,7 +29,7 @@ const imageRoute = require('./api/image'); const labelsRoute = require('./api/labels'); const scriptRoute = require('./api/script'); const senderRoute = require('./api/sender'); -const attachmentsRoute = require('./api/attachments'); +const filesRoute = require('./api/file_upload'); const searchRoute = require('./api/search'); function register(app) { @@ -63,7 +63,7 @@ function register(app) { app.use('/api/images', imageRoute); app.use('/api/script', scriptRoute); app.use('/api/sender', senderRoute); - app.use('/api/attachments', attachmentsRoute); + app.use('/api/files', filesRoute); app.use('/api/search', searchRoute); } diff --git a/src/views/index.ejs b/src/views/index.ejs index e3ede5da4..c21fb3ff3 100644 --- a/src/views/index.ejs +++ b/src/views/index.ejs @@ -126,7 +126,7 @@
File name: | -+ | |
---|---|---|
File type: | -+ | |
File size: | -+ | |
- + - + |