internal-hls: correctly handle URL concatenation of all types (#560)

This commit is contained in:
jj 2024-06-08 18:34:18 +02:00 committed by GitHub
parent f3056c6dc3
commit 04d66946fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,16 +1,27 @@
import { createInternalStream } from './manage.js';
import HLS from 'hls-parser';
import path from "node:path";
function getURL(url) {
try {
return new URL(url);
} catch {
return null;
}
}
function transformObject(streamInfo, hlsObject) {
if (hlsObject === undefined) {
return (object) => transformObject(streamInfo, object);
}
const fullUrl = hlsObject.uri.startsWith("/")
? new URL(hlsObject.uri, streamInfo.url).toString()
: new URL(path.join(streamInfo.url, "/../", hlsObject.uri)).toString();
hlsObject.uri = createInternalStream(fullUrl, streamInfo);
let fullUrl;
if (getURL(hlsObject.uri)) {
fullUrl = hlsObject.uri;
} else {
fullUrl = new URL(hlsObject.uri, streamInfo.url);
}
hlsObject.uri = createInternalStream(fullUrl.toString(), streamInfo);
return hlsObject;
}