import https from 'https'; export const handler = async (event) => { try { // Get the livestream status const status = await getLivestreamStatus(); // Check if it contains "Currently off the air" const isOffAir = status.includes('Currently off the air'); // Construct the HTML response with the appropriate image const htmlResponse = `
`;
// Return the HTML response
return {
statusCode: 200,
headers: {
'Content-Type': 'text/html',
},
body: htmlResponse,
};
} catch (error) {
console.error('Error:', error);
// Return an error response
return {
statusCode: 500,
headers: {
'Content-Type': 'text/html',
},
body: `${error.message}
`, }; } }; // Helper function to get the livestream status function getLivestreamStatus() { return new Promise((resolve, reject) => { https.get('https://atp.fm/livestream_status', (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { try { resolve(data); console.log('🍓') console.log(data); // Printing the response body here } catch (error) { reject(new Error(`Failed to parse JSON: ${error.message}`)); } }); }).on('error', (error) => { reject(new Error(`Request failed: ${error.message}`)); }); }); }