-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (31 loc) · 1023 Bytes
/
index.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
34
35
36
import path from 'path';
import express from 'express';
import * as api from './api.js';
import { filterCalendar } from './filters.js';
const app = express();
app.use('/', express.static(path.join(process.cwd(), '/static')));
const names = {
'lecture': 'Lectures',
'tutorial': 'Tutorials',
'lab': 'Labs',
'exam': 'Exams',
'important-date': 'Important Dates',
'quiz': 'Quizzes',
'tip': 'Tips',
'other': 'Other'
}
app.get('/filter/:category', async (req, res) => {
let category = req.params.category;
let url = req.query.url;
const text = await api.fetchCalendar(url);
const comp = api.parseCalendar(text);
const filtered = filterCalendar(comp, category);
if (category !== 'all') {
filtered.updatePropertyWithValue('x-wr-calname', `${names[category]} - ${filtered.getFirstPropertyValue('x-wr-calname')}`);
}
const ics = api.generateIcs(filtered);
res.setHeader('Content-Type', 'text/calendar');
//res.setHeader('Content-Type', 'text/plain');
res.send(ics);
});
app.listen(process.env.PORT || 3000);