-
Notifications
You must be signed in to change notification settings - Fork 1
/
routes-rss.js
33 lines (28 loc) · 890 Bytes
/
routes-rss.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Created by massimilianocannarozzo on 25/11/18.
*/
/* eslint-env node */
const RaiApi = require('./raiapi');
const api = new RaiApi();
const router = require('express').Router();
const moment = require('moment-timezone').tz.setDefault('Europe/Rome');
let canali = {};
RaiApi.listCanali().then(data => canali = data);
//RSS
router.get(/^\/canali\/(\d+)\.xml/, (req, res, next) => {
const { params: { 0: canale }, hostname, url, query: { data } } = req;
const m = moment(data);
api.getAll(canale, data)
.then(programmi => res.set({
'Content-Type': 'text/xml',
}).render('rss.ejs', {
programmi,
hostname,
url,
canale: canali[canale].name,
dateTag: m.format('YYYY.MM.DD'),
today: m.toDate(),
}))
.catch(error => next(error))
});
module.exports = router;