-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from antebrl/39-proxy-mode
39 proxy mode
- Loading branch information
Showing
28 changed files
with
793 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const request = require('request'); | ||
const ChannelService = require('../services/ChannelService'); | ||
const ProxyHelperService = require('../services/proxy/ProxyHelperService'); | ||
|
||
module.exports = { | ||
channel(req, res) { | ||
let { url: targetUrl, channelId, headers } = req.query; | ||
|
||
if(!targetUrl) { | ||
const channel = channelId ? | ||
ChannelService.getChannelById(parseInt(channelId)) : | ||
ChannelService.getCurrentChannel(); | ||
|
||
if (!channel) { | ||
res.status(404).json({ error: 'Channel not found' }); | ||
return; | ||
} | ||
targetUrl = channel.url; | ||
if(channel.headers && channel.headers.length > 0) { | ||
headers = Buffer.from(JSON.stringify(channel.headers)).toString('base64'); | ||
} | ||
} | ||
|
||
|
||
request(ProxyHelperService.getRequestOptions(targetUrl, headers), (error, response, body) => { | ||
if (error) { | ||
res.status(500).json({ error: 'Failed to fetch m3u8 file' }); | ||
return; | ||
} | ||
|
||
const proxyBaseUrl = `${req.protocol}://${req.get('host')}/proxy/`; | ||
const rewrittenBody = ProxyHelperService.rewriteUrls(body, proxyBaseUrl, headers, targetUrl).join('\n'); | ||
|
||
//res.set('Content-Type', 'application/vnd.apple.mpegurl'); | ||
res.send(rewrittenBody); | ||
}); | ||
}, | ||
|
||
segment(req, res) { | ||
let { url: targetUrl, headers } = req.query; | ||
|
||
if (!targetUrl) { | ||
res.status(400).json({ error: 'Missing url query parameter' }); | ||
return; | ||
} | ||
|
||
console.log('Proxy request to:', targetUrl); | ||
|
||
req.pipe(request(ProxyHelperService.getRequestOptions(targetUrl, headers))).pipe(res); | ||
}, | ||
|
||
key(req, res) { | ||
module.exports.segment(req, res); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
class Channel { | ||
static nextId = 0; | ||
constructor(name, url, avatar, restream, headers = [], group = null, playlist = null) { | ||
constructor(name, url, avatar, mode, headers = [], group = null, playlist = null) { | ||
this.id = Channel.nextId++; | ||
this.name = name; | ||
this.url = url; | ||
this.avatar = avatar; | ||
this.restream = restream; | ||
this.mode = mode; | ||
this.headers = headers; | ||
this.group = group; | ||
this.playlist = playlist; | ||
} | ||
|
||
restream() { | ||
return this.mode === 'restream'; | ||
} | ||
} | ||
|
||
module.exports = Channel; |
Oops, something went wrong.