-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtockify-middleware.js
More file actions
44 lines (41 loc) · 1.44 KB
/
Copy pathtockify-middleware.js
File metadata and controls
44 lines (41 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import axios from "axios";
const TOCKIFY_API_BASE = "https://tockify.com/api/ngevent/";
export async function fetchTockifyEventKind(tockifySlug, calendarSlug) {
try {
const resp = await axios.get(`${TOCKIFY_API_BASE}${tockifySlug}`, {
params: { view: "detail", calname: calendarSlug, max: 1 }
});
return resp.data.events[0]?.kind || 'singleton';
} catch (err) {
if (err.response?.status === 404) {
console.log(`Event ${tockifySlug} not found in Tockify (404), skipping.`);
return null;
}
console.error(`Error fetching kind for ${tockifySlug}:`, err.message);
return null;
}
}
export default async function fetchTockifyEventDetails(tockifySlug, calendarSlug) {
try {
const resp = await axios.get(`${TOCKIFY_API_BASE}${tockifySlug}`, {
params: {
view: "detail",
calname: calendarSlug,
max: 1
},
});
const event = resp.data.events[0];
const eventDetails = {
description: event.content.description.text || '',
ctaLabel: event.content.customButtonText || '',
ctaUrl: event.content.customButtonLink || '',
pinned: event.sorter.split('_')[0] === '090' ? true : false,
skipDetails: event.content.noDetail ? true : false,
recurring: event.kind === 'repeat' ? true : false
}
return eventDetails;
} catch (err) {
console.error(`Error fetching Tockify event details for ${tockifySlug}:`, err.message);
return null;
}
}