mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
upload of modified open file WIP
This commit is contained in:
parent
6d2d72fa7f
commit
4ff7e0813d
@ -121,14 +121,14 @@ ws.subscribeToMessages(async message => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === 'task-error') {
|
if (message.type === 'taskError') {
|
||||||
toastService.closePersistent(message.taskId);
|
toastService.closePersistent(message.taskId);
|
||||||
toastService.showError(message.message);
|
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));
|
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.");
|
const toast = makeToast(message.taskId, "Export finished successfully.");
|
||||||
toast.closeAfter = 5000;
|
toast.closeAfter = 5000;
|
||||||
|
|
||||||
|
@ -153,12 +153,12 @@ ws.subscribeToMessages(async message => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === 'task-error') {
|
if (message.type === 'taskError') {
|
||||||
toastService.closePersistent(message.taskId);
|
toastService.closePersistent(message.taskId);
|
||||||
toastService.showError(message.message);
|
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));
|
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.");
|
const toast = makeToast(message.taskId, "Delete finished successfully.");
|
||||||
toast.closeAfter = 5000;
|
toast.closeAfter = 5000;
|
||||||
|
|
||||||
@ -167,16 +167,16 @@ ws.subscribeToMessages(async message => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ws.subscribeToMessages(async message => {
|
ws.subscribeToMessages(async message => {
|
||||||
if (message.taskType !== 'undelete-notes') {
|
if (message.taskType !== 'undeleteNotes') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === 'task-error') {
|
if (message.type === 'taskError') {
|
||||||
toastService.closePersistent(message.taskId);
|
toastService.closePersistent(message.taskId);
|
||||||
toastService.showError(message.message);
|
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));
|
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.");
|
const toast = makeToast(message.taskId, "Undeleting notes finished successfully.");
|
||||||
toast.closeAfter = 5000;
|
toast.closeAfter = 5000;
|
||||||
|
|
||||||
|
31
src/public/app/services/file_watcher.js
Normal file
31
src/public/app/services/file_watcher.js
Normal file
@ -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
|
||||||
|
}
|
@ -52,12 +52,12 @@ ws.subscribeToMessages(async message => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === 'task-error') {
|
if (message.type === 'taskError') {
|
||||||
toastService.closePersistent(message.taskId);
|
toastService.closePersistent(message.taskId);
|
||||||
toastService.showError(message.message);
|
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));
|
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.");
|
const toast = makeToast(message.taskId, "Import finished successfully.");
|
||||||
toast.closeAfter = 5000;
|
toast.closeAfter = 5000;
|
||||||
|
|
||||||
|
@ -89,18 +89,18 @@ function makeToast(message, protectingLabel, text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ws.subscribeToMessages(async message => {
|
ws.subscribeToMessages(async message => {
|
||||||
if (message.taskType !== 'protect-notes') {
|
if (message.taskType !== 'protectNotes') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const protectingLabel = message.data.protect ? "Protecting" : "Unprotecting";
|
const protectingLabel = message.data.protect ? "Protecting" : "Unprotecting";
|
||||||
|
|
||||||
if (message.type === 'task-error') {
|
if (message.type === 'taskError') {
|
||||||
toastService.closePersistent(message.taskId);
|
toastService.closePersistent(message.taskId);
|
||||||
toastService.showError(message.message);
|
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));
|
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.");
|
const toast = makeToast(message, protectingLabel, protectingLabel + " finished successfully.");
|
||||||
toast.closeAfter = 3000;
|
toast.closeAfter = 3000;
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ async function sortAlphabetically(noteId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ws.subscribeToMessages(message => {
|
ws.subscribeToMessages(message => {
|
||||||
if (message.type === 'open-note') {
|
if (message.type === 'openNote') {
|
||||||
appContext.tabManager.activateOrOpenNote(message.noteId);
|
appContext.tabManager.activateOrOpenNote(message.noteId);
|
||||||
|
|
||||||
if (utils.isElectron()) {
|
if (utils.isElectron()) {
|
||||||
|
@ -59,7 +59,7 @@ async function handleMessage(event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === 'frontend-update') {
|
if (message.type === 'frontend-update') {
|
||||||
let {entityChanges, lastSyncedPush} = message.data;
|
let {entityChanges} = message.data;
|
||||||
lastPingTs = Date.now();
|
lastPingTs = Date.now();
|
||||||
|
|
||||||
if (entityChanges.length > 0) {
|
if (entityChanges.length > 0) {
|
||||||
|
@ -144,7 +144,7 @@ function processContent(images, note, content) {
|
|||||||
function openNote(req) {
|
function openNote(req) {
|
||||||
if (utils.isElectron()) {
|
if (utils.isElectron()) {
|
||||||
ws.sendMessageToAllClients({
|
ws.sendMessageToAllClients({
|
||||||
type: 'open-note',
|
type: 'openNote',
|
||||||
noteId: req.params.noteId
|
noteId: req.params.noteId
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ const sql = require('../../services/sql');
|
|||||||
const utils = require('../../services/utils');
|
const utils = require('../../services/utils');
|
||||||
const log = require('../../services/log');
|
const log = require('../../services/log');
|
||||||
const TaskContext = require('../../services/task_context');
|
const TaskContext = require('../../services/task_context');
|
||||||
|
const fs = require('fs');
|
||||||
|
const noteRevisionService = require("../../services/note_revisions.js");
|
||||||
|
|
||||||
function getNote(req) {
|
function getNote(req) {
|
||||||
const noteId = req.params.noteId;
|
const noteId = req.params.noteId;
|
||||||
@ -80,7 +82,7 @@ function deleteNote(req) {
|
|||||||
function undeleteNote(req) {
|
function undeleteNote(req) {
|
||||||
const note = repository.getNote(req.params.noteId);
|
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);
|
noteService.undeleteNote(note, note.deleteId, taskContext);
|
||||||
|
|
||||||
@ -109,7 +111,7 @@ function protectNote(req) {
|
|||||||
const protect = !!parseInt(req.params.isProtected);
|
const protect = !!parseInt(req.params.isProtected);
|
||||||
const includingSubTree = !!parseInt(req.query.subtree);
|
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);
|
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 = {
|
module.exports = {
|
||||||
getNote,
|
getNote,
|
||||||
updateNote,
|
updateNote,
|
||||||
@ -286,5 +309,6 @@ module.exports = {
|
|||||||
changeTitle,
|
changeTitle,
|
||||||
duplicateSubtree,
|
duplicateSubtree,
|
||||||
eraseDeletedNotesNow,
|
eraseDeletedNotesNow,
|
||||||
getDeleteNotesPreview
|
getDeleteNotesPreview,
|
||||||
|
uploadModifiedFile
|
||||||
};
|
};
|
||||||
|
@ -165,6 +165,7 @@ function register(app) {
|
|||||||
apiRoute(POST, '/api/notes/erase-deleted-notes-now', notesApiRoute.eraseDeletedNotesNow);
|
apiRoute(POST, '/api/notes/erase-deleted-notes-now', notesApiRoute.eraseDeletedNotesNow);
|
||||||
apiRoute(PUT, '/api/notes/:noteId/change-title', notesApiRoute.changeTitle);
|
apiRoute(PUT, '/api/notes/:noteId/change-title', notesApiRoute.changeTitle);
|
||||||
apiRoute(POST, '/api/notes/:noteId/duplicate/:parentNoteId', notesApiRoute.duplicateSubtree);
|
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);
|
apiRoute(GET, '/api/edited-notes/:date', noteRevisionsApiRoute.getEditedNotesOnDate);
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class TaskContext {
|
|||||||
this.lastSentCountTs = Date.now();
|
this.lastSentCountTs = Date.now();
|
||||||
|
|
||||||
ws.sendMessageToAllClients({
|
ws.sendMessageToAllClients({
|
||||||
type: 'task-progress-count',
|
type: 'taskProgressCount',
|
||||||
taskId: this.taskId,
|
taskId: this.taskId,
|
||||||
taskType: this.taskType,
|
taskType: this.taskType,
|
||||||
data: this.data,
|
data: this.data,
|
||||||
@ -49,7 +49,7 @@ class TaskContext {
|
|||||||
|
|
||||||
reportError(message) {
|
reportError(message) {
|
||||||
ws.sendMessageToAllClients({
|
ws.sendMessageToAllClients({
|
||||||
type: 'task-error',
|
type: 'taskError',
|
||||||
taskId: this.taskId,
|
taskId: this.taskId,
|
||||||
taskType: this.taskType,
|
taskType: this.taskType,
|
||||||
data: this.data,
|
data: this.data,
|
||||||
@ -59,7 +59,7 @@ class TaskContext {
|
|||||||
|
|
||||||
taskSucceeded(result) {
|
taskSucceeded(result) {
|
||||||
ws.sendMessageToAllClients({
|
ws.sendMessageToAllClients({
|
||||||
type: 'task-succeeded',
|
type: 'taskSucceeded',
|
||||||
taskId: this.taskId,
|
taskId: this.taskId,
|
||||||
taskType: this.taskType,
|
taskType: this.taskType,
|
||||||
data: this.data,
|
data: this.data,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user