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
upload of modified open file WIP
zadam4ff7e0813dfa
diff --git a/src/public/app/dialogs/export.js b/src/public/app/dialogs/export.jsindex bd1892044f..690d430868 100644--- a/src/public/app/dialogs/export.js+++ b/src/public/app/dialogs/export.js@@ -121,14 +121,14 @@ ws.subscribeToMessages(async message => {return;}- if (message.type === 'task-error') {+ if (message.type === 'taskError') {toastService.closePersistent(message.taskId);toastService.showError(message.message);}- else if (message.type === 'task-progress-count') {+ else if (message.type === 'taskProgressCount') {toastService.showPersistent(makeToast(message.taskId, "Export in progress: " + message.progressCount));}- else if (message.type === 'task-succeeded') {+ else if (message.type === 'taskSucceeded') {const toast = makeToast(message.taskId, "Export finished successfully.");toast.closeAfter = 5000;diff --git a/src/public/app/services/branches.js b/src/public/app/services/branches.jsindex 8c7c482d03..f001abdee2 100644--- a/src/public/app/services/branches.js+++ b/src/public/app/services/branches.js@@ -153,12 +153,12 @@ ws.subscribeToMessages(async message => {return;}- if (message.type === 'task-error') {+ if (message.type === 'taskError') {toastService.closePersistent(message.taskId);toastService.showError(message.message);- } else if (message.type === 'task-progress-count') {+ } else if (message.type === 'taskProgressCount') {toastService.showPersistent(makeToast(message.taskId, "Delete notes in progress: " + message.progressCount));- } else if (message.type === 'task-succeeded') {+ } else if (message.type === 'taskSucceeded') {const toast = makeToast(message.taskId, "Delete finished successfully.");toast.closeAfter = 5000;@@ -167,16 +167,16 @@ ws.subscribeToMessages(async message => {});ws.subscribeToMessages(async message => {- if (message.taskType !== 'undelete-notes') {+ if (message.taskType !== 'undeleteNotes') {return;}- if (message.type === 'task-error') {+ if (message.type === 'taskError') {toastService.closePersistent(message.taskId);toastService.showError(message.message);- } else if (message.type === 'task-progress-count') {+ } else if (message.type === 'taskProgressCount') {toastService.showPersistent(makeToast(message.taskId, "Undeleting notes in progress: " + message.progressCount));- } else if (message.type === 'task-succeeded') {+ } else if (message.type === 'taskSucceeded') {const toast = makeToast(message.taskId, "Undeleting notes finished successfully.");toast.closeAfter = 5000;diff --git a/src/public/app/services/file_watcher.js b/src/public/app/services/file_watcher.jsnew file mode 100644index 0000000000..2d53ce3c55--- /dev/null+++ b/src/public/app/services/file_watcher.js@@ -0,0 +1,31 @@+import ws from "./ws.js";+import appContext from "./app_context.js";++const fileModificationStatus = {};++function getFileModificationStatus(noteId) {+ return fileModificationStatus[noteId];+}++function fileModificationUploaded(noteId) {+ delete fileModificationStatus[noteId];+}++ws.subscribeToMessages(async message => {+ if (message.type !== 'openedFileUpdated') {+ return;+ }++ fileModificationStatus[message.noteId] = message;++ appContext.triggerEvent('openedFileUpdated', {+ noteId: message.noteId,+ lastModifiedMs: message.lastModifiedMs,+ filePath: message.filePath+ });+});++export default {+ getFileModificationStatus,+ fileModificationUploaded+}diff --git a/src/public/app/services/import.js b/src/public/app/services/import.jsindex 367d4ffeaf..fcc8c1b1de 100644--- a/src/public/app/services/import.js+++ b/src/public/app/services/import.js@@ -52,12 +52,12 @@ ws.subscribeToMessages(async message => {return;}- if (message.type === 'task-error') {+ if (message.type === 'taskError') {toastService.closePersistent(message.taskId);toastService.showError(message.message);- } else if (message.type === 'task-progress-count') {+ } else if (message.type === 'taskProgressCount') {toastService.showPersistent(makeToast(message.taskId, "Import in progress: " + message.progressCount));- } else if (message.type === 'task-succeeded') {+ } else if (message.type === 'taskSucceeded') {const toast = makeToast(message.taskId, "Import finished successfully.");toast.closeAfter = 5000;diff --git a/src/public/app/services/protected_session.js b/src/public/app/services/protected_session.jsindex 46b83b5a30..42550a14e8 100644--- a/src/public/app/services/protected_session.js+++ b/src/public/app/services/protected_session.js@@ -89,18 +89,18 @@ function makeToast(message, protectingLabel, text) {}ws.subscribeToMessages(async message => {- if (message.taskType !== 'protect-notes') {+ if (message.taskType !== 'protectNotes') {return;}const protectingLabel = message.data.protect ? "Protecting" : "Unprotecting";- if (message.type === 'task-error') {+ if (message.type === 'taskError') {toastService.closePersistent(message.taskId);toastService.showError(message.message);- } else if (message.type === 'task-progress-count') {+ } else if (message.type === 'taskProgressCount') {toastService.showPersistent(makeToast(message, protectingLabel,protectingLabel + " in progress: " + message.progressCount));- } else if (message.type === 'task-succeeded') {+ } else if (message.type === 'taskSucceeded') {const toast = makeToast(message, protectingLabel, protectingLabel + " finished successfully.");toast.closeAfter = 3000;diff --git a/src/public/app/services/tree.js b/src/public/app/services/tree.jsindex 1d7f40fb0c..07c6badae6 100644--- a/src/public/app/services/tree.js+++ b/src/public/app/services/tree.js@@ -127,7 +127,7 @@ async function sortAlphabetically(noteId) {}ws.subscribeToMessages(message => {- if (message.type === 'open-note') {+ if (message.type === 'openNote') {appContext.tabManager.activateOrOpenNote(message.noteId);if (utils.isElectron()) {diff --git a/src/public/app/services/ws.js b/src/public/app/services/ws.jsindex e2b1715667..4a26de88b7 100644--- a/src/public/app/services/ws.js+++ b/src/public/app/services/ws.js@@ -59,7 +59,7 @@ async function handleMessage(event) {}if (message.type === 'frontend-update') {- let {entityChanges, lastSyncedPush} = message.data;+ let {entityChanges} = message.data;lastPingTs = Date.now();if (entityChanges.length > 0) {diff --git a/src/routes/api/clipper.js b/src/routes/api/clipper.jsindex 257e06bff1..eeef650348 100644--- a/src/routes/api/clipper.js+++ b/src/routes/api/clipper.js@@ -144,7 +144,7 @@ function processContent(images, note, content) {function openNote(req) {if (utils.isElectron()) {ws.sendMessageToAllClients({- type: 'open-note',+ type: 'openNote',noteId: req.params.noteId});diff --git a/src/routes/api/notes.js b/src/routes/api/notes.jsindex 60eb242d9f..a8df5b1661 100644--- a/src/routes/api/notes.js+++ b/src/routes/api/notes.js@@ -7,6 +7,8 @@ const sql = require('../../services/sql');const utils = require('../../services/utils');const log = require('../../services/log');const TaskContext = require('../../services/task_context');+const fs = require('fs');+const noteRevisionService = require("../../services/note_revisions.js");function getNote(req) {const noteId = req.params.noteId;@@ -80,7 +82,7 @@ function deleteNote(req) {function undeleteNote(req) {const note = repository.getNote(req.params.noteId);- const taskContext = TaskContext.getInstance(utils.randomString(10), 'undelete-notes');+ const taskContext = TaskContext.getInstance(utils.randomString(10), 'undeleteNotes');noteService.undeleteNote(note, note.deleteId, taskContext);@@ -109,7 +111,7 @@ function protectNote(req) {const protect = !!parseInt(req.params.isProtected);const includingSubTree = !!parseInt(req.query.subtree);- const taskContext = new TaskContext(utils.randomString(10), 'protect-notes', {protect});+ const taskContext = new TaskContext(utils.randomString(10), 'protectNotes', {protect});noteService.protectNoteRecursively(note, protect, includingSubTree, taskContext);@@ -273,6 +275,27 @@ function getDeleteNotesPreview(req) {};}+function uploadModifiedFile(req) {+ const noteId = req.params.noteId;+ const {filePath} = req.body;++ const note = repository.getNote(noteId);++ if (!note) {+ return [404, `Note ${noteId} has not been found`];+ }++ noteRevisionService.createNoteRevision(note);++ const fileContent = fs.readFileSync(filePath);++ if (!fileContent) {+ return [400, `File ${fileContent} is empty`];+ }++ note.setContent(fileContent);+}+module.exports = {getNote,updateNote,@@ -286,5 +309,6 @@ module.exports = {changeTitle,duplicateSubtree,eraseDeletedNotesNow,- getDeleteNotesPreview+ getDeleteNotesPreview,+ uploadModifiedFile};diff --git a/src/routes/routes.js b/src/routes/routes.jsindex 137d7b5095..4c9e9a6c78 100644--- a/src/routes/routes.js+++ b/src/routes/routes.js@@ -165,6 +165,7 @@ function register(app) {apiRoute(POST, '/api/notes/erase-deleted-notes-now', notesApiRoute.eraseDeletedNotesNow);apiRoute(PUT, '/api/notes/:noteId/change-title', notesApiRoute.changeTitle);apiRoute(POST, '/api/notes/:noteId/duplicate/:parentNoteId', notesApiRoute.duplicateSubtree);+ apiRoute(POST, '/api/notes/:noteId/upload-modified-file', notesApiRoute.uploadModifiedFile);apiRoute(GET, '/api/edited-notes/:date', noteRevisionsApiRoute.getEditedNotesOnDate);diff --git a/src/services/task_context.js b/src/services/task_context.jsindex 0edd3c0bba..4034096472 100644--- a/src/services/task_context.js+++ b/src/services/task_context.js@@ -38,7 +38,7 @@ class TaskContext {this.lastSentCountTs = Date.now();ws.sendMessageToAllClients({- type: 'task-progress-count',+ type: 'taskProgressCount',taskId: this.taskId,taskType: this.taskType,data: this.data,@@ -49,7 +49,7 @@ class TaskContext {reportError(message) {ws.sendMessageToAllClients({- type: 'task-error',+ type: 'taskError',taskId: this.taskId,taskType: this.taskType,data: this.data,@@ -59,7 +59,7 @@ class TaskContext {taskSucceeded(result) {ws.sendMessageToAllClients({- type: 'task-succeeded',+ type: 'taskSucceeded',taskId: this.taskId,taskType: this.taskType,data: this.data,