Last active
January 24, 2018 14:03
-
-
Save hi1280/e6d5e396388a8b647e23017c090f7d3f to your computer and use it in GitHub Desktop.
Web画面経由でコマンドを操作する
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
"use strict"; | |
Object.defineProperty(exports, "__esModule", { value: true }); | |
const express = require("express"); | |
const ejs = require("ejs"); | |
const favicon = require("serve-favicon"); | |
const path = require("path"); | |
const routes_1 = require("./routes"); | |
const root = __dirname + '/'; | |
const app = express(); | |
app.use(favicon(path.join(__dirname, 'favicon.ico'))); | |
app.use(express.static(root)); | |
app.use('/', routes_1.default); | |
app.get('*', function (req, res) { | |
ejs.renderFile('./views/index.ejs', (err, str) => { | |
if (err) { | |
res.send(err.message); | |
} | |
res.send(str); | |
}); | |
}); | |
const port = process.env.PORT || '3000'; | |
app.listen(port, () => console.log(`running on localhost:${port}`)); |
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
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<link rel="apple-touch-icon" href="./remocon.png" /> | |
<title>Remocon</title> | |
</head> | |
<body> | |
<div><a href="./tv-on">TVの電源ボタン</a></div> | |
<div><a href="./tv-input-change">TVの入力切り替え</a></div> | |
<div><a href="./tv-channel-down">TVの前チャンネル</a></div> | |
<div><a href="./tv-channel-up">TVの次チャンネル</a></div> | |
<div><a href="./tv-volume-down">TVの音量下げる</a></div> | |
<div><a href="./tv-volume-up">TVの音量上げる</a></div> | |
<div><a href="./tv-up">TVの上ボタン</a></div> | |
<div><a href="./tv-down">TVの下ボタン</a></div> | |
<div><a href="./tv-left">TVの左ボタン</a></div> | |
<div><a href="./tv-right">TVの右ボタン</a></div> | |
<div><a href="./tv-enter">TVの決定ボタン</a></div> | |
<div><a href="./tv-back">TVの戻るボタン</a></div> | |
<div><a href="./tv-degital">TVの地デジボタン</a></div> | |
<div><a href="./tv-bs">TVのBSボタン</a></div> | |
<div><a href="./light-on">照明をつける</a></div> | |
<div><a href="./light-off">照明を消す</a></div> | |
<div><a href="./light-up">照明を明るくする</a></div> | |
<div><a href="./light-down">照明を暗くする</a></div> | |
<div><a href="./video-on">ビデオの電源ボタン</a></div> | |
<div><a href="./video-channel-down">ビデオの前チャンネル</a></div> | |
<div><a href="./video-channel-up">ビデオの次チャンネル</a></div> | |
<div><a href="./video-input-change">ビデオの入力切り替え</a></div> | |
</body> | |
</html> |
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
"use strict"; | |
Object.defineProperty(exports, "__esModule", { value: true }); | |
const express = require("express"); | |
const ejs = require("ejs"); | |
const child_process_1 = require("child_process"); | |
const router_configs = [ | |
{ | |
path: '/tv-on', | |
cmd: 'sudo irsend SEND_ONCE TV KEY_PLAY' | |
}, | |
{ | |
path: '/tv-input-change', | |
cmd: 'sudo irsend SEND_ONCE TV KEY_SELECT' | |
}, | |
{ | |
path: '/tv-channel-down', | |
cmd: 'sudo irsend SEND_ONCE TV KEY_CHANNELDOWN' | |
}, | |
{ | |
path: '/tv-channel-up', | |
cmd: 'sudo irsend SEND_ONCE TV KEY_CHANNELUP' | |
}, | |
{ | |
path: '/tv-volume-down', | |
cmd: 'sudo irsend SEND_ONCE TV KEY_VOLUMEDOWN' | |
}, | |
{ | |
path: '/tv-volume-up', | |
cmd: 'sudo irsend SEND_ONCE TV KEY_VOLUMEUP' | |
}, | |
{ | |
path: '/tv-up', | |
cmd: 'sudo irsend SEND_ONCE TV KEY_UP' | |
}, | |
{ | |
path: '/tv-down', | |
cmd: 'sudo irsend SEND_ONCE TV KEY_DOWN' | |
}, | |
{ | |
path: '/tv-left', | |
cmd: 'sudo irsend SEND_ONCE TV KEY_LEFT' | |
}, | |
{ | |
path: '/tv-right', | |
cmd: 'sudo irsend SEND_ONCE TV KEY_RIGHT' | |
}, | |
{ | |
path: '/tv-enter', | |
cmd: 'sudo irsend SEND_ONCE TV KEY_ENTER' | |
}, | |
{ | |
path: '/tv-back', | |
cmd: 'sudo irsend SEND_ONCE TV KEY_BACK' | |
}, | |
{ | |
path: '/tv-degital', | |
cmd: 'sudo irsend SEND_ONCE TV KEY_D' | |
}, | |
{ | |
path: '/tv-bs', | |
cmd: 'sudo irsend SEND_ONCE TV KEY_B' | |
}, | |
{ | |
path: '/light-on', | |
cmd: 'sudo irsend SEND_ONCE LIGHT KEY_PLAY' | |
}, | |
{ | |
path: '/light-off', | |
cmd: 'sudo irsend SEND_ONCE LIGHT KEY_STOP' | |
}, | |
{ | |
path: '/light-up', | |
cmd: 'sudo irsend SEND_ONCE LIGHT KEY_UP' | |
}, | |
{ | |
path: '/light-down', | |
cmd: 'sudo irsend SEND_ONCE LIGHT KEY_DOWN' | |
}, | |
{ | |
path: '/video-on', | |
cmd: 'sudo irsend SEND_ONCE VIDEO KEY_PLAY' | |
}, | |
{ | |
path: '/video-channel-down', | |
cmd: 'sudo irsend SEND_ONCE VIDEO KEY_CHANNELDOWN' | |
}, | |
{ | |
path: '/video-channel-up', | |
cmd: 'sudo irsend SEND_ONCE VIDEO KEY_CHANNELUP' | |
}, | |
{ | |
path: '/video-input-change', | |
cmd: 'sudo irsend SEND_ONCE VIDEO KEY_SELECT' | |
} | |
]; | |
const routes = express.Router(); | |
router_configs.forEach((config) => { | |
routes.get(config.path, (req, res) => { | |
child_process_1.exec(config.cmd, (err, stdout, stderr) => { | |
if (err) { | |
res.send(err.message); | |
} | |
ejs.renderFile('./views/index.ejs', (err, str) => { | |
if (err) { | |
res.send(err.message); | |
} | |
res.send(str); | |
}); | |
}); | |
}); | |
}); | |
exports.default = routes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment