Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(() => {
const { Route } = require('serverful')
jest.mock('serverful')
Route.BASE_PATH = '/'
Browser = require('../../src/browser')
jest.mock('../../src/browser')
})
beforeEach(() => {
const { Route } = require('serverful')
jest.mock('serverful')
Route.BASE_PATH = '/'
Request = require('../../src/rtp-play-request')
jest.mock('../../src/rtp-play-request')
jest.mock('modern-logger')
})
async handler ({ query, headers, server, info }, h) {
const { channel, proxy = false } = query
if (!channels[ channel ]) {
throw Boom.badRequest(`Invalid channel ${channel}`)
}
const host = _.get(headers, 'x-forwarded-host', info.host)
const proto = _.get(headers, 'cloudfront-forwarded-proto', _.get(headers, 'x-forwarded-proto', server.info.protocol))
const baseUrl = `${proto}://${host}${Route.BASE_PATH === '/' ? '' : Route.BASE_PATH}`
let url
if (channels[ channel ].is_tv) {
url = `https://streaming-live.rtp.pt/liverepeater/smil:${channel}.smil/playlist.m3u`
} else {
url = `http://streaming-live.rtp.pt/liveradio/${channels[ channel ].name}/playlist.m3u8?DVR`
}
const _headers = { 'Referer': `http://www.rtp.pt/play/direto/${channel}` }
const options = { url, headers: _headers, tor: proxy }
let { body } = await Request.get(options)
if (channels[ channel ].is_tv) {
body = body.replace(/chunklist_b(\d+)_slpt.m3u8/g, `${baseUrl}/chunklist.m3u8?channel=${channel}&bandwidth=$1&proxy=${proxy}`)
} else {