mirror of
https://github.com/wukko/cobalt.git
synced 2025-01-12 11:52:12 +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 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue