From c67a11950a08e2ab83ebdb3286de2d9172978a63 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Tue, 11 Jul 2023 14:48:03 +0200 Subject: [PATCH] added: simple node cli client tool --- .gitignore | 4 +++ tools/nodeclient/app.js | 63 ++++++++++++++++++++++++++++++++++ tools/nodeclient/settings.json | 5 +++ 3 files changed, 72 insertions(+) create mode 100644 .gitignore create mode 100644 tools/nodeclient/app.js create mode 100644 tools/nodeclient/settings.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..44c500a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +tools/nodeclient/node_modules/* +tools/nodeclient/note.md +tools/nodeclient/package-lock.json +tools/nodeclient/package.json diff --git a/tools/nodeclient/app.js b/tools/nodeclient/app.js new file mode 100644 index 0000000..aa8bccb --- /dev/null +++ b/tools/nodeclient/app.js @@ -0,0 +1,63 @@ +const axios = require("axios"); +const readline = require("readline"); +const fs = require("fs"); +var cp = require("child_process"); + +var rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + +var settings = JSON.parse(fs.readFileSync("settings.json", { encoding: "utf8", flag: "r" })); + +axios.post(`${settings.url}/handler.php`, +{ + action: "fetch", + password: settings.password +}, +{ + headers: + { + "Content-type": "application/x-www-form-urlencoded" + } +}) +.then(res => +{ + var notes = res.data; + notes.every( (note, i) => + { + console.log(`[${i}] ${note.title}`) + return i < settings.maxcount; + }); + + rl.prompt(); + rl.on("line", (line) => + { + var note = notes[line] + + fs.writeFileSync("note.md", note.content); + + cp.exec("sublime_text.exe -w note.md", function (err, stdout, stderr) + { + var newcontent = fs.readFileSync("note.md", { encoding: "utf8", flag: "r" }); + + if (note.content != newcontent) + { + note.content = newcontent; + axios.post(`${settings.url}/handler.php`, + { + action: "push", + password: settings.password, + data: JSON.stringify(notes) + }, + { + headers: + { + "Content-type": "application/x-www-form-urlencoded" + } + }); + } + }) + rl.close(); + }); +}); diff --git a/tools/nodeclient/settings.json b/tools/nodeclient/settings.json new file mode 100644 index 0000000..f2f3f5c --- /dev/null +++ b/tools/nodeclient/settings.json @@ -0,0 +1,5 @@ +{ + "password": "", + "url": "http://localhost:8000", + "maxcount": 50 +}