1
0
Fork 0

Read calendar data from local file

This commit is contained in:
Ryan Mwangi 2024-11-04 13:51:00 +03:00
parent 978ddb9ebc
commit d2f3afd9fa
1 changed files with 15 additions and 0 deletions

View File

@ -47,6 +47,20 @@ app.post('/merge', async (req, res) => {
const promises = calendars.map((calendar) => {
// Check if calendar URL is a file path or a URL
const isFilePath = !calendar.url.startsWith('http');
if (isFilePath) {
try{
// Read calendar data from local file
const data = fs.readFileSync(path.resolve(calendar.url), 'utf-8');
return Promise.resolve({
url: data,
prefix: calendar.prefix,
override: calendar.override,
});
} catch (error){
}
} else {
return axios.get(calendar.url)
.then((response) => {
return {
@ -59,6 +73,7 @@ app.post('/merge', async (req, res) => {
console.error(`Error fetching calendar from ${calendar.url}:`, error);
return null;
});
}
});
const results = await Promise.all(promises);