Skip to content

Commit

Permalink
internal-hls: correctly handle URL concatenation of all types (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmoron committed Jun 8, 2024
1 parent f3056c6 commit 04d6694
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/modules/stream/internal-hls.js
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down

0 comments on commit 04d6694

Please sign in to comment.