Fix some cdn replacement bugs

This commit is contained in:
mrjvs 2023-12-27 23:52:18 +01:00
parent adddb84417
commit 23c1df5aef
2 changed files with 6 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import { playerStatus } from "@/stores/player/slices/source";
import { ThumbnailImage } from "@/stores/player/slices/thumbnails";
import { usePlayerStore } from "@/stores/player/store";
import { LoadableSource, selectQuality } from "@/stores/player/utils/qualities";
import { processCdnLink } from "@/utils/cdn";
import { isSafari } from "@/utils/detectFeatures";
function makeQueue(layers: number): number[] {
@ -46,11 +47,11 @@ class ThumnbnailWorker {
const canvas = document.createElement("canvas");
this.hls = new Hls();
if (source.type === "mp4") {
el.src = source.url;
el.src = processCdnLink(source.url);
el.crossOrigin = "anonymous";
} else if (source.type === "hls") {
this.hls.attachMedia(el);
this.hls.loadSource(source.url);
this.hls.loadSource(processCdnLink(source.url));
} else throw new Error("Invalid loadable source type");
this.videoEl = el;
this.canvasEl = canvas;

View File

@ -5,7 +5,9 @@ export function processCdnLink(url: string): string {
const replacements = conf().CDN_REPLACEMENTS;
for (const [before, after] of replacements) {
if (parsedUrl.hostname.endsWith(before)) {
parsedUrl.host = after;
parsedUrl.hostname = after;
parsedUrl.port = "";
parsedUrl.protocol = "https://";
return parsedUrl.toString();
}
}