import withSession from 'hocs/withSession' export default withSession(async (req, res) => { switch (req.method) { case 'POST': try { const user = req.session.get('user') const { station } = JSON.parse(req.body) if (!user || !user?.isVerified || !station) { throw new Error('Something went wrong') } const response = await fetch(station.replace('radios', 'radios/play')) const data = await response.text() const script = /(?<=ST\.radio = {)[\s\S]*?(?=script)/.exec(data)?.[0] const url = /(?<=url: ").*(?=")/.exec(script)?.[0] const mimeType = /(?<=content_type: ").*(?=")/.exec(script)?.[0] const songImage = /(?<="song-image")[\s\S]*?(?=div)/.exec(data)?.[0] const thumbnail = /(?<=src\=").*(?=")/.exec(songImage)?.[0] res.status(200).json({url, mimeType, thumbnail}) } catch (error) { console.log(error) res.status(400).send('') } break default: res.status(400).send('') break } })