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

@ -8,9 +8,9 @@ fi
VERSION=$1 VERSION=$1
SERIES=${VERSION:0:4}-latest SERIES=${VERSION:0:4}-latest
sudo docker push zadam/trilium:$VERSION docker push zadam/trilium:$VERSION
sudo docker push zadam/trilium:$SERIES docker push zadam/trilium:$SERIES
if [[ $1 != *"beta"* ]]; then if [[ $1 != *"beta"* ]]; then
sudo docker push zadam/trilium:latest docker push zadam/trilium:latest
fi fi

123
package-lock.json generated
View File

@ -1085,6 +1085,15 @@
"resolved": "https://registry.npmjs.org/any-base/-/any-base-1.1.0.tgz", "resolved": "https://registry.npmjs.org/any-base/-/any-base-1.1.0.tgz",
"integrity": "sha512-uMgjozySS8adZZYePpaWs8cxB9/kdzmpX6SgJZ+wbz1K5eYk5QMYDVJaZKhxyIHUdnnJkfR7SVgStgH7LkGUyg==" "integrity": "sha512-uMgjozySS8adZZYePpaWs8cxB9/kdzmpX6SgJZ+wbz1K5eYk5QMYDVJaZKhxyIHUdnnJkfR7SVgStgH7LkGUyg=="
}, },
"anymatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz",
"integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==",
"requires": {
"normalize-path": "^3.0.0",
"picomatch": "^2.0.4"
}
},
"app-builder-bin": { "app-builder-bin": {
"version": "3.5.12", "version": "3.5.12",
"resolved": "https://registry.npmjs.org/app-builder-bin/-/app-builder-bin-3.5.12.tgz", "resolved": "https://registry.npmjs.org/app-builder-bin/-/app-builder-bin-3.5.12.tgz",
@ -1358,6 +1367,11 @@
"tar": "^6.1.0" "tar": "^6.1.0"
} }
}, },
"binary-extensions": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz",
"integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA=="
},
"binaryextensions": { "binaryextensions": {
"version": "4.15.0", "version": "4.15.0",
"resolved": "https://registry.npmjs.org/binaryextensions/-/binaryextensions-4.15.0.tgz", "resolved": "https://registry.npmjs.org/binaryextensions/-/binaryextensions-4.15.0.tgz",
@ -1573,6 +1587,14 @@
"concat-map": "0.0.1" "concat-map": "0.0.1"
} }
}, },
"braces": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
"requires": {
"fill-range": "^7.0.1"
}
},
"browser-process-hrtime": { "browser-process-hrtime": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/browser-process-hrtime/-/browser-process-hrtime-1.0.0.tgz", "resolved": "https://registry.npmjs.org/browser-process-hrtime/-/browser-process-hrtime-1.0.0.tgz",
@ -1884,6 +1906,21 @@
"parse5": "^3.0.1" "parse5": "^3.0.1"
} }
}, },
"chokidar": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.1.tgz",
"integrity": "sha512-9+s+Od+W0VJJzawDma/gvBNQqkTiqYTWLuZoyAsivsI4AaWTCzHG06/TMjsf1cYe9Cb97UCEhjz7HvnPk2p/tw==",
"requires": {
"anymatch": "~3.1.1",
"braces": "~3.0.2",
"fsevents": "~2.3.1",
"glob-parent": "~5.1.0",
"is-binary-path": "~2.1.0",
"is-glob": "~4.0.1",
"normalize-path": "~3.0.0",
"readdirp": "~3.5.0"
}
},
"chownr": { "chownr": {
"version": "1.1.4", "version": "1.1.4",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz",
@ -2784,9 +2821,9 @@
} }
}, },
"electron": { "electron": {
"version": "13.0.0-beta.16", "version": "13.0.0-beta.17",
"resolved": "https://registry.npmjs.org/electron/-/electron-13.0.0-beta.16.tgz", "resolved": "https://registry.npmjs.org/electron/-/electron-13.0.0-beta.17.tgz",
"integrity": "sha512-wNcSmRfzpqGctAaJURi4Mga+2+QUu1KeKBy57ASHJYTT0WekrnyJaGpeukS1DHcwFWwfGsz0+i61hbV5P6rs0w==", "integrity": "sha512-gfVN6e61mjM1x3h3z57hFb6fFrKee/LhPp0za5NK9MvnDTloO3ZMAK4wDUlmOZicMFYWgEFxSxjqD/DFCOP/GQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@electron/get": "^1.0.1", "@electron/get": "^1.0.1",
@ -3902,6 +3939,14 @@
"trim-repeated": "^1.0.0" "trim-repeated": "^1.0.0"
} }
}, },
"fill-range": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
"requires": {
"to-regex-range": "^5.0.1"
}
},
"finalhandler": { "finalhandler": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",
@ -4057,6 +4102,12 @@
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
}, },
"fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"optional": true
},
"function-bind": { "function-bind": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
@ -4212,6 +4263,14 @@
"path-is-absolute": "^1.0.0" "path-is-absolute": "^1.0.0"
} }
}, },
"glob-parent": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
"requires": {
"is-glob": "^4.0.1"
}
},
"glob-to-regexp": { "glob-to-regexp": {
"version": "0.4.1", "version": "0.4.1",
"resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz",
@ -4599,6 +4658,14 @@
"integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=",
"dev": true "dev": true
}, },
"is-binary-path": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
"integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==",
"requires": {
"binary-extensions": "^2.0.0"
}
},
"is-ci": { "is-ci": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-ci/-/is-ci-2.0.0.tgz", "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-2.0.0.tgz",
@ -4627,6 +4694,11 @@
"resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-0.1.1.tgz", "resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-0.1.1.tgz",
"integrity": "sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik=" "integrity": "sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik="
}, },
"is-extglob": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
"integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI="
},
"is-fullwidth-code-point": { "is-fullwidth-code-point": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
@ -4640,6 +4712,14 @@
"resolved": "https://registry.npmjs.org/is-function/-/is-function-1.0.2.tgz", "resolved": "https://registry.npmjs.org/is-function/-/is-function-1.0.2.tgz",
"integrity": "sha512-lw7DUp0aWXYg+CBCN+JKkcE0Q2RayZnSvnZBlwgxHBQhqt5pZNVy4Ri7H9GmmXkdu7LUthszM+Tor1u/2iBcpQ==" "integrity": "sha512-lw7DUp0aWXYg+CBCN+JKkcE0Q2RayZnSvnZBlwgxHBQhqt5pZNVy4Ri7H9GmmXkdu7LUthszM+Tor1u/2iBcpQ=="
}, },
"is-glob": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz",
"integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==",
"requires": {
"is-extglob": "^2.1.1"
}
},
"is-installed-globally": { "is-installed-globally": {
"version": "0.4.0", "version": "0.4.0",
"resolved": "https://registry.npmjs.org/is-installed-globally/-/is-installed-globally-0.4.0.tgz", "resolved": "https://registry.npmjs.org/is-installed-globally/-/is-installed-globally-0.4.0.tgz",
@ -4662,6 +4742,11 @@
"integrity": "sha512-WW/rQLOazUq+ST/bCAVBp/2oMERWLsR7OrKyt052dNDk4DHcDE0/7QSXITlmi+VBcV13DfIbysG3tZJm5RfdBA==", "integrity": "sha512-WW/rQLOazUq+ST/bCAVBp/2oMERWLsR7OrKyt052dNDk4DHcDE0/7QSXITlmi+VBcV13DfIbysG3tZJm5RfdBA==",
"dev": true "dev": true
}, },
"is-number": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng=="
},
"is-number-like": { "is-number-like": {
"version": "1.0.8", "version": "1.0.8",
"resolved": "https://registry.npmjs.org/is-number-like/-/is-number-like-1.0.8.tgz", "resolved": "https://registry.npmjs.org/is-number-like/-/is-number-like-1.0.8.tgz",
@ -5521,9 +5606,9 @@
"dev": true "dev": true
}, },
"node-abi": { "node-abi": {
"version": "2.21.0", "version": "2.26.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.21.0.tgz", "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.26.0.tgz",
"integrity": "sha512-smhrivuPqEM3H5LmnY3KU6HfYv0u4QklgAxfFyRNujKUzbUcYZ+Jc2EhukB9SRcD2VpqhxM7n/MIcp1Ua1/JMg==", "integrity": "sha512-ag/Vos/mXXpWLLAYWsAoQdgS+gW7IwvgMLOgqopm/DbzAjazLltzgzpVMsFlgmo9TzG5hGXeaBZx2AI731RIsQ==",
"requires": { "requires": {
"semver": "^5.4.1" "semver": "^5.4.1"
}, },
@ -5676,6 +5761,11 @@
} }
} }
}, },
"normalize-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA=="
},
"normalize-url": { "normalize-url": {
"version": "4.5.0", "version": "4.5.0",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz", "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz",
@ -6084,6 +6174,11 @@
"resolved": "https://registry.npmjs.org/phin/-/phin-2.9.3.tgz", "resolved": "https://registry.npmjs.org/phin/-/phin-2.9.3.tgz",
"integrity": "sha512-CzFr90qM24ju5f88quFC/6qohjC144rehe5n6DH900lgXmUe86+xCKc10ev56gRKC4/BkHUoG4uSiQgBiIXwDA==" "integrity": "sha512-CzFr90qM24ju5f88quFC/6qohjC144rehe5n6DH900lgXmUe86+xCKc10ev56gRKC4/BkHUoG4uSiQgBiIXwDA=="
}, },
"picomatch": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.3.tgz",
"integrity": "sha512-KpELjfwcCDUb9PeigTs2mBJzXUPzAuP2oPcA989He8Rte0+YUAjw1JVedDhuTKPkHjSYzMN3npC9luThGYEKdg=="
},
"pify": { "pify": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
@ -6426,6 +6521,14 @@
"util-deprecate": "~1.0.1" "util-deprecate": "~1.0.1"
} }
}, },
"readdirp": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.5.0.tgz",
"integrity": "sha512-cMhu7c/8rdhkHXWsY+osBhfSy0JikwpHK/5+imo+LpeasTF8ouErHrlYkwT0++njiyuDvc7OFY5T3ukvZ8qmFQ==",
"requires": {
"picomatch": "^2.2.1"
}
},
"rechoir": { "rechoir": {
"version": "0.7.0", "version": "0.7.0",
"resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.7.0.tgz", "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.7.0.tgz",
@ -7479,6 +7582,14 @@
"integrity": "sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==", "integrity": "sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==",
"dev": true "dev": true
}, },
"to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
"requires": {
"is-number": "^7.0.0"
}
},
"toidentifier": { "toidentifier": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",

View File

@ -28,6 +28,7 @@
"axios": "0.21.1", "axios": "0.21.1",
"better-sqlite3": "7.1.4", "better-sqlite3": "7.1.4",
"body-parser": "1.19.0", "body-parser": "1.19.0",
"chokidar": "^3.5.1",
"cls-hooked": "4.2.2", "cls-hooked": "4.2.2",
"commonmark": "0.29.3", "commonmark": "0.29.3",
"cookie-parser": "1.4.5", "cookie-parser": "1.4.5",
@ -56,7 +57,7 @@
"jsdom": "16.5.3", "jsdom": "16.5.3",
"mime-types": "2.1.30", "mime-types": "2.1.30",
"multer": "1.4.2", "multer": "1.4.2",
"node-abi": "2.21.0", "node-abi": "2.26.0",
"open": "8.0.6", "open": "8.0.6",
"portscanner": "2.2.0", "portscanner": "2.2.0",
"rand-token": "1.0.1", "rand-token": "1.0.1",
@ -79,7 +80,7 @@
}, },
"devDependencies": { "devDependencies": {
"cross-env": "7.0.3", "cross-env": "7.0.3",
"electron": "13.0.0-beta.16", "electron": "13.0.0-beta.17",
"electron-builder": "22.10.5", "electron-builder": "22.10.5",
"electron-packager": "15.2.0", "electron-packager": "15.2.0",
"electron-rebuild": "2.3.5", "electron-rebuild": "2.3.5",

View File

@ -1,6 +1,7 @@
import utils from "../../services/utils.js";
import openService from "../../services/open.js"; import openService from "../../services/open.js";
import TypeWidget from "./type_widget.js"; import TypeWidget from "./type_widget.js";
import fileWatcher from "../../services/file_watcher.js";
import server from "../../services/server.js";
const TPL = ` const TPL = `
<div class="note-detail-file note-detail-printable"> <div class="note-detail-file note-detail-printable">
@ -23,6 +24,12 @@ const TPL = `
} }
</style> </style>
<div class="file-watcher-wrapper alert alert-warning">
<p>File <code class="file-watcher-path"></code> has been last modified on <span class="file-watcher-last-modified"></span>.</p>
<button class="btn btn-sm file-watcher-upload-button">Upload modified file</button>
</div>
<pre class="file-preview-content"></pre> <pre class="file-preview-content"></pre>
<div class="file-preview-not-available alert alert-info"> <div class="file-preview-not-available alert alert-info">
@ -47,12 +54,25 @@ export default class FileTypeWidget extends TypeWidget {
this.$pdfPreview = this.$widget.find(".pdf-preview"); this.$pdfPreview = this.$widget.find(".pdf-preview");
this.$videoPreview = this.$widget.find(".video-preview"); this.$videoPreview = this.$widget.find(".video-preview");
this.$audioPreview = this.$widget.find(".audio-preview"); this.$audioPreview = this.$widget.find(".audio-preview");
this.$fileWatcherWrapper = this.$widget.find(".file-watcher-wrapper");
this.$fileWatcherWrapper.hide();
this.$fileWatcherPath = this.$widget.find(".file-watcher-path");
this.$fileWatcherLastModified = this.$widget.find(".file-watcher-last-modified");
this.$fileWatcherUploadButton = this.$widget.find(".file-watcher-upload-button");
this.$fileWatcherUploadButton.on("click", async () => {
await server.post(`notes/${this.noteId}/upload-modified-file`, {
filePath: this.$fileWatcherPath.text()
});
fileWatcher.fileModificationUploaded(this.noteId);
this.refreshFileWatchingStatus();
});
} }
async doRefresh(note) { async doRefresh(note) {
const attributes = note.getAttributes();
const attributeMap = utils.toObject(attributes, l => [l.name, l.value]);
this.$widget.show(); this.$widget.show();
const noteComplement = await this.tabContext.getNoteComplement(); const noteComplement = await this.tabContext.getNoteComplement();
@ -87,5 +107,22 @@ export default class FileTypeWidget extends TypeWidget {
else { else {
this.$previewNotAvailable.show(); this.$previewNotAvailable.show();
} }
this.refreshFileWatchingStatus();
}
refreshFileWatchingStatus() {
const status = fileWatcher.getFileModificationStatus(this.noteId);
this.$fileWatcherWrapper.toggle(!!status);
if (status) {
this.$fileWatcherPath.text(status.filePath);
this.$fileWatcherLastModified.text(dayjs.unix(status.lastModifiedMs / 1000).format("HH:mm:ss"));
}
}
openedFileUpdatedEvent(data) {
this.refreshFileWatchingStatus();
} }
} }

View File

@ -7,6 +7,8 @@ const noteRevisionService = require('../../services/note_revisions');
const tmp = require('tmp'); const tmp = require('tmp');
const fs = require('fs'); const fs = require('fs');
const { Readable } = require('stream'); const { Readable } = require('stream');
const chokidar = require('chokidar');
const ws = require('../../services/ws');
function updateFile(req) { function updateFile(req) {
const {noteId} = req.params; const {noteId} = req.params;
@ -120,6 +122,19 @@ function saveToTmpDir(req) {
fs.writeSync(tmpObj.fd, note.getContent()); fs.writeSync(tmpObj.fd, note.getContent());
fs.closeSync(tmpObj.fd); 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 { return {
tmpFilePath: tmpObj.name tmpFilePath: tmpObj.name
}; };

View File

@ -188,6 +188,8 @@ function formatDownloadTitle(filename, type, mime) {
filename = "untitled"; filename = "untitled";
} }
filename = sanitize(filename);
if (type === 'text') { if (type === 'text') {
return filename + '.html'; return filename + '.html';
} else if (['relation-map', 'search'].includes(type)) { } else if (['relation-map', 'search'].includes(type)) {