-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
144 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { execSync } from "child_process"; | ||
import si, { Systeminformation } from "systeminformation"; | ||
|
||
const rebootMachine = async () => { | ||
const { osInfo }: { osInfo: Systeminformation.OsData } = await si.get({ | ||
osInfo: "platform", | ||
}); | ||
|
||
if (osInfo.platform === "linux") { | ||
try { | ||
execSync("sudo shutdown -r now"); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
else if (osInfo.platform === "Windows") { | ||
try { | ||
execSync("shutdown /r"); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
else if (osInfo.platform === "darwin") { | ||
try { | ||
execSync("sudo shutdown -r now"); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
export default rebootMachine; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { execSync } from "child_process"; | ||
import si, { Systeminformation } from "systeminformation"; | ||
|
||
const shutdownMachine = async () => { | ||
const { osInfo }: { osInfo: Systeminformation.OsData } = await si.get({ | ||
osInfo: "platform", | ||
}); | ||
|
||
if (osInfo.platform === "linux") { | ||
try { | ||
execSync("sudo shutdown -h now"); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
else if (osInfo.platform === "Windows") { | ||
try { | ||
execSync("shutdown /s"); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
else if (osInfo.platform === "darwin") { | ||
try { | ||
execSync("sudo shutdown -h now"); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
export default shutdownMachine; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Request, Response } from "express"; | ||
import { readAppVersion } from "../../utils/readAppVersion"; | ||
|
||
const ApiVersionRute = async (req: Request, res: Response) => { | ||
const appVersion = await readAppVersion(); | ||
res.send(`v${appVersion}`); | ||
} | ||
|
||
export default ApiVersionRute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Request, Response } from "express"; | ||
import rebootMachine from "../../controllers/reboot.controller.ts"; | ||
|
||
const RebootRoute = async (req: Request, res: Response) => { | ||
const result = await rebootMachine(); | ||
if (result === true) { | ||
res.send('Success'); | ||
} | ||
else { | ||
res.send('Error'); | ||
} | ||
} | ||
|
||
export default RebootRoute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Request, Response } from "express"; | ||
import shutdownMachine from "../../controllers/shutdown.controller"; | ||
|
||
const ShutdownRoute = async (req: Request, res: Response) => { | ||
const result = await shutdownMachine(); | ||
if (result === true) { | ||
res.send('Success'); | ||
} | ||
else { | ||
res.send('Error'); | ||
} | ||
} | ||
|
||
export default ShutdownRoute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import fs from "fs/promises"; | ||
|
||
export const readAppVersion = async () => { | ||
try { | ||
const file = await fs.readFile("./package.json", "utf-8"); | ||
return JSON.parse(file).version; | ||
} catch (error) { | ||
return false; | ||
} | ||
}; |