Compare commits
3 Commits
276e41cc8f
...
c80064f135
Author | SHA1 | Date |
---|---|---|
Ryan Mwangi | c80064f135 | |
Ryan Mwangi | 03493e34f1 | |
Ryan Mwangi | 14e7db9c21 |
15
script.js
15
script.js
|
@ -42,7 +42,22 @@ const form = document.getElementById('merge-form');
|
||||||
console.error(error);
|
console.error(error);
|
||||||
result.innerHTML = 'Error merging calendars';
|
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
|
const refreshInterval = 60 * 60 * 1000; // 1 hour
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
fetch('/merge')
|
fetch('/merge')
|
||||||
|
|
26
server.js
26
server.js
|
@ -128,14 +128,30 @@ function addLinkToGroup(linkGroup, url, prefix, overrideSummary) {
|
||||||
//adding the new link to the calendarData object
|
//adding the new link to the calendarData object
|
||||||
app.post('/add-link', (req, res) => {
|
app.post('/add-link', (req, res) => {
|
||||||
const { linkGroupName, linkUrl, prefix, overrideSummary } = req.body;
|
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
|
// Add the new link to the calendarData object
|
||||||
let linkGroup = calendarData.linkGroups.find((group) => group.name === linkGroupName);
|
let linkGroup = calendarData.linkGroups.find((group) => group.name === linkGroupName);
|
||||||
if (!linkGroup) {
|
if (!linkGroup) {
|
||||||
linkGroup = addLinkGroup(linkGroupName);
|
linkGroup = {
|
||||||
}
|
name: linkGroupName,
|
||||||
addLinkToGroup(linkGroup, linkUrl, prefix, overrideSummary);
|
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!' });
|
res.json({ message: 'Link added successfully!' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue