From 3fb86482404e11942cd83c3500a297a3991db0e4 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Wed, 13 Sep 2017 16:28:53 +0200 Subject: Restructure project --- routes/getSchedule.js | 55 --------------------------------------------------- routes/index.js | 31 ----------------------------- routes/manifest.js | 19 ------------------ routes/opensearch.js | 12 ----------- 4 files changed, 117 deletions(-) delete mode 100644 routes/getSchedule.js delete mode 100644 routes/index.js delete mode 100644 routes/manifest.js delete mode 100644 routes/opensearch.js (limited to 'routes') diff --git a/routes/getSchedule.js b/routes/getSchedule.js deleted file mode 100644 index f6c3cb6..0000000 --- a/routes/getSchedule.js +++ /dev/null @@ -1,55 +0,0 @@ -const express = require('express') -const router = express.Router() -const request = require('request') -const iconv = require('iconv-lite') - -const getUserIndex = require('../lib/getUserIndex') -const getURLOfUser = require('../lib/getURLOfUser') - -// copied from http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/untisscripts.js, -// were using the same code as they do to be sure that we always get the same -// week number. -function getWeekNumber (target) { - const dayNr = (target.getDay() + 6) % 7 - target.setDate(target.getDate() - dayNr + 3) - const firstThursday = target.valueOf() - target.setMonth(0, 1) - if (target.getDay() !== 4) { - target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7) - } - - return 1 + Math.ceil((firstThursday - target) / 604800000) -} - -router.get('/:type/:value', function (req, res, next) { - getUserIndex().then(users => { - const { type, value } = req.params - let { week } = req.query - const user = - users.filter(user => user.type === type && user.value === value)[0] - - if (!user) { - next(new Error(`${type}${value} is not in the user index.`)) - } - - if (!week) { - week = getWeekNumber(new Date()) - } - - const { index } = user - - const url = getURLOfUser(type, index, week) - - request(url, { encoding: null }, function (err, data) { - if (err) { - next(err) - return - } - - const utf8Body = iconv.decode(data.body, 'ISO-8859-1') - res.status(data.statusCode).end(utf8Body) - }) - }) -}) - -module.exports = router diff --git a/routes/index.js b/routes/index.js deleted file mode 100644 index d2267ba..0000000 --- a/routes/index.js +++ /dev/null @@ -1,31 +0,0 @@ -'use strict' - -const express = require('express') -const router = express.Router() -const getMeetingpointData = require('../lib/getMeetingpointData') - -/* GET home page. */ -router.get(['/', '/s/*', '/t/*', '/r/*', '/c/*'], function (req, res, next) { - getMeetingpointData().then(data => { - const isBeta = process.env.BETA === '1' - - let flags = [] - if (isBeta) { - flags.push('BETA') - flags.push('NO_FEATURE_DETECT') - } else if (req.query.nfd != null) { - flags.push('NO_FEATURE_DETECT') - } - - const flagsStr = `var FLAGS = ${JSON.stringify(flags)};` - const usersStr = `var USERS = ${JSON.stringify(data.users)};` - const validWeekNumbersStr = `var VALID_WEEK_NUMBERS = ${JSON.stringify(data.validWeekNumbers)}` - - res.render('index', { flagsStr, usersStr, validWeekNumbersStr }) - }).catch(function () { - console.error('Unable to get user info, emergency redirect!') - res.render('redirect') - }) -}) - -module.exports = router diff --git a/routes/manifest.js b/routes/manifest.js deleted file mode 100644 index b2ce55f..0000000 --- a/routes/manifest.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict' - -const express = require('express') -const router = express.Router() -const path = require('path') - -router.get('/', function (req, res, next) { - console.log('got a request') - - const isBeta = process.env.BETA === '1' - - if (isBeta) { - res.sendFile('manifest.beta.webmanifest', { root: path.join(__dirname, '../public') }) - } else { - res.sendFile('manifest.webmanifest', { root: path.join(__dirname, '../public') }) - } -}) - -module.exports = router diff --git a/routes/opensearch.js b/routes/opensearch.js deleted file mode 100644 index c3e2e57..0000000 --- a/routes/opensearch.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict' - -const express = require('express') -const router = express.Router() -const path = require('path') - -router.get('/', function (req, res, next) { - res.setHeader('content-type', 'application/opensearchdescription+xml') - res.sendFile('opensearch.xml', { root: path.join(__dirname, '../public') }) -}) - -module.exports = router -- cgit v1.1