Compare commits

..

No commits in common. "1552cc20137a868cb6a09e9564f84dcbc4f44f4d" and "661e614310051e9b1a92191bd836c4856aa2713b" have entirely different histories.

4 changed files with 20 additions and 45 deletions

View File

@ -1,10 +1,10 @@
[
{
"url": "https://calendar.google.com/calendar/ical/b4c66eb4bb2cc15257d071bab3f935385778b042112ea1aaedada47f3f1a6e3a%40group.calendar.google.com/public/basic.ics",
"prefix": "work"
"url": "https://example.com/calendar1.ics",
"prefix": "Calendar 1"
},
{
"url": "https://calendar.google.com/calendar/ical/774518759e4e2dd42aab0c511b02397bb216f3b67dc425d76bae07d1eff529d6%40group.calendar.google.com/public/basic.ics",
"url": "https://example.com/calendar2.ics",
"prefix": "Calendar 2"
}
]

View File

@ -32,8 +32,6 @@
<div id="calendars">
<div class="calendar">
<input type="text" id="prefix-0" placeholder="Prefix">
<input type="checkbox" id="override-0">
<label for="override-0">Override</label>
<input type="url" id="url-0" placeholder="Calendar URL">
</div>
</div>
@ -45,3 +43,4 @@
<script src="script.js"></script>
</body>
</html>

View File

@ -10,8 +10,6 @@ const form = document.getElementById('merge-form');
newCalendar.className = 'calendar';
newCalendar.innerHTML = `
<input type="text" id="prefix-${calendarIndex}" placeholder="Prefix">
<input type="checkbox" id="override-${calendarIndex}">
<label for="override-${calendarIndex}">Override</label>
<input type="url" id="url-${calendarIndex}" placeholder="Calendar URL">
`;
calendars.appendChild(newCalendar);
@ -23,9 +21,8 @@ const form = document.getElementById('merge-form');
const calendarsData = [];
for (let i = 0; i < calendarIndex; i++) {
const prefix = document.getElementById(`prefix-${i}`).value;
const override = document.getElementById(`override-${i}`).checked;
const url = document.getElementById(`url-${i}`).value;
calendarsData.push({ prefix, override, url });
calendarsData.push({ prefix, url });
}
fetch('/merge', {
method: 'POST',

View File

@ -28,7 +28,6 @@ app.post('/merge', async (req, res) => {
return {
data: response.data,
prefix: calendar.prefix,
override: calendar.override,
};
})
.catch((error) => {
@ -47,19 +46,11 @@ app.post('/merge', async (req, res) => {
const calendar = ical.parseICS(result.data);
Object.keys(calendar).forEach((key) => {
const event = calendar[key];
if (result.override) {
mergedCal.push({
start: event.start,
end: event.end,
summary: result.prefix,
});
} else {
mergedCal.push({
start: event.start,
end: event.end,
summary: `${result.prefix} ${event.summary}`,
});
}
});
});
@ -70,10 +61,10 @@ app.post('/merge', async (req, res) => {
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VEVENT
`;
mergedCal.forEach((event) => {
icalString += `BEGIN:VEVENT
DTSTART:${event.start}
icalString += `DTSTART:${event.start}
DTEND:${event.end}
SUMMARY:${event.summary}
END:VEVENT
@ -100,9 +91,6 @@ app.get('/:filename', (req, res) => {
res.sendFile(filename, { root: '.' });
});
// Store the merged calendar URL in a file
const mergedCalendarUrlFile = 'merged_calendar_url.txt';
// Function to update the merged calendar
async function updateMergedCalendar(){
try {
@ -117,7 +105,6 @@ async function updateMergedCalendar(){
return {
data: response.data,
prefix: calendar.prefix,
override: calendar.override,
};
})
.catch((error) => {
@ -136,19 +123,11 @@ async function updateMergedCalendar(){
const calendar = ical.parseICS(result.data);
Object.keys(calendar).forEach((key) => {
const event = calendar[key];
if (result.override) {
mergedCal.push({
start: event.start,
end: event.end,
summary: result.prefix,
});
} else {
mergedCal.push({
start: event.start,
end: event.end,
summary: `${result.prefix} ${event.summary}`,
});
}
});
});
@ -171,7 +150,7 @@ END:VEVENT
fs.writeFileSync(filename, icalString);
// Generate a unique URL for the merged calendar
const mergedCalendarUrl = `${req.protocol}://${req.get('host')}/${filename}`;
const mergedCalendarUrl = `http://localhost:3000/${filename}`;
console.log(`Merged calendar updated: ${mergedCalendarUrl}`);