mirror of
https://github.com/khairul169/home-lab.git
synced 2026-10-02 17:13:57 +07:00
feat: add terminal & wake pc
This commit is contained in:
@@ -2,13 +2,15 @@ import { Hono } from "hono";
|
||||
import auth from "./auth";
|
||||
import system from "./system";
|
||||
import _process from "./process";
|
||||
import apps from "./apps";
|
||||
import { authMiddleware } from "../lib/jwt";
|
||||
|
||||
const routes = new Hono()
|
||||
.route("/auth", auth)
|
||||
.use(authMiddleware)
|
||||
.route("/system", system)
|
||||
.route("/process", _process);
|
||||
.route("/process", _process)
|
||||
.route("/apps", apps);
|
||||
|
||||
export type AppType = typeof routes;
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Hono } from "hono";
|
||||
import wol from "wol";
|
||||
import { HTTPException } from "hono/http-exception";
|
||||
|
||||
const route = new Hono().post("/wakepc", async (c) => {
|
||||
const { PC_MAC_ADDR } = process.env;
|
||||
|
||||
try {
|
||||
await new Promise((resolve, reject) => {
|
||||
wol.wake(PC_MAC_ADDR || "", (err: any, res: any) =>
|
||||
err ? reject(err) : resolve(res)
|
||||
);
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw new HTTPException(400, { message: "Cannot wake pc up!" });
|
||||
}
|
||||
|
||||
return c.json({ message: "waking up..." });
|
||||
});
|
||||
|
||||
export default route;
|
||||
Reference in New Issue
Block a user