opened file change detection now useable on all note types

This commit is contained in:
zadam
2021-04-24 21:56:44 +02:00
parent dcd35b1ea2
commit ccac46527c
13 changed files with 100 additions and 49 deletions

View File

@@ -3,6 +3,7 @@
const protectedSessionService = require('../../services/protected_session');
const repository = require('../../services/repository');
const utils = require('../../services/utils');
const log = require('../../services/log');
const noteRevisionService = require('../../services/note_revisions');
const tmp = require('tmp');
const fs = require('fs');
@@ -122,6 +123,8 @@ function saveToTmpDir(req) {
fs.writeSync(tmpObj.fd, note.getContent());
fs.closeSync(tmpObj.fd);
log.info(`Saved temporary file for note ${noteId} into ${tmpObj.name}`);
if (utils.isElectron()) {
chokidar.watch(tmpObj.name).on('change', (path, stats) => {
ws.sendMessageToAllClients({
@@ -130,8 +133,6 @@ function saveToTmpDir(req) {
lastModifiedMs: stats.atimeMs,
filePath: tmpObj.name
});
console.log(stats, path);
});
}

View File

@@ -285,6 +285,8 @@ function uploadModifiedFile(req) {
return [404, `Note ${noteId} has not been found`];
}
log.info(`Updating note ${noteId} with content from ${filePath}`);
noteRevisionService.createNoteRevision(note);
const fileContent = fs.readFileSync(filePath);

View File

@@ -186,7 +186,7 @@ function register(app) {
route(GET, '/api/notes/:noteId/download', [auth.checkApiAuthOrElectron], filesRoute.downloadFile);
// this "hacky" path is used for easier referencing of CSS resources
route(GET, '/api/notes/download/:noteId', [auth.checkApiAuthOrElectron], filesRoute.downloadFile);
apiRoute(POST, '/api/notes/:noteId/saveToTmpDir', filesRoute.saveToTmpDir);
apiRoute(POST, '/api/notes/:noteId/save-to-tmp-dir', filesRoute.saveToTmpDir);
apiRoute(GET, '/api/notes/:noteId/attributes', attributesRoute.getEffectiveNoteAttributes);
apiRoute(POST, '/api/notes/:noteId/attributes', attributesRoute.addNoteAttribute);