From 04d66946fc657cdf5b6ea4871c2a69d8e6c417e5 Mon Sep 17 00:00:00 2001 From: jj Date: Sat, 8 Jun 2024 18:34:18 +0200 Subject: [PATCH] internal-hls: correctly handle URL concatenation of all types (#560) --- src/modules/stream/internal-hls.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/modules/stream/internal-hls.js b/src/modules/stream/internal-hls.js index c6a11455..9fa37e6e 100644 --- a/src/modules/stream/internal-hls.js +++ b/src/modules/stream/internal-hls.js @@ -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; }