Compare commits

...

3 Commits

2 changed files with 36 additions and 5 deletions

View File

@ -42,7 +42,22 @@ const form = document.getElementById('merge-form');
console.error(error);
result.innerHTML = 'Error merging calendars';
});
// Send the input data to the server
fetch('/add-links', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ calendars: calendarsData })
})
.then((response) => response.json())
.then((data) => {
console.log('Links added successfully!');
}) .catch((error) => {
console.error('Error adding links:', error);
});
});
const refreshInterval = 60 * 60 * 1000; // 1 hour
setInterval(() => {
fetch('/merge')

View File

@ -128,14 +128,30 @@ function addLinkToGroup(linkGroup, url, prefix, overrideSummary) {
//adding the new link to the calendarData object
app.post('/add-link', (req, res) => {
const { linkGroupName, linkUrl, prefix, overrideSummary } = req.body;
// Read the existing data from calendars.json
const calendarsFile = 'calendars.json';
let calendarsData = {};
try {
calendarsData = JSON.parse(fs.readFileSync(calendarsFile, 'utf8'));
} catch (error) {
console.error(error);
}
// Add the new link to the calendarData object
let linkGroup = calendarData.linkGroups.find((group) => group.name === linkGroupName);
if (!linkGroup) {
linkGroup = addLinkGroup(linkGroupName);
}
addLinkToGroup(linkGroup, linkUrl, prefix, overrideSummary);
linkGroup = {
name: linkGroupName,
links: []
};
calendarsData.linkGroups.push(linkGroup);
}
linkGroup.links.push({
url: linkUrl,
prefix,
overrideSummary
});
// Write the updated data back to calendars.json
fs.writeFileSync(calendarsFile, JSON.stringify(calendarsData, null, 2));
res.json({ message: 'Link added successfully!' });
});