Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_loadCalendar() {
// TODO: Make use of HTTP cache control stuff
this.log(`Updating calendar ${this.name}`);
ical.fromURL(this._url, {}, (err, cal) => {
if (err) {
this.log(`Failed to load iCal calender: ${this.url} with error ${err}`);
this.emit('error', err);
}
if (cal) {
this.emit('data', cal);
}
this._scheduleNextIteration();
});
}
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));
if (message[1] === ' ') {
message = message.replace(' ', '')
}
message = message.split(' ')
const cmd = message[0]
let localHashtag = ''
if (message.length > 1) {
localHashtag = message[1].toLowerCase()
}
const user = event.getSender()
const roomId = room.roomId
if (cmd === '!calendar' || cmd === '!cal') {
if (localHashtag.length == 0 && hashtagMappings.hasOwnProperty(roomId)) {
localHashtag = hashtagMappings[roomId]
}
ical.fromURL(calendarURL, {}, function(err, data) {
if (!err) {
const today = new Date()
const upperLimit = new Date()
upperLimit.setDate(today.getDate() + calendarUpperLimitInMonths * 30)
const globalFormattingOptions = {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
}
globals = []
locals = []
for (var key in data) {
if (data.hasOwnProperty(key) && data[key].start && data[key].end) {
if (data[key].rrule && data[key].start.tz) {
var nextOccurrences = data[key].rrule.between(
for (let calendarObject of calendarEntry.calendar.objects) {
if (calendarObject.data && calendarObject.data.href) {
let ics = url.origin + calendarObject.data.href;
let header = {};
let username = node.config.username;
let password = node.config.password;
if (username && password) {
var auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
header = {
headers: {
'Authorization': auth
}
}
}
return ical.fromURL(ics, header).then(data => {
for (var k in data) {
var ev = data[k];
ev.calendarName = calendar.displayName;
retEntries[ev.uid] = ev;
}
return retEntries;
});
}
}
}
}
})
);
for (var _a = 0, _b = calendarEntry.calendar.objects; _a < _b.length; _a++) {
var calendarObject = _b[_a];
if (calendarObject.data && calendarObject.data.href) {
var ics = url.origin + calendarObject.data.href;
var header = {};
var username = node.config.username;
var password = node.config.password;
if (username && password) {
var auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
header = {
headers: {
'Authorization': auth
}
};
}
return ical.fromURL(ics, header).then(function (data) {
for (var k in data) {
var ev = data[k];
ev.calendarName = calendar.displayName;
retEntries[ev.uid] = ev;
}
return retEntries;
});
}
}
}
}
}));
}
});
}
else {
if (urlOrFile.match(/^https?:\/\//)) {
var header = {};
var username = node.config.username;
var password = node.config.password;
if (username && password) {
var auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
header = {
headers: {
'Authorization': auth
}
};
}
ical.fromURL(node.config.url, header, function (err, data) {
if (err) {
callback && callback(err, null);
return;
}
callback && callback(null, data);
});
}
else {
ical.parseFile(node.config.url, function (err, data) {
if (err) {
callback && callback(err, null);
return;
}
callback && callback(null, data);
});
}
} else {
if (urlOrFile.match(/^https?:\/\//)) {
let header = {};
let username = node.config.username;
let password = node.config.password;
if (username && password) {
var auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
header = {
headers: {
'Authorization': auth
}
}
}
ical.fromURL(node.config.url, header, (err, data) => {
if (err) {
callback && callback(err, null);
return;
}
callback && callback(null, data);
});
} else {
ical.parseFile(node.config.url, (err, data) => {
if (err) {
callback && callback(err, null);
return;
}
callback && callback(null, data);
});
}
}
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;
}
header = {
headers: {
'Authorization': auth
}
}
}
ical.fromURL(node.config.url, header, (err, data) => {
if (err) {
callback && callback(err, null);
return;
}
callback && callback(null, data);
});
} else {
ical.parseFile(node.config.url, (err, data) => {
if (err) {
callback && callback(err, null);
return;
}
callback && callback(null, data);
});
}
}
}