Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = async function(ctx) {
ctx.request.body = await raw(ctx.req, {
encoding: true,
limit: '1mb' // practical
});
if (ctx.request.type.includes('xml')) {
ctx.request.xml = new DOMParser().parseFromString(ctx.request.body);
} else if (ctx.request.type === 'text/calendar') {
ctx.request.ical = ical.parseICS(ctx.request.body);
}
};
getICal(urlOrFile, user, pass, sslignore, calName, (err, _data) => {
if (err || !_data) {
adapter.log.warn('Error reading "' + urlOrFile + '": ' + err);
cb(calName);
return;
}
adapter.log.debug('File read successfully ' + urlOrFile);
let data;
try {
data = ical.parseICS(_data, (err, data) => {
if (data) {
adapter.log.info('processing URL: ' + calName + ' ' + urlOrFile);
adapter.log.debug(JSON.stringify(data));
const realnow = new Date();
const today = new Date();
today.setHours(0, 0, 0, 0);
const endpreview = new Date();
endpreview.setDate(endpreview.getDate() + parseInt(adapter.config.daysPreview, 10));
const now2 = new Date();
// clear time
now2.setHours(0, 0, 0, 0);
setImmediate(() =>
processData(data, realnow, today, endpreview, now2, calName, filter, cb));
export function shouldBlockPipeline(icalData: string | Buffer, now = new Date(), advanceMarginSec = 3600): CalendarEvent | undefined {
const events: Events = ical.parseICS(icalData.toString('utf8'));
const blocks = containingEventsWithMargin(events, now, advanceMarginSec);
return blocks.length > 0 ? blocks[0] : undefined;
}