api/stream: move bsky override into isHlsResponse

This commit is contained in:
jj 2024-12-16 11:29:13 +00:00
parent bc597c817f
commit bf4675a5e3
No known key found for this signature in database
2 changed files with 6 additions and 6 deletions

View file

@ -55,8 +55,11 @@ function transformMediaPlaylist(streamInfo, hlsPlaylist) {
const HLS_MIME_TYPES = ["application/vnd.apple.mpegurl", "audio/mpegurl", "application/x-mpegURL"]; const HLS_MIME_TYPES = ["application/vnd.apple.mpegurl", "audio/mpegurl", "application/x-mpegURL"];
export function isHlsResponse (req) { export function isHlsResponse(req, streamInfo) {
return HLS_MIME_TYPES.includes(req.headers['content-type']); return HLS_MIME_TYPES.includes(req.headers['content-type'])
// bluesky's cdn responds with wrong content-type for the hls playlist,
// so we enforce it here until they fix it
|| (streamInfo.service === 'bsky' && streamInfo.url.endsWith('.m3u8'));
} }
export async function handleHlsPlaylist(streamInfo, req, res) { export async function handleHlsPlaylist(streamInfo, req, res) {

View file

@ -96,10 +96,7 @@ async function handleGenericStream(streamInfo, res) {
res.status(fileResponse.statusCode); res.status(fileResponse.statusCode);
fileResponse.body.on('error', () => {}); fileResponse.body.on('error', () => {});
// bluesky's cdn responds with wrong content-type for the hls playlist, const isHls = isHlsResponse(fileResponse, streamInfo);
// so we enforce it here until they fix it
const isHls = isHlsResponse(fileResponse)
|| (streamInfo.service === "bsky" && streamInfo.url.endsWith('.m3u8'));
for (const [ name, value ] of Object.entries(fileResponse.headers)) { for (const [ name, value ] of Object.entries(fileResponse.headers)) {
if (!isHls || name.toLowerCase() !== 'content-length') { if (!isHls || name.toLowerCase() !== 'content-length') {