From 2064e42bcb387f0e4e1b21fb8a65426e5b3924e2 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Sun, 21 Jan 2024 20:31:34 +0100 Subject: [PATCH] handle errors for domain extraction --- src/backend/extension/streams.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/backend/extension/streams.ts b/src/backend/extension/streams.ts index 2afb900d..588718af 100644 --- a/src/backend/extension/streams.ts +++ b/src/backend/extension/streams.ts @@ -2,21 +2,23 @@ import { Stream } from "@movie-web/providers"; import { setDomainRule } from "@/backend/extension/messaging"; -function extractDomain(url: string): string { +function extractDomain(url: string): string | null { try { const u = new URL(url); return u.hostname; } catch { - return url; + return null; } } function extractDomainsFromStream(stream: Stream): string[] { if (stream.type === "hls") { - return [extractDomain(stream.playlist)]; + return [extractDomain(stream.playlist)].filter((v): v is string => !!v); } if (stream.type === "file") { - return Object.values(stream.qualities).map((v) => extractDomain(v.url)); + return Object.values(stream.qualities) + .map((v) => extractDomain(v.url)) + .filter((v): v is string => !!v); } return []; }