Compare commits
No commits in common. "c80064f1352e5150fa7d627c2ac7157f294fc37e" and "276e41cc8f6e1207b3884aac4cc9dea7bd57d7f6" have entirely different histories.
c80064f135
...
276e41cc8f
15
script.js
15
script.js
|
@ -42,22 +42,7 @@ 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,30 +128,14 @@ 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 = {
|
linkGroup = addLinkGroup(linkGroupName);
|
||||||
name: linkGroupName,
|
}
|
||||||
links: []
|
addLinkToGroup(linkGroup, linkUrl, prefix, overrideSummary);
|
||||||
};
|
|
||||||
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