X-Git-Url: https://git.r.bdr.sh/rbdr/dead-drop/blobdiff_plain/5e981bca19ace2a7704f267175b6aa368e63bda0..7404eac982a0d928866aeddaa1a0ea4d1f2d3870:/lib/dead_drop.js?ds=inline diff --git a/lib/dead_drop.js b/lib/dead_drop.js index 1ea86e8..6f97645 100644 --- a/lib/dead_drop.js +++ b/lib/dead_drop.js @@ -1,8 +1,13 @@ 'use strict'; const Koa = require('koa'); +const KoaBodyParser = require('koa-bodyparser'); const KoaRoute = require('koa-route'); +const MainMenuController = require('./controllers/main_menu'); +const RecordingMenuController = require('./controllers/recording_menu'); +const RecordingsController = require('./controllers/recordings'); + const internals = {}; /** @@ -42,60 +47,57 @@ module.exports = internals.DeadDrop = class DeadDrop { this._app = Koa(); - this._app.use(KoaRoute.get('/menus/main', function * () { - - this.body = 'I will return the main menu.'; - })); - - this._app.use(KoaRoute.post('/menus/main', function * () { + this._app.use(KoaBodyParser()); - this.body = 'I will parse the main menu.'; - })); + this._initializeMainMenuRoutes(); + this._initializeRecordingMenuRoutes(); + this._initializeRecordingsRoutes(); - this._app.use(KoaRoute.get('/menus/recording', function * () { + this._app.use(function * () { - this.body = 'I will return the select recording menu.'; - })); + this.body = 'How did you get here? Shoo!'; + }); - this._app.use(KoaRoute.post('/menus/recording', function * () { + } - this.body = 'I will parse the select recording menu.'; - })); + // Starts listening - this._app.use(KoaRoute.get('/recordings', function * () { + _startServer() { - this.body = 'I will initiate recording process'; - })); + this._app.listen(this.port); + } - this._app.use(KoaRoute.post('/recordings', function * () { + // Initializes the main menu routes. - this.body = 'I will create a new recording'; - })); + _initializeMainMenuRoutes() { - this._app.use(KoaRoute.get('/recordings/:id', function * (id) { + const mainMenuController = new MainMenuController(); - id = parseInt(id); + this._app.use(KoaRoute.get('/menus/main', mainMenuController.serveMenu())); + this._app.use(KoaRoute.post('/menus/main', mainMenuController.parseMenuSelection())); + } - if (id === 0) { - this.body = 'I will return a random recording'; - } - else { - this.body = 'I will return a specific recording'; - } - })); + // Initializes the recording menu routes. - this._app.use(function * () { + _initializeRecordingMenuRoutes() { - this.body = 'hello, world'; - }); + const recordingMenuController = new RecordingMenuController(); + this._app.use(KoaRoute.get('/menus/recording', recordingMenuController.serveMenu())); + this._app.use(KoaRoute.post('/menus/recording', recordingMenuController.parseMenuSelection())); } - // Starts listening + // Initializes the recordings routes. - _startServer() { + _initializeRecordingsRoutes() { - this._app.listen(this.port); + const recordingsController = new RecordingsController({ + redis: this.redis + }); + + this._app.use(KoaRoute.get('/recordings', recordingsController.startRecording())); + this._app.use(KoaRoute.post('/recordings', recordingsController.saveRecording())); + this._app.use(KoaRoute.get('/recordings/:id', recordingsController.getRecording())); } // Prints the banner.