This commit is contained in:
parent
2c2e8610c3
commit
978ac90f53
|
@ -13,8 +13,6 @@ export const raPlaMiddlewareRouter = express.Router();
|
||||||
|
|
||||||
raPlaMiddlewareRouter.get('/', async (req: Request, res: Response) => {
|
raPlaMiddlewareRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
logger.info('Starting transaction');
|
|
||||||
|
|
||||||
let user = (req.query.user ?? '').toString();
|
let user = (req.query.user ?? '').toString();
|
||||||
let file = (req.query.file ?? '').toString();
|
let file = (req.query.file ?? '').toString();
|
||||||
let blockers = (req.query.blockers ?? '').toString() === '1';
|
let blockers = (req.query.blockers ?? '').toString() === '1';
|
||||||
|
@ -35,8 +33,6 @@ raPlaMiddlewareRouter.get('/', async (req: Request, res: Response) => {
|
||||||
|
|
||||||
res.set({'Content-Disposition': 'attachment; filename=' + file + '.ics'});
|
res.set({'Content-Disposition': 'attachment; filename=' + file + '.ics'});
|
||||||
res.status(200).send(resultingFile);
|
res.status(200).send(resultingFile);
|
||||||
|
|
||||||
logger.info('Stopping transaction');
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
|
|
|
@ -68,10 +68,8 @@ export const parseIcal = function (icalContents: string): iCalFile {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getDuration = function (event: string): number {
|
export const getDuration = function (event: string): number {
|
||||||
let startRegex: RegExp = /DTSTART.*?(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z?\r/gm; // Fix this, doesnt match \n but matching Z doesnt work all the time
|
let startRegex: RegExp = /DTSTART.*?(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z?\r/gm;
|
||||||
let endRegex: RegExp = /DTEND.*?(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z?\r/gm; // s.o.
|
let endRegex: RegExp = /DTEND.*?(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z?\r/gm;
|
||||||
|
|
||||||
// localhost:3000/rapla-middleware?user=eisenbiegler&file=TINF19B4&blockers=0&wahl=4&pflicht=2
|
|
||||||
|
|
||||||
let startMatch = startRegex.exec(event);
|
let startMatch = startRegex.exec(event);
|
||||||
|
|
||||||
|
@ -105,7 +103,14 @@ export const getDuration = function (event: string): number {
|
||||||
let startDt = new Date(startDtYear, startDtMonth - 1, startDtDay, startDtHour, startDtMinute);
|
let startDt = new Date(startDtYear, startDtMonth - 1, startDtDay, startDtHour, startDtMinute);
|
||||||
let endDt = new Date(endDtYear, endDtMonth - 1, endDtDay, endDtHour, endDtMinute);
|
let endDt = new Date(endDtYear, endDtMonth - 1, endDtDay, endDtHour, endDtMinute);
|
||||||
|
|
||||||
return endDt.getHours() - startDt.getHours();
|
let hourDifference = endDt.getHours() - startDt.getHours();
|
||||||
|
let minuteDifference = 0;
|
||||||
|
|
||||||
|
if (hourDifference === 0) {
|
||||||
|
minuteDifference = endDt.getMinutes() - startDt.getMinutes();
|
||||||
|
}
|
||||||
|
|
||||||
|
return hourDifference + (minuteDifference / 60);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const serializeIcal = function (ical: iCalFile): string {
|
export const serializeIcal = function (ical: iCalFile): string {
|
||||||
|
@ -126,6 +131,7 @@ export const removeBlockers = function (ical: iCalFile): iCalFile {
|
||||||
!event.content.includes('SUMMARY:Beginn Theorie')
|
!event.content.includes('SUMMARY:Beginn Theorie')
|
||||||
&& !event.content.includes('SUMMARY:Präsenz')
|
&& !event.content.includes('SUMMARY:Präsenz')
|
||||||
&& event.duration < 10
|
&& event.duration < 10
|
||||||
|
&& event.duration > 0.25
|
||||||
) {
|
) {
|
||||||
remainingEvents.push(event);
|
remainingEvents.push(event);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user