1
0
Fork 0

read existing data from calendars.json

This commit is contained in:
Ryan Mwangi 2024-10-14 15:49:20 +03:00
parent 14e7db9c21
commit 03493e34f1
1 changed files with 8 additions and 1 deletions

View File

@ -128,7 +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) {