From 23c1df5aeffea54b534bb5fc8dfd8063db60024b Mon Sep 17 00:00:00 2001 From: mrjvs Date: Wed, 27 Dec 2023 23:52:18 +0100 Subject: [PATCH] Fix some cdn replacement bugs --- src/components/player/internals/ThumbnailScraper.tsx | 5 +++-- src/utils/cdn.ts | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/player/internals/ThumbnailScraper.tsx b/src/components/player/internals/ThumbnailScraper.tsx index f238aca8..b0fc8474 100644 --- a/src/components/player/internals/ThumbnailScraper.tsx +++ b/src/components/player/internals/ThumbnailScraper.tsx @@ -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; diff --git a/src/utils/cdn.ts b/src/utils/cdn.ts index bf87fb27..3a86336c 100644 --- a/src/utils/cdn.ts +++ b/src/utils/cdn.ts @@ -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(); } }