Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
renamed "attachment" to "file" for consistency
azivner7464835058ca
diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.jsindex 560f0d1f3e..8ffe1a6f8f 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.jssimilarity index 69%rename from src/public/javascripts/services/attachment.jsrename to src/public/javascripts/services/file.jsindex 20689f354a..20052e1101 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 filediff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.jsindex 081e6d3f3d..c8725880ba 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.jsdeleted file mode 100644index f6a9ceb71a..0000000000--- 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 filediff --git a/src/public/javascripts/services/note_detail_file.js b/src/public/javascripts/services/note_detail_file.jsnew file mode 100644index 0000000000..84a03f6beb--- /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 filediff --git a/src/public/javascripts/services/note_type.js b/src/public/javascripts/services/note_type.jsindex 8ae1b2f47e..83c5dfe92d 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 searchdiff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.cssindex a7aff3af80..fa3dd610ca 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 filediff --git a/src/routes/api/export.js b/src/routes/api/export.jsindex a4775d02ba..657a3154c5 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.jssimilarity index 95%rename from src/routes/api/attachments.jsrename to src/routes/api/file_upload.jsindex deb3de4b30..6567c2193c 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, reconst 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.jsindex f49e476a9a..9b9bebc436 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 requestdetail.content = null;}diff --git a/src/routes/routes.js b/src/routes/routes.jsindex 9abb82a74e..e2a5ebf43b 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.ejsindex e3ede5da40..c21fb3ff38 100644--- a/src/views/index.ejs+++ b/src/views/index.ejs@@ -126,7 +126,7 @@<li><a id="show-note-revisions-button">Note revisions</a></li><li><a class="show-labels-button"><kbd>Alt+L</kbd> Labels</a></li><li><a id="show-source-button"><kbd>Ctrl+U</kbd> HTML source</a></li>- <li><a id="upload-attachment-button">Upload attachment</a></li>+ <li><a id="upload-file-button">Upload file</a></li></ul></div></div>@@ -177,31 +177,31 @@<div id="note-detail-render" class="note-detail-component"></div>- <div id="note-detail-attachment" class="note-detail-component">- <table id="attachment-table">+ <div id="note-detail-file" class="note-detail-component">+ <table id="file-table"><tr><th>File name:</th>- <td id="attachment-filename"></td>+ <td id="file-filename"></td></tr><tr><th>File type:</th>- <td id="attachment-filetype"></td>+ <td id="file-filetype"></td></tr><tr><th>File size:</th>- <td id="attachment-filesize"></td>+ <td id="file-filesize"></td></tr><tr><td>- <button id="attachment-download" class="btn btn-primary" type="button">Download</button>+ <button id="file-download" class="btn btn-primary" type="button">Download</button> - <button id="attachment-open" class="btn btn-primary" type="button">Open</button>+ <button id="file-open" class="btn btn-primary" type="button">Open</button></td></tr></table></div>- <input type="file" id="attachment-upload" style="display: none" />+ <input type="file" id="file-upload" style="display: none" /></div><div id="label-list">