upload of modified open file WIP

This commit is contained in:
zadam
2021-04-24 11:39:59 +02:00
parent 4ff7e0813d
commit a74741343e
6 changed files with 181 additions and 15 deletions

View File

@@ -7,6 +7,8 @@ const noteRevisionService = require('../../services/note_revisions');
const tmp = require('tmp');
const fs = require('fs');
const { Readable } = require('stream');
const chokidar = require('chokidar');
const ws = require('../../services/ws');
function updateFile(req) {
const {noteId} = req.params;
@@ -120,6 +122,19 @@ function saveToTmpDir(req) {
fs.writeSync(tmpObj.fd, note.getContent());
fs.closeSync(tmpObj.fd);
if (utils.isElectron()) {
chokidar.watch(tmpObj.name).on('change', (path, stats) => {
ws.sendMessageToAllClients({
type: 'openedFileUpdated',
noteId: noteId,
lastModifiedMs: stats.atimeMs,
filePath: tmpObj.name
});
console.log(stats, path);
});
}
return {
tmpFilePath: tmpObj.name
};