From 6c9af1f4e4942aa656e219a8d366252054972600 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Fri, 18 Oct 2024 15:30:53 +0300 Subject: [PATCH] generate a unique identifier for each set of calendars --- server.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index ba0a20d..1b14fba 100644 --- a/server.js +++ b/server.js @@ -7,7 +7,13 @@ import axios from 'axios'; const app = express(); app.use(express.json()); -let mergedCalendarUrl = ''; +const CALENDARS_FILE = 'calendars.json'; +const MERGED_CALENDARS_DIR = 'merged_calendars'; + +// Ensure the merged calendars directory exists +if (!fs.existsSync(MERGED_CALENDARS_DIR)) { + fs.mkdirSync(MERGED_CALENDARS_DIR); +} app.get('/', (req, res) => { res.sendFile('index.html', { root: '.' }); @@ -21,6 +27,9 @@ app.post('/merge', async (req, res) => { if (!calendars || !Array.isArray(calendars)) { return res.status(400).json({ error: 'Invalid input' }); } + // Generate a unique identifier for this set of calendars + const calendarId = crypto.randomBytes(16).toString('hex'); + // Fetch calendar data from URLs const promises = calendars.map((calendar) => { return axios.get(calendar.url)