upload of modified open file WIP

This commit is contained in:
zadam 2021-04-24 11:39:44 +02:00
parent 6d2d72fa7f
commit 4ff7e0813d
11 changed files with 82 additions and 26 deletions

View File

@ -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;

View File

@ -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;

View 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
}

View File

@ -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;

View File

@ -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;

View File

@ -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()) {

View File

@ -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) {

View File

@ -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
});

View File

@ -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
};

View File

@ -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);

View File

@ -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,