mirror of
https://github.com/wukko/cobalt.git
synced 2025-01-12 20:12:22 +01:00
internal-hls: correctly handle URL concatenation of all types (#560)
This commit is contained in:
parent
f3056c6dc3
commit
04d66946fc
1 changed files with 16 additions and 5 deletions
|
@ -1,16 +1,27 @@
|
||||||
import { createInternalStream } from './manage.js';
|
import { createInternalStream } from './manage.js';
|
||||||
import HLS from 'hls-parser';
|
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) {
|
function transformObject(streamInfo, hlsObject) {
|
||||||
if (hlsObject === undefined) {
|
if (hlsObject === undefined) {
|
||||||
return (object) => transformObject(streamInfo, object);
|
return (object) => transformObject(streamInfo, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fullUrl = hlsObject.uri.startsWith("/")
|
let fullUrl;
|
||||||
? new URL(hlsObject.uri, streamInfo.url).toString()
|
if (getURL(hlsObject.uri)) {
|
||||||
: new URL(path.join(streamInfo.url, "/../", hlsObject.uri)).toString();
|
fullUrl = hlsObject.uri;
|
||||||
hlsObject.uri = createInternalStream(fullUrl, streamInfo);
|
} else {
|
||||||
|
fullUrl = new URL(hlsObject.uri, streamInfo.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
hlsObject.uri = createInternalStream(fullUrl.toString(), streamInfo);
|
||||||
|
|
||||||
return hlsObject;
|
return hlsObject;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue