From 7d551915bf4832a4cfa78473d79c04d95d246eb0 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Tue, 11 Jul 2023 18:09:04 +0200 Subject: [PATCH] changed in node tool added: filter on notes title added: put modified note on top --- tools/nodeclient/app.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/nodeclient/app.js b/tools/nodeclient/app.js index aa8bccb..e301632 100644 --- a/tools/nodeclient/app.js +++ b/tools/nodeclient/app.js @@ -9,6 +9,7 @@ var rl = readline.createInterface({ }); var settings = JSON.parse(fs.readFileSync("settings.json", { encoding: "utf8", flag: "r" })); +var filter = process.argv.length > 2 ? process.argv[2] : ""; axios.post(`${settings.url}/handler.php`, { @@ -24,7 +25,10 @@ axios.post(`${settings.url}/handler.php`, .then(res => { var notes = res.data; - notes.every( (note, i) => + + notes + .filter(n => n.title.includes(filter)) + .every( (note, i) => { console.log(`[${i}] ${note.title}`) return i < settings.maxcount; @@ -33,7 +37,7 @@ axios.post(`${settings.url}/handler.php`, rl.prompt(); rl.on("line", (line) => { - var note = notes[line] + var note = notes.filter(n => n.title.includes(filter))[line]; fs.writeFileSync("note.md", note.content); @@ -44,6 +48,10 @@ axios.post(`${settings.url}/handler.php`, if (note.content != newcontent) { note.content = newcontent; + + notes.splice(notes.indexOf(note), 1); + notes.unshift(note); + axios.post(`${settings.url}/handler.php`, { action: "push",