Skip to content

Commit

Permalink
local edit support
Browse files Browse the repository at this point in the history
  • Loading branch information
cnshsliu committed Jun 13, 2024
1 parent 4d4517e commit a858227
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lua/server/smp.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";
const { spawn } = require("child_process");
const marked = require("marked");
const childProcess = require("child_process");
const katex = require("katex");
Expand Down Expand Up @@ -1815,7 +1816,6 @@ const init = async () => {
.replace(smpConfig.home, "")
.replace(/^\//, "")
.replace(/.md$/, ""),
path: filepath.replace(smpConfig.home, "").replace(/^\//, ""),
});
}
}
Expand All @@ -1837,14 +1837,33 @@ const init = async () => {
handler: async (request, h) => {
const PLD = request.payload;
const content = await readFile(
path.join(smpConfig.home, PLD.filePath),
path.join(smpConfig.home, PLD.title + ".md"),
"utf8"
);
const ret = { path: PLD.filePath, content: content };
return h.response(ret).header("Access-Control-Allow-Origin", "*");
},
});

server.route({
method: "POST",
path: "/mind/localedit",
handler: async (request, h) => {
const PLD = request.payload;
const nvimPath = "/opt/homebrew/bin/neovide";
const filePath = path.join(smpConfig.home, PLD.title + ".md");

const nvim = spawn(nvimPath, [filePath], {
detached: true,
stdio: "ignore",
});

nvim.unref();

return h.response("okay").header("Access-Control-Allow-Origin", "*");
},
});

await server.start();
logToFile("Server running on " + server.info.uri);
console.log("Server running on " + server.info.uri);
Expand Down

0 comments on commit a858227

Please sign in to comment.